ผู้ใช้:Geonuch/common.js/watchlist.js

จาก วิกิซอร์ซ

หมายเหตุ: หลังเผยแพร่ คุณอาจต้องล้างแคชเว็บเบราว์เซอร์ของคุณเพื่อดูการเปลี่ยนแปลง

  • ไฟร์ฟอกซ์ / ซาฟารี: กด Shift ค้างขณะคลิก Reload หรือกด Ctrl-F5 หรือ Ctrl-R (⌘-R บนแมค)
  • กูเกิล โครม: กด Ctrl-Shift-R (⌘-Shift-R บนแมค)
  • อินเทอร์เน็ตเอกซ์พลอเรอร์ และ Edge: กด Ctrl ค้างขณะคลิก Refresh หรือกด Ctrl-F5
  • โอเปร่า: กด Ctrl-F5
//<source lang="javascript">
/** Add dismiss buttons to watchlist-message *************************************
 *
 *  Description: Allows multiple dismiss buttons on [[MediaWiki:Watchlist-announcements]] 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 watchItems = $("div.watchlist-message");
  if (watchItems.length == 0) watchItems = $("li.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.className = 'dismissButton';
    ButtonLink.setAttribute('href','javascript:dismissWatchlistMessage(' + i + ',' + watchlistCookieID + ')');
    ButtonLink.setAttribute('title','Hide this message');
    ButtonLink.appendChild(ButtonText);

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

function dismissWatchlistMessage(num,cid) {
  var watchItems = $("div.watchlist-message");
  if(watchItems.length == 0) watchItems = $("li.watchlist-message")
  watchItems[num].style.display = 'none';

  var e = new Date();
  e.setTime( e.getTime() + (4*7*24*60*60*1000) );
  document.cookie = 'hidewatchlistmessage-' + cid + '=yes; expires=' + e.toGMTString() + '; path=/';
}

/**
 * Hide the "green bullets" message for those using enhanced recent changes.
 */
$( document ).ready( function() {
  if ( $( 'table.mw-enhanced-rc' ).length > 0 ) {
    mw.util.addCSS( '#mw-wlheader-showupdated,  { display: none; } ' ); //moving out #mw-watchlist-resetbutton
  }
  addDismissButton();
  /* Load the geonotices. See [[Wikipedia:Geonotice]]. */
  mw.loader.load( mw.config.get( 'wgScript' ) + '?title=User:Geonuch/common.js/Geonotice.js&action=raw&ctype=text/javascript&maxage=3600&ver=2');
});
//</source>