MediaWiki:Common.js/watchlist.js: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
>Remember the [email protected]
 
Line 1: Line 1:
//<source lang="JavaScript">
//<source lang="JavaScript">


/** Add dismiss button to watchlist-message *************************************
/** Add dismiss buttons to watchlist-message *************************************
  *
  *
  *  Description: Hide the watchlist message for one week.
  *  Description: Allows multiple dismiss buttons on [[MediaWiki:Watchlist-details]] with bump-able cookie IDs.
  *  Maintainers: [[User:Ruud Koot|Ruud Koot]]
*  Note: HTML is backwards compatible with old version, new version ignores old syntax, except for dismissed IDs.
  *  Maintainers: [[User:Ruud Koot|Ruud Koot]], [[User:MZMcBride|MZMcBride]]
  */
  */


function addDismissButton() {
function addDismissButton() {
    var watchlistMessage = document.getElementById("watchlist-message");
  var docobj = document.getElementById('bodyContent') || document.getElementById('content') || document
    if ( watchlistMessage == null ) return;
  var watchItems = getElementsByClassName(docobj, 'div', 'watchlist-message');
     var watchlistCookieID = watchlistMessage.className.replace(/cookie\-ID\_/ig,'');
  if(watchItems.length == 0) return
 
  for(var i=0;i<watchItems.length;i++) {
     if ( document.cookie.indexOf( "hidewatchlistmessage-" + watchlistCookieID + "=yes" ) != -1 ) {
     var watchlistCookieID = parseInt(watchItems[i].className.replace(/.*cookie\-ID\_(\d*).*/ig,'$1'));
        watchlistMessage.style.display = "none";
    if(isNaN(watchlistCookieID)) continue
     if(document.cookie.indexOf('hidewatchlistmessage-' + watchlistCookieID + '=yes') != -1) {
      watchItems[i].style.display = 'none';
      continue;
     }
     }
    var Button    = document.createElement('span');
    var ButtonLink = document.createElement('a');
    var ButtonText = document.createTextNode('dismiss');


     var Button     = document.createElement( "span" );
     ButtonLink.setAttribute('id','dismissButton');
     var ButtonLink = document.createElement( "a" );
     ButtonLink.setAttribute('href','javascript:dismissWatchlistMessage(' + i + ',' + watchlistCookieID + ')');
     var ButtonText = document.createTextNode( "dismiss" );
     ButtonLink.setAttribute('title','Hide this message for one week');
     ButtonLink.appendChild(ButtonText);


     ButtonLink.setAttribute( "id", "dismissButton" );
     Button.appendChild(document.createTextNode('['));
    ButtonLink.setAttribute( "href", "javascript:dismissWatchlistMessage();" );
     Button.appendChild(ButtonLink);
     ButtonLink.setAttribute( "title", "Hide this message for one week" );
     Button.appendChild(document.createTextNode(']'));
    ButtonLink.appendChild( ButtonText );
     watchItems[i].appendChild(Button);
 
  }
     Button.appendChild( document.createTextNode( "[" ) );
}
     Button.appendChild( ButtonLink );
    Button.appendChild( document.createTextNode( "]" ) );


    watchlistMessage.appendChild( Button );
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';


function dismissWatchlistMessage() {
  var e = new Date();
    var e = new Date();
  e.setTime( e.getTime() + (7*24*60*60*1000) );
    e.setTime( e.getTime() + (7*24*60*60*1000) );
  document.cookie = 'hidewatchlistmessage-' + cid + '=yes; expires=' + e.toGMTString() + '; path=/';
    var watchlistMessage = document.getElementById("watchlist-message");
    var watchlistCookieID = watchlistMessage.className.replace(/cookie\-ID\_/ig,'');
    document.cookie = "hidewatchlistmessage-" + watchlistCookieID + "=yes; expires=" + e.toGMTString() + "; path=/";
    watchlistMessage.style.display = "none";
}
}
 
addOnloadHook(addDismissButton);
addOnloadHook( addDismissButton );
 


/** Geo-targeted watchlist notice *******************************************************
/** Geo-targeted watchlist notice *******************************************************
Line 50: Line 52:
   */
   */


addOnloadHook((function (){document.write('<script type="text/javascript" src="http://tools.wikimedia.de/~gmaxwell/cgi-bin/geonotice.py"><\/script>')}));
if (wgPageName == "Special:Watchlist") {
  addOnloadHook(function() { importScriptURI('http://tools.wikimedia.de/~gmaxwell/cgi-bin/geonotice.py') });
}


//</source>
//</source>

Revision as of 23:55, 4 June 2008

//<source lang="JavaScript">

/** Add dismiss buttons to watchlist-message *************************************
 *
 *  Description: Allows multiple dismiss buttons on [[MediaWiki:Watchlist-details]] with bump-able cookie IDs.
 *  Note: HTML is backwards compatible with old version, new version ignores old syntax, except for dismissed IDs.
 *  Maintainers: [[User:Ruud Koot|Ruud Koot]], [[User:MZMcBride|MZMcBride]]
 */

function addDismissButton() {
  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('hidewatchlistmessage-' + watchlistCookieID + '=yes') != -1) {
      watchItems[i].style.display = 'none';
      continue;
    }
    var Button     = document.createElement('span');
    var ButtonLink = document.createElement('a');
    var ButtonText = document.createTextNode('dismiss');

    ButtonLink.setAttribute('id','dismissButton');
    ButtonLink.setAttribute('href','javascript:dismissWatchlistMessage(' + i + ',' + watchlistCookieID + ')');
    ButtonLink.setAttribute('title','Hide this message for one week');
    ButtonLink.appendChild(ButtonText);

    Button.appendChild(document.createTextNode('['));
    Button.appendChild(ButtonLink);
    Button.appendChild(document.createTextNode(']'));
    watchItems[i].appendChild(Button);
  }
}

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() + (7*24*60*60*1000) );
  document.cookie = 'hidewatchlistmessage-' + cid + '=yes; expires=' + e.toGMTString() + '; path=/';
}
addOnloadHook(addDismissButton);

/** Geo-targeted watchlist notice *******************************************************
  *
  *  Description: Allows for geographic targeting of watchlist notices. See [[Wikipedia:Geonotice]] for more information.
  *  Created by: [[User:Gmaxwell]]
  */

if (wgPageName == "Special:Watchlist") {
  addOnloadHook(function() { importScriptURI('http://tools.wikimedia.de/~gmaxwell/cgi-bin/geonotice.py') });
}

//</source>