Benutzer:ParaDox/monobook/orderedListsSummary.js
< Benutzer:ParaDox | monobook
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
// Siehe Diskussionsseite:
// http://de.wikipedia.org/wiki/Benutzer_Diskussion:ParaDox/monobook/orderedListsSummary.js
window.addEventListener('load', function(event) {
/* ============================== */
function __ONLOAD() {} // DUMMY
var thisTabID = 'OLSummaryTab';
var thisLinkText = 'N';
var thisVersion = ' (V0.36 by "de:user:ParaDox" 2008-08-05)';
var thisScript = '[[:de:user:ParaDox/monobook/orderedListsSummary.js]]';
var textAreaObj;
if ( document.getElementById('ca-edit') ) {
var wikiTab = document.getElementById('ca-edit');
} else if ( document.getElementById('ca-viewsource') ) {
var wikiTab = document.getElementById('ca-viewsource');
} else {
return;
}
if ( document.getElementById(thisTabID) ) {
alert(thisScript + thisVersion + '\nFehler: ID "' + thisTabID + '" schon vorhanden!')
return;
}
/* ============================== */
function makeTab() {
// geclonten Tab und Link initialisieren
var cloneTab = wikiTab.cloneNode(true);
cloneTab.id = thisTabID;
cloneTab.className = '';
cloneTab.style.marginRight = '1.5pt';
var cloneTab_link = cloneTab.firstChild;
cloneTab_link.accessKey = '';
cloneTab_link.title = 'NummerierteListen-Übersicht' + thisVersion;
cloneTab_link.href = '#';
cloneTab_link.style.paddingLeft = '2.25pt';
cloneTab_link.style.paddingRight = '1.50pt';
cloneTab_link.style.backgroundColor = '#FFFFBB';
// LinkText
cloneTab_link.firstChild.nodeValue = thisLinkText;
// Tab ins DOM hinter letztem Tab anfügen
wikiTab.parentNode.appendChild(cloneTab);
}
/* ============================== */
function appendTextarea(pRows, pStr) {
var textContainer = document.createElement('TEXTAREA');
document.getElementsByTagName('H1')[0].appendChild(textContainer);
textContainer.style.width = '100%';
textContainer.rows = String(pRows);
textContainer.value = pStr;
return textContainer;
}
/* ============================== */
function clickListener() {
document.addEventListener('click', function(event) {
if ( event.target.parentNode.id == thisTabID ) {
event.stopPropagation();
event.preventDefault();
displayListSummary();
}
}, true);
}
/* ============================== */
function displayListSummary() {
var temp, i;
var tempArr = new Array();
var prozentPro;
var prozentCtr;
var result = '';
var olFound = 0;
var olArr = document.getElementById('bodyContent').getElementsByTagName('ol');
var groupSum = new Object();
var isGroups = false;
var jetzt = new Date();
jetzt = jetzt.toLocaleString(); jetzt = jetzt.substr(0, jetzt.length - 3);
for ( var ol=0; ol<olArr.length; ol++ ) {
var thisNode = olArr[ol];
var thisName = thisNode.nodeName.toLowerCase();
while ( thisNode.previousSibling ) {
if ( thisName == 'ol' ) {
var liCount = 0;
for ( var li=0; li<thisNode.childNodes.length; li++ ) {
var childName = thisNode.childNodes[li].nodeName.toLowerCase();
if ( childName == 'li' ) {
liCount++;
}
}
}
thisNode = thisNode.previousSibling;
thisName = thisNode.nodeName.toLowerCase();
while ( (thisName == 'ol') && thisNode.previousSibling ) {
// skip previous OLs in this section
thisNode = thisNode.previousSibling;
thisName = thisNode.nodeName.toLowerCase();
}
while ( (thisName.substr(0,1) != 'h') && thisNode.previousSibling ) {
// skip back to previous header
thisNode = thisNode.previousSibling;
thisName = thisNode.nodeName.toLowerCase();
}
if ( thisName.substr(0,1) == 'h' ) {
if ( thisNode.childNodes.length > 0 ) {
olFound++;
var childOffset = 1;
if ( thisNode.childNodes.length < 2 ) childOffset = 0;
var thisSecName = thisNode.childNodes[childOffset].innerHTML;
////
// Falls Überschrift bspw. in einem "<small></small>-Tag", wie kurzzeitig etwa 21:45, 4. Aug. 2008
// http://de.wikipedia.org/w/index.php?title=Wikipedia:Meinungsbilder/Weiterf%C3%BChrung_der_gesichteten_Versionen&oldid=49175772
thisSecName = thisSecName.replace(/^<span class="mw-headline">/, '');
thisSecName = thisSecName.replace(/<\/span>$/, '');
////
if ( thisSecName == 'Pro' ) prozentPro = liCount
else if ( thisSecName == 'Contra' ) prozentCtr = liCount;
////
// Zeilenumbruch bei sehr langen Überschriften
var dispName = '';
var restStr = thisSecName;
while ( restStr.length > 80 ) {
temp = restStr.substr(0, 80).lastIndexOf(' ');
if ( temp > 1 ) {
dispName += restStr.substr(0, temp) + ' <!--\n --> ';
restStr = restStr.substr(temp + 1);
}
}
if ( dispName == '' ) {
dispName = thisSecName;
} else {
dispName += restStr;
}
result += '* ' + ('000' + String(liCount)).substr(-3)
+ ': ' + dispName
+ '\n';
////
////
// groupSum:
// groupName: bis vor erstem "Leerzeichen+Ziffer" (" n")
var groupName = thisSecName.replace(/(.*?)( \d).*/, '$1');
if ( groupName != thisSecName ) {
if ( groupName == 'Option' ) {
groupName += RegExp.$2
}
var isGroups = true;
if ( groupSum[groupName] == null ) {
groupSum[groupName] = liCount;
} else {
groupSum[groupName] += liCount;
}
}
////
}
break;
}
}
}
var listsFound = String( olFound > 0 ? olFound : 'Keine' );
var listPlural = olFound > 1 ? 'Listen' : 'Liste';
var resultText = '* ' + listsFound + ' nummerierte ' + listPlural + ' gefunden am ' + jetzt + '\n';
if ( document.getElementById('lastmod') ) {
temp = document.getElementById('lastmod').innerHTML;
temp = temp.replace(/^ (.*)/, '$1');
temp = temp.replace(/(.*)\.$/, '$1');
resultText += '* ' + temp + '\n';
} else if ( document.getElementById('contentSub') ) {
temp = document.getElementById('contentSub').innerHTML;
tempArr = temp.match(/.*(Zeitpunkt der Bearbeitung:.+?) durch.*/);
if ( tempArr != null ) {
temp = tempArr[1].replace(/^Zeitpunkt der Bearbeitung: (\d\d:\d\d), (.*)/, 'SEITEN-VERSION VOM: $2 $1');
resultText += '** ' + temp + '\n';
}
}
if ( (groupSum != null) && isGroups ) {
var groupProzent = new Object();
var groupsSumme = 0;
for ( var grpNam in groupSum ) {
groupsSumme += groupSum[grpNam];
}
for ( var grpNam in groupSum ) {
groupProzent[grpNam] = (groupSum[grpNam] / groupsSumme * 100).toFixed(1);
}
resultText += 'GRUPPIERTE SUMMEN:\n'
+ '* ' + ('000' + String(groupsSumme)).substr(-3) + ' =100%: GESAMT\n'
for ( var grpNam in groupSum ) {
if (firstGroup == null) {
var firstGroup = grpNam;
var relativeGrpArr = ['NULL'];
} else {
var lastGroup = grpNam;
var hundertSum = groupSum[previousGroup] + groupSum[grpNam];
var prozent = groupSum[previousGroup] / hundertSum * 100;
relativeGrpArr[relativeGrpArr.length] = previousGroup
+ ' << ' + prozent.toFixed(1) + ' % ' + (100 - prozent).toFixed(1) + ' >> ' + grpNam;
}
var previousGroup = grpNam;
resultText += '* ' + ('000' + String(groupSum[grpNam])).substr(-3)
+ ' ' + ('0000' + groupProzent[grpNam] ).substr(-4)
+ '%: ' + grpNam
+ '\n';
}
if ( relativeGrpArr.length > 2 ) {
hundertSum = groupSum[firstGroup] + groupSum[lastGroup];
prozent = groupSum[firstGroup] / hundertSum * 100;
relativeGrpArr[0] = firstGroup
+ ' << ' + prozent.toFixed(1) + ' % ' + (100 - prozent).toFixed(1) + ' >> ' + lastGroup;
resultText += 'RELATIVE PROZENT:\n';
for ( i=0; i<relativeGrpArr.length; i++) {
resultText += '* ' + relativeGrpArr[i] + '\n';
}
}
resultText += 'EINZEL-SUMMEN:\n';
} else {
if ( (prozentPro!=null) && (prozentCtr!=null) ) {
prozentPro = prozentPro / (prozentPro + prozentCtr) * 100;
prozentCtr = 100 - prozentPro;
resultText += '• Pro=' + prozentPro.toFixed(1) + '% • Contra=' + prozentCtr.toFixed(1) + '%\n';
}
}
resultText += result;
var Zeilen = resultText.split('\n');
if ( textAreaObj ) {
textAreaObj.rows = String(Zeilen.length - 1);
textAreaObj.value = resultText;
} else {
textAreaObj = appendTextarea(Zeilen.length - 1, resultText);
}
}
/* ============================== */
function __INIT() {} // DUMMY
makeTab();
clickListener();
}, false);