מדיה ויקי:Gadget-Watchlist.js: הבדלים בין גרסאות בדף

גם מ"התרומות שלי".
מ 25 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-Watchlist.js יובאו
 
(18 גרסאות ביניים של 2 משתמשים אינן מוצגות)
שורה 1: שורה 1:
if ($.inArray( mw.config.get('wgCanonicalSpecialPageName'), ['Recentchanges', 'Watchlist', 'Newpages']) + 1)
$(document).ready(function() {
var cannonicalPageName = mw.config.get('wgCanonicalSpecialPageName');
// Adds Watch/Unwatch links to recent-changes list.
// Adds Watch/Unwatch links to recent-changes list.
function wlinrc_setText(element, text) {
function wlinrc_setText(element, text) {
שורה 7: שורה 10:
}
}


function wlinrc_done() {
function wlinrc_done(span) {
if (this.readyState != 4) // this is some ajax incantation - ony "4" is good.
if (cannonicalPageName == 'Watchlist') {
return;
var span = this.span;
if ($.inArray(wgCanonicalSpecialPageName, ['Watchlist', 'Contributions']) + 1) {
span.parentNode.removeChild(span);
span.parentNode.removeChild(span);
return;
return;
שורה 17: שורה 17:
wlinrc_setText(span.firstChild, span.isWatched ? '[עקוב]' : '[הפסק לעקוב]');
wlinrc_setText(span.firstChild, span.isWatched ? '[עקוב]' : '[הפסק לעקוב]');
span.source.style.fontWeight = span.isWatched ? 'normal' : 'bolder';
span.source.style.fontWeight = span.isWatched ? 'normal' : 'bolder';
span.style.color = span.isWatched ? 'blue' : 'red';
span.style.color = span.isWatched ? 'blue' : 'green';
span.isWatched ^= true;
span.isWatched ^= true;
}
}


function wlinrc_watchme() {
function wlinrc_watchme() {
var ajax = sajax_init_object();
var params = {action: 'watch', title: this.target.replace(' ', '_') , format: 'json'};
ajax.open('GET', 'http://he.wikipedia.org/w/api.php?action=watch' +
if (this.isWatched)
'&title=' + this.target.replace(' ', '_') +
params.unwatch = '';
(this.isWatched ? '&unwatch=' : ''));
if (mw && mw.user && mw.user.tokens)
ajax.onreadystatechange = wlinrc_done;
params.token = mw.user.tokens.get('watchToken');
ajax.span = this;
var span = this;
$.post(mw.util.wikiScript('api'), params, function() { wlinrc_done(span); });
wlinrc_setText(this.firstChild, '[נשלח...]');
wlinrc_setText(this.firstChild, '[נשלח...]');
this.style.color = 'orange';
this.style.color = 'orange';
ajax.send(null);
}
}


שורה 40: שורה 40:
} else {
} else {
var anchors = element.getElementsByTagName('a');
var anchors = element.getElementsByTagName('a');
var link = '', source = null;
link = '';
source = null;
for (var i = 0; i < anchors.length; i++) {
for (var i = 0; i < anchors.length; i++) {
var anchor = anchors[i];
anchor = anchors[i];
var linkString = anchor.href;
var linkString = anchor.href;
if (linkString && linkString.indexOf('/wiki/', 0) > 0) {
if (linkString && linkString.indexOf('/wiki/', 0) > 0) {
שורה 55: שורה 56:
var span = document.createElement(span);
var span = document.createElement(span);
// this is a kludge: we take advantage of the fact that watched pages appear in boldface  
// this is a kludge: we take advantage of the fact that watched pages appear in boldface  
// in last changes page, with className of "'mw-watched'" to deduc that this page is watched.
// in last changes page, with className of "'mw-changeslist-line-watched'" to deduc that this page is watched.
span.isWatched = wgCanonicalSpecialPageName == 'Watchlist' || getElementsByClassName(element, 'strong', 'mw-watched').length > 0;
var inWatchList = cannonicalPageName == 'Watchlist';
span.appendChild(document.createTextNode(span.isWatched ? '[הפסק לעקוב]' : '[עקוב]'));
span.isWatched =  inWatchList || $(element).closest('.mw-changeslist-line-watched').length;
$.extend(span.style, {cursor: 'pointer', color: span.isWatched ? 'red' : 'blue'});
var stopFollowStr = inWatchList
? (mw.user.options.get('watchlistunwatchlinks') === "1" ? null : '[הסר]' )
: '[הפסק לעקוב]';
if (stopFollowStr) span.appendChild(document.createTextNode(span.isWatched ? stopFollowStr  : '[עקוב]'));
$.extend(span.style, {cursor: 'pointer', color: span.isWatched ? 'green' : 'blue'});
$.extend(span, {onclick: wlinrc_watchme, target: link, source: source});
$.extend(span, {onclick: wlinrc_watchme, target: link, source: source});
element.appendChild(span);
element.appendChild(span);
}
}


function wlinrc_addWatchListLinks() {
// this works in "regular" changes list
// this works in "regular" changes list
$('li.mw-line-even, li.mw-line-odd').each(function(i,e){wlinrc_addWatchListLink(e)});
var kinds = ['mw-line-even', 'mw-line-odd'];
 
for (var i in kinds) {
// this works in "enhanced" changes list.
var links = getElementsByClassName(document, 'li', kinds[i]);
var tds = $("td.mw-enhanced-rc").next().each(function() {
for (var l in links)
var a = $(this).find("a:eq(0)");
wlinrc_addWatchListLink(links[l]);
if (a.length)
}
wlinrc_addWatchListLink(this, a[0]);
// this works in "enhanced" changes list.
});
var tds = $("td.mw-enhanced-rc").next();
 
for (var i = 0; i < tds.length; i++) {
if (cannonicalPageName == 'Newpages') {
var a = $(tds[i]).find("a:eq(0)");
$(".mw-newpages-time").parent().each(function() {
if (a.length)
var anchors = $(this).find(".mw-newpages-time").next();
wlinrc_addWatchListLink(tds[i], a[0]);
if (anchors.length)
}
wlinrc_addWatchListLink(this, anchors[0]);
if (wgCanonicalSpecialPageName == 'Contributions') {
});
var lis = $("#bodyContent").find("li");
for (var i = 0; i < lis.length; i++)  
wlinrc_addWatchListLink(lis[i]);
}
}
}


if ($.inArray(wgCanonicalSpecialPageName, ['Recentchanges', 'Watchlist', 'Contributions']) + 1)
});
hookEvent("load", wlinrc_addWatchListLinks);