Benutzer:Dietzel/lix.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
  • Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Strg+F5
// <nowiki>

window.lix = jQuery.extend({

	load : function() {
		jQuery( document ).ready( function () {
			mw.loader.using( [ "mediawiki.util", "jquery.ui" ], function () {
				mw.util.addPortletLink("p-tb", "javascript:lix.clickText();", "Lesbarkeitsindex", "tb-lix", "Lesbarkeitsindex", "", null);
				var gui = jQuery('<div/>', {id: 'tb-lix-gui', style: 'display: none; width: 300px; background-color: white; border: 1px solid gray; padding: 3px'});

				var hideButton = jQuery('<button/>', {id: 'tb-lix-hideButton', style: 'float: right; margin: 12px'});
				hideButton.button({ icons: {
					primary: 'ui-icon-circle-close'
				}, text: false
				}).click(function()
				{
					jQuery('#tb-lix-gui').hide();
			 	});

				var updateButton = jQuery('<button/>', {text: 'aktualisieren', id: 'tb-lix-updateButton', style: 'float: right'});
				updateButton.button({ icons: {
					primary: 'ui-icon-circle-check'
				}}).click(function()
				{
					lix.update();
			 	});
				gui.append(jQuery('<p/>').append(hideButton).append(updateButton));
				gui.append(jQuery('<p style="margin-top: 50px">Flesch Reading Ease<br/>0 = sehr schwer, 100 = sehr leicht<br/><span id="numFRE" style="font-weight: bold">0</span></p>').get(0));
				gui.append(jQuery('<p>Wiener Sachtextformel<br/>15 = sehr schwer, 4 = sehr leicht<br/><span id="numWSTF" style="font-weight: bold">0</span></p>').get(0));
				gui.append(jQuery('<p>Gunning-Fog-Index<br/>Anzahl Schuljahre, die zum Verstehen nötig sind<br/><span id="numGFI" style="font-weight: bold">0</span></p>').get(0));
				jQuery('#tb-lix').append(gui);
				lix.update();
			} );
		} );

	},

	clickText : function() {
		jQuery('#tb-lix-gui').toggle();
	},

	update : function() {
		var pageText = jQuery('#mw-content-text').text().toLowerCase();
		var sentenceCount = pageText.match(/((.+[\.|\?|\.|\:])|.+((\.)"))/g).length;
		var words = pageText.match(/\S+/g);
		var wordCount = words.length;
		var syllablesI = 0; var syllablesIII = 0; var lettersVI = 0;
		for (var i = 0; i < wordCount; i++) {
			j = 0;
			if (words[i].length > 5) {lettersVI++;}
			if (words[i].match(/[aeiouäöüy]{1,2}/g)) {j = words[i].match(/[aeiouäöüy]{1,2}/g).length;}
			if (j==1) {syllablesI++;}
			if (j>2) {syllablesIII++;}
		}
		var syllableCount = pageText.match(/[aeiouäöüy]{1,2}/g).length;
		var FRE = Math.round(180 - (wordCount / sentenceCount) - (syllableCount / wordCount * 58.5));
		var WSTF = (Math.round(0.1935 * (syllablesIII / wordCount * 100) + 0.1672 * (wordCount / sentenceCount) + 0.1297 * (lettersVI / wordCount * 100) - 0.0327 * (syllablesI / wordCount * 100) - 0.875)*10)/10;
		var GFI = Math.round(((wordCount / sentenceCount) + (syllablesIII / wordCount * 100)) * 4)/10;
//alert(sentenceCount + ', ' + wordCount + ', ' + syllableCount + ', ' + syllablesI + ', ' + syllablesIII + ', ' + lettersVI);
		jQuery('#numFRE').text(FRE);
		jQuery('#numWSTF').text(WSTF);
		jQuery('#numGFI').text(GFI);
	}

});

lix.load();

// </nowiki>