MediaWiki:Common.js/watchlist.js

Aus Kitakien

(Unterschied zwischen Versionen)
Wechseln zu: Navigation, Suche
Merlissimo (Diskussion)
(+Skript für hide watchlistmessage)
Zum nächsten Versionsunterschied →

Version vom 18:11, 8. Nov. 2009

//<source lang="JavaScript">
 
/** Add dismiss buttons to watchlist-message *************************************
 *
 *  Description: Allows multiple dismiss buttons on div.watchlist-message
 *  Maintainers: [[User:Ruud Koot|Ruud Koot]], [[User:MZMcBride|MZMcBride]], [[User:Merlissimo|Merlissimo]]
 */
 
  var docobj = document.getElementById('bodyContent') || document.getElementById('content') || document
  var watchItems = getElementsByClassName(docobj, 'div', 'watchlist-message');
  if(watchItems.length == 0) return
  for(var i=0;i<watchItems.length;i++) {
    var watchlistCookieID = parseInt(watchItems[i].className.replace(/.*cookie\-ID\_(\d*).*/ig,'$1'));
    if(isNaN(watchlistCookieID)) continue
    if(document.cookie.indexOf('dewiki-hidewatchlistmessage-' + watchlistCookieID + '=yes') != -1) {
      watchItems[i].style.display = 'none';
      continue;
    }
    var Button     = document.createElement('span');
    var ButtonLink = document.createElement('a');
    var ButtonText = document.createTextNode('Verbergen');
 
    ButtonLink.setAttribute('id','dismissButton');
    ButtonLink.setAttribute('href','javascript:dismissWatchlistMessage(' + i + ',' + watchlistCookieID + ')');
    ButtonLink.setAttribute('title','Nachricht ausblenden');
    ButtonLink.appendChild(ButtonText);
 
    Button.setAttribute('style','font-size:0.6em;float:right;position:relative;padding-right:4px');
    Button.appendChild(document.createTextNode('['));
    Button.appendChild(ButtonLink);
    Button.appendChild(document.createTextNode(']'));
    watchItems[i].insertBefore(Button,watchItems[i].firstChild);
  }
}
 
function dismissWatchlistMessage(num,cid) {
  var docobj = document.getElementById('bodyContent') || document.getElementById('content') || document
  var watchItems = getElementsByClassName(docobj, 'div', 'watchlist-message');
  watchItems[num].style.display = 'none';
 
  var e = new Date();
  e.setTime( e.getTime() + (3*7*24*60*60*1000) );
  document.cookie = 'dewiki-hidewatchlistmessage-' + cid + '=yes; expires=' + e.toGMTString() + '; path=/';
}
 
addOnloadHook(addDismissButton);
 
//</source>
Persönliche Werkzeuge