ମିଡ଼ିଆଉଇକି:Gadget-watchlist-notice-core.js
ସୂଚନା: ବଦଳଗୁଡ଼ିକ ଦେଖିବା ପାଇଁ ଆପଣଙ୍କୁ ହୁଏତ ନିଜ ବ୍ରାଉଜର କ୍ୟାସ ବାଇପାସ କରିବାକୁ ପଡ଼ିପାରେ ।
- Firefox / Safari: Reload ଉପରେ କ୍ଲିକ କରିବା ବେଳେ Shift ଧରି କିମ୍ବା Ctrl-F5 ବା Ctrl-R ଦବାନ୍ତୁ (Macରେ ⌘-R)
- Google Chrome: Ctrl-Shift-R ଦବାନ୍ତୁ (Macରେ ⌘-Shift-R)
- Internet Explorer / Edge: Refresh ଉପରେ କ୍ଲିକ କଲା ବେଳେ Ctrl ଧରି ବା Ctrl-F5 ଦବାଇ
- Opera: Ctrl-F5 ଦବାନ୍ତୁ ।
/**
* Add dismiss buttons to watchlist-message, then unhide it
* Allows multiple dismiss buttons on [[MediaWiki:Watchlist-messages]] with bumpable cookie IDs.
* Note: HTML is backwards compatible with old version, new version ignores old syntax, except for dismissed IDs.
* @author: [[:en:User:Ruud Koot]]
* @author: [[:en:User:MZMcBride]]
*/
/*jslint white: true, regexp: true */
/*global jQuery, mediaWiki */
( function ( mw, $ ) {
'use strict';
var storageKey = 'hidewatchlistmessages';
function getDismissedNotices () {
var hiddenNotices = mw.storage.get( storageKey )
|| mw.storage.session.get( storageKey );
try {
return JSON.parse( hiddenNotices ) || [];
} catch (e) {
return [];
}
}
function saveDismissedNotices ( notices ) {
notices = JSON.stringify( notices );
mw.storage.set( storageKey, notices )
|| mw.storage.session.set( storageKey, notices );
}
// Remove ids which are no longer defined
function expungeOldNotices ( currentList ) {
var dismissedNotices = getDismissedNotices(),
originalLength = dismissedNotices.length;
for ( var i = dismissedNotices.length - 1; i >= 0; i--) {
if( !( dismissedNotices[i] in currentList ) ) {
dismissedNotices.splice( i, 0 );
}
}
if( originalLength !== dismissedNotices.length ) {
saveDismissedNotices( dismissedNotices );
}
}
function dismissWatchlistMessage( event ) {
var $message = $( this ).closest( '.watchlist-message' );
var cid = $( this ).data( 'watchlistMessage' ).cid;
var notices = getDismissedNotices();
$message.hide();
notices.push( cid );
saveDismissedNotices( notices );
event.preventDefault();
}
function addDismissButton() {
var watchItems = $( 'div.watchlist-message' );
var watchItemIds = [];
var dismissedNotices = getDismissedNotices();
var dismissedNoticesLength = dismissedNotices.length;
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;
}
watchItemIds.push( watchlistCookieID );
if (
dismissedNotices.indexOf( watchlistCookieID ) !== -1 ||
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', '#' );
ButtonLink.setAttribute( 'title', 'Hide this message' );
ButtonLink.appendChild( ButtonText );
$( ButtonLink ).data( 'watchlistMessage', {
index: i,
cid: watchlistCookieID
} );
$( ButtonLink ).click( dismissWatchlistMessage );
Button.appendChild( document.createTextNode(' [' ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( ']' ) );
watchItems[i].appendChild( Button );
}
expungeOldNotices( watchItemIds );
$( '#watchlist-message' ).show();
}
$( addDismissButton );
}( mediaWiki, jQuery ) );