Benutzer:Aarakast/common.js

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
// To Do:
// - https://de.wikipedia.org/wiki/Ralph_Bathurst summary
// - https://de.wikipedia.org/wiki/Oxford summary
// - Toggle Hyphenation
// - Remeber Toogle state
/*

// activate hyphenation in Chrome
mw.loader.load('https://mnater.github.io/Hyphenator/Hyphenator.js?bm=true');

// Use MathJax instead of fallback pngs
var mathTags = $('.mwe-math-mathml-a11y');
if (mathTags.length > 0){
    window.MathJax = {
        AuthorInit: function () {
            MathJax.Hub.Register.StartupHook("End",function () {
                MathJax.Hub.Queue(
                    function(){
                        mathTags.removeClass('mwe-math-mathml-a11y');
                        $('.mwe-math-fallback-image-inline').addClass('mwe-math-mathml-a11y');
                    }
                );
            });
        }
    };
    mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=MML_HTMLorMML-full');
}

try {
	var hideToc, $this = $('.toc'), $tocTitle = $this.find('.toctitle'), $tocToggleLink = $this.find('.togglelink'), $tocList = $this.find('ul').eq(0);
	function toggleToc() {
	    if ($tocList.is(':hidden')) {
	        $tocList.slideDown('fast');
	        $tocToggleLink.text(mw.msg('hidetoc'));
	        $this.removeClass('tochidden');
	        mw.cookie.set('hidetoc', null);
	    } else {
	        $tocList.slideUp('fast');
	        $tocToggleLink.text(mw.msg('showtoc'));
	        $this.addClass('tochidden');
	        mw.cookie.set('hidetoc', '1');
	    }
	}
	document.querySelector(".toctitle > h2").addEventListener('click',toggleToc);
} catch(err) {}

// Extract first sentence from article
// covers a lot, but not all uppercase letters: http://www.fileformat.info/info/unicode/category/Lu/list.htm
summary = document.querySelector(".mw-parser-output > p").textContent;
i = 1;
while(summary.length < 10 && i < 5) {
    i++;
    summary = document.querySelector(".mw-parser-output > p:nth-child(" + i + ")").textContent;
}
summary = summary.replace(/[{(\[].+?[)}\]]/g, ' ') // remove brackets and contents
			.replace(/([^\d][.?!;])\s+[\u0041-\u005A\u00C0-\u00DE+\u1E9E].*        DELETE THIS WHEN UNCOMMENTING   =================================    /, '$1') // split at first dot thats not after a number and continues with an uppercase letter
			.replace(/\s+/g,' ') // remove duplicate whitespace
			.replace(/\s+([.,;:?!])/g,'$1'); // remove whitespace before punctuation
var div = document.createElement("div");
div.id="custom_summary";
div.textContent = "– " + summary;
document.querySelector("#firstHeading").insertAdjacentElement("afterEnd",div);

var div_footbar = document.createElement("div");
div_footbar.id = "custom_footbar";

var div_footbar_left = document.createElement("div");
div_footbar_left.classList.add("settings");

var span_hidelinks = document.createElement("span");
span_hidelinks.classList.add("hidelinks");
span_hidelinks.classList.add("clickable");
span_hidelinks.textContent = "Hide Links: off";
span_hidelinks.addEventListener('click', function() {
	jQuery('.mw-parser-output a').toggleClass('hidelink');
	if(jQuery('.mw-parser-output a').hasClass('hidelink')) {
		span_hidelinks.textContent = "Hide Links: on";
	} else {
		span_hidelinks.textContent = "Hide Links: off";
	}
});
div_footbar_left.appendChild(span_hidelinks);

div_footbar.appendChild(div_footbar_left);

var div_footbar_right = document.createElement("div");
div_footbar_right.classList.add("word_statistics");

var span_wordcount = document.createElement("span");
span_wordcount.classList.add("wordcount");
var num_words = document.querySelector(".mw-parser-output").textContent
					.replace(/\s+/g, ' ') // remove whitespace mainly from formulas
					.replace(/\s(.)\s/g, '$1') // white space in formulas #2
					.split(' ').length;
span_wordcount.textContent = num_words + " Wörter";
div_footbar_right.appendChild(span_wordcount);

var span_readduration = document.createElement("span");
span_readduration.classList.add("readduration");
span_readduration.textContent = Math.ceil(num_words / 130) + " Minuten";
div_footbar_right.appendChild(span_readduration);

div_footbar.appendChild(div_footbar_right);
document.querySelector("body").appendChild(div_footbar);
*/