משתמש:Yova/common.js/watchlistNotifier.js
< משתמש:Yova | common.js
הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.
- פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
- גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
- אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
- אופרה: ללחוץ על Ctrl-F5.
// ייעוד: הוספת עדכונים מרשימת המעקב מתחת לsiteNotice
// יוצר: [[משתמש:Yova|Yova]]
$(document).ready(function()
{
if (!$.cookie('WatchlistNotifier') || $.cookie('WatchlistNotifier').length == 0)
{
$.cookie('WatchlistNotifier', new Date().getTime(), {path: '/', expires: 30});
}
$('<div>', {id: 'watchlistNotifierDiv'}).css({fontSize: '75%', border: '1px solid', padding: '5px'}).insertAfter('#siteNotice');
$('<hr style="height: 10pt; visibility: hidden;" />').insertAfter('#watchlistNotifierDiv');
setUpdate();
});
function setUpdate()
{
$.getJSON(
mw.util.wikiScript('api'),
{
action: 'query',
list: 'watchlist',
wldir: 'newer',
wlstart: $.cookie('WatchlistNotifier'),
wllimit: 1,
wlexcludeuser: wgUserName,
wlshow: '!bot',
wlprop: 'user|title|sizes|comment|timestamp|ids',
format: 'json'
},
function(data)
{
if (data && data.query && data.query.watchlist && data.query.watchlist[0])
{
var Month = new Date(data.query.watchlist[0].timestamp).getMonth();
var notifierMonth = Month==0 ? 'בינואר' : Month==1 ? 'בפברואר' : Month==2 ? 'במרץ' : Month==3 ? 'באפריל' : Month==4 ? 'במאי' : Month==5 ? 'ביוני' : Month==6 ? 'ביולי' : Month==7 ? 'באוגוסט' : Month==8 ? 'בספטמבר' : Month==9 ? 'באוקטובר' : Month==10 ? 'בנובמבר' : 'בדצמבר';
var dateChecked = zeroPad(new Date(data.query.watchlist[0].timestamp).getDate(), 2)+' '+notifierMonth+' '+new Date(data.query.watchlist[0].timestamp).getFullYear();
var diffrence = '<a href="http://he.wikipedia.org/w/index.php?title='+data.query.watchlist[0].title.replace(' ','%20')+'&action=historysubmit&diff='+data.query.watchlist[0].revid+'&oldid='+data.query.watchlist[0].old_revid+'" title="'+data.query.watchlist[0].title+'" tabindex="1">הבדל</a>';
var history = '<a href="http://he.wikipedia.org/w/index.php?title='+data.query.watchlist[0].title.replace(' ','%20')+'&action=history" title="'+data.query.watchlist[0].title+'">היסטוריה</a>';
var title = '<a href="http://he.wikipedia.org/wiki/'+data.query.watchlist[0].title.replace(' ','%20')+'" title="'+data.query.watchlist[0].title+'">'+data.query.watchlist[0].title+'</a>';
var notificationDate = zeroPad(new Date(data.query.watchlist[0].timestamp).getHours(),2)+':'+zeroPad(new Date(data.query.watchlist[0].timestamp).getMinutes(),2);
var sizeText = data.query.watchlist[0].newlen-data.query.watchlist[0].oldlen;
var sizeStyle = Math.abs(sizeText) > 500 ? 'strong' : 'span';
var sizeClass = sizeText > 0 ? 'pos' : sizeText < 0 ? 'neg' : 'null';
var sizeSign = sizeText > 0 ? '+' : sizeText <0 ? '-' : '';
var size = '<'+sizeStyle+' dir="rtl" class="mw-plusminus-'+sizeClass+'" title="'+addCommas(data.query.watchlist[0].newlen)+' בתים לאחר השינוי">('+Math.abs(sizeText)+sizeSign+')</'+sizeStyle+'>';
var user = '<a href="http://he.wikipedia.org/wiki/User:'+data.query.watchlist[0].user.replace(' ','%20')+'" title="משתמש:'+data.query.watchlist[0].user+'" class="mw-userlink">'+data.query.watchlist[0].user+'</a>'
var talk = '<a href="http://he.wikipedia.org/wiki/User%20talk:'+data.query.watchlist[0].user.replace(' ','%20')+'" title="שיחת משתמש:'+data.query.watchlist[0].user+'">שיחה</a>';
var contributions = '<a href="http://he.wikipedia.org/wiki/מיוחד:תרומות/'+data.query.watchlist[0].user.replace(' ','%20')+'" title="מיוחד:תרומות/'+data.query.watchlist[0].user+'">תרומות</a>';
$('#watchlistNotifierDiv').html('<a href="http://he.wikipedia.org/wiki/מיוחד:רשימת_המעקב">רשימת המעקב</a>: <b>'+dateChecked+'</b><br /><ul class="special"><li class="mw-line-even">('+diffrence+' | '+history+') . . '+title+'; '+notificationDate+' . . '+size+' . . '+user+' <span class="mw-usertoollinks">('+talk+' | '+contributions+')</span> <span class="comment">('+data.query.watchlist[0].comment+')</span> (<a onclick=acceptAlert("'+data.query.watchlist[0].timestamp+'")>אשר</a>|<a onclick=acceptAllAlert()>אשר הכל</a>)</li></ul>');
checkUpdate(60000);
}
else
{
var Month = new Date().getMonth();
var notifierMonth = Month==0 ? 'בינואר' : Month==1 ? 'בפברואר' : Month==2 ? 'במרץ' : Month==3 ? 'באפריל' : Month==4 ? 'במאי' : Month==5 ? 'ביוני' : Month==6 ? 'ביולי' : Month==7 ? 'באוגוסט' : Month==8 ? 'בספטמבר' : Month==9 ? 'באוקטובר' : Month==10 ? 'בנובמבר' : 'בדצמבר';
var dateChecked = zeroPad(new Date().getDate(), 2)+' '+notifierMonth+' '+new Date().getFullYear();
$('#watchlistNotifierDiv').html('<a href="http://he.wikipedia.org/wiki/מיוחד:רשימת_המעקב">רשימת המעקב</a>: <b>'+dateChecked+'</b><br />אין שינויים חדשים.');
checkUpdate(5000);
}
}
);
}
function checkUpdate(num)
{
setTimeout(setUpdate(), num);
}
function acceptAlert(time)
{
$.cookie('WatchlistNotifier', new Date(time).getTime() + 1000, {path: '/', expires: 30});
setUpdate();
}
function acceptAllAlert()
{
$.cookie('WatchlistNotifier', new Date().getTime(), {path: '/', expires: 30});
setUpdate();
}
function zeroPad(num,count)
{
var numZeropad = num + '';
while(numZeropad.length < count)
{
numZeropad = "0" + numZeropad;
}
return numZeropad;
}
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1))
{
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}