Benutzer:Martin Kraft/hideUserComments.js
aus Wikipedia, der freien Enzyklopädie
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
/**
*
* The Purpose of this Script is, to hide the edits of certain uses in Wikipedia talk pages by default.
* Each of the users Edits is then replaced by a small link, that enables you to unhide the post if needed.
*
* To use this Script just add the following two lines to your common.js:
var usersToHide = ['Some_Users_Name', 'Some_Other_Users_Name'];
importScript('Benutzer:Martin_Kraft/hideUserComments.js');
*
*/
(function ($) {
var usersToHide = window.usersToHide;
if(!usersToHide) return;
$.each(usersToHide, function( i, n ) {
var userName = n,
selector = '>a[href*="/wiki/Benutzer"][href*=":' + userName + '"]:last-of-type';
$('dd'+selector+',p'+selector).each(function () {
var $diskLink = $(this),
$edit = $diskLink.parent(),
$prevEdit, $lastEdit,
$hideTrigger,
nodeName = $edit[0].nodeName || 'dd',
editIsVisible = true;
$edit.contents().wrapAll('<div class="hide-block" style="background-color:#fdfdfd"></div>');
var $hideBlock = $edit.find('>.hide-block');
$hideBlock.find('>dl').each(function () {
$edit.append(this);
});
// Find previous dls
$prevEdit = $edit;
do {
$lastEdit = $prevEdit;
$prevEdit = $prevEdit.prev(nodeName);
if ($prevEdit.length == 0 ||
($prevEdit.length && $prevEdit.find('>a[href^="/wiki/Benutzer"]:last-child,>dl:first-child').length)) {
$prevEdit = $lastEdit
break;
} else {
$hideBlock = $hideBlock.add($prevEdit);
}
} while ($prevEdit != $lastEdit);
$prevEdit.before('<' + nodeName + '><a href="#" class="hide-'+i+'-trigger">'+userName+'</a></' + nodeName + '>');
$hideTrigger = $prevEdit.parent().find('>'+nodeName+'>.hide-'+i+'-trigger').css({
display: 'block',
fontSize: '0.7em',
color: '#AAA',
textDecoration:'none'
}).click(function (e) {
e.preventDefault();
editIsVisible = !editIsVisible;
$hideTrigger.html((editIsVisible? '▽' : '▷')+' Edit by ' + userName); // '╳'
$hideBlock[editIsVisible? 'show' : 'hide']();
});
$hideTrigger.trigger('click');
});
});
})(jQuery);