Benutzer:Janomoogo/duplinks.js
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
//This script uses code from https://en.wikipedia.org/wiki/User:Evad37/duplinks-alt.js and https://en.wikipedia.org/wiki/User:Ucucha/duplinks.js $(function($) { mw.loader.using('mediawiki.util').then(function() { var portletLink = mw.util.addPortletLink('p-tb', '#', 'Doppelte Links finden', 'ca-findduplicatelinks'); $(portletLink).click(function(e) { e.preventDefault(); var $content = $('.mw-parser-output'); // Objects to keep track of whether we've seen a link before, and which links are duplicated var seen = {}; var duplicated = {}; var hasDuplicatedLinks = false; // Styles mw.util.addCSS('.duplicate-link { border: 1px solid red; }\n .duplicated-link { border: 1px dashed green; }'); // Detect and mark links which are duplicates var findDups = function() { var href = this.attributes.href && this.attributes.href.value; if (href != undefined && href.indexOf('#') != 0) { if (seen[href]) { this.classList.add('duplicate-link'); duplicated[href] = true; hasDuplicatedLinks = true; } else { seen[href] = true; } } }; // Detect and mark the first occurance of duplicated links var markDups = function() { var href = this.attributes.href && this.attributes.href.value; if (href != undefined && href.indexOf('#') != 0) { if (duplicated[href]) { this.classList.add('duplicated-link'); duplicated[href] = ''; } } }; // Kanon-Tab mw.util.$content.find('.tab-kanon a').not('.infobox *, .navContent *, li *, .jp-zitat *, .jp-dialog *, .NavFrame *, .thumb *, .qmtemplatestart *, table *, .noprint *').each(findDups); mw.util.$content.find('.tab-kanon a').not('.infobox *, .navContent *, li *, .jp-zitat *, .jp-dialog *, .NavFrame *, .thumb *, .qmtemplatestart *, table *, .noprint *').each(markDups); // Legends-Tab seen = {}; duplicated = {}; mw.util.$content.find('.tab-legends a').not('.infobox *, .navContent *, li *, .jp-zitat *, .jp-dialog *, .NavFrame *, .thumb *, .qmtemplatestart *, table *, .noprint *').each(findDups); mw.util.$content.find('.tab-legends a').not('.infobox *, .navContent *, li *, .jp-zitat *, .jp-dialog *, .NavFrame *, .thumb *, .qmtemplatestart *, table *, .noprint *').each(markDups); // HdK-Tab seen = {}; duplicated = {}; mw.util.$content.find('.tab-hdk > li a').each(findDups); mw.util.$content.find('.tab-hdk > li a').each(markDups); // Show a notice if no duplicates were found if (!hasDuplicatedLinks) { mw.notify('Keine doppelten Links gefunden'); } }); }); });