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

תיקון הסקריפט במצב "משופרת" + הוספת "הפסק לעקוב" מרשימת המעקב.
שורה 11: שורה 11:
return;
return;
var span = this.span;
var span = this.span;
if (wgCanonicalSpecialPageName == 'Watchlist') {
span.parentNode.removeChild(span);
return;
}
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';
שורה 29: שורה 33:
}
}


function wlinrc_addWatchListLink(element) {
function wlinrc_addWatchListLink(element, anchor) {
var anchors = element.getElementsByTagName('a');
var link, source;
var link = '', source = null;
if (anchor) {
for (var i = 0; i < anchors.length; i++) {
source = anchor;
var anchor = anchors[i];
link = anchor.title;
var linkString = anchor.href;
} else {
if (linkString && linkString.indexOf('/wiki/', 0) > 0) {
var anchors = element.getElementsByTagName('a');
link = anchor.title;
var link = '', source = null;
source = anchor;
for (var i = 0; i < anchors.length; i++) {
break;
var anchor = anchors[i];
var linkString = anchor.href;
if (linkString && linkString.indexOf('/wiki/', 0) > 0) {
link = anchor.title;
source = anchor;
break;
}
}
}
if (!link)
return;
}
}
if (!link)
return;
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-watched'" to deduc that this page is watched.
span.isWatched = (getElementsByClassName(element, 'strong', 'mw-watched').length > 0);
span.isWatched = wgCanonicalSpecialPageName == 'Watchlist' || getElementsByClassName(element, 'strong', 'mw-watched').length > 0;
span.appendChild(document.createTextNode(span.isWatched ? '[הפסק לעקוב]' : '[עקוב]'));
span.appendChild(document.createTextNode(span.isWatched ? '[הפסק לעקוב]' : '[עקוב]'));
$.extend(span.style, {cursor: 'pointer', color: span.isWatched ? 'red' : 'blue'});
$.extend(span.style, {cursor: 'pointer', color: span.isWatched ? 'red' : 'blue'});
שורה 62: שורה 72:
}
}
// this works in "enhanced" changes list.
// this works in "enhanced" changes list.
var trs = document.getElementsByTagName('tr');
var tds = $("td.mw-enhanced-rc").next();
for (var i = 0; i < trs.length; i++) {
for (var i = 0; i < tds.length; i++) {
var isChangelist = 0;
var a = $(tds[i]).find("a:eq(0)");
var tr = trs[i];
if (a.length)
for (var parent = tr.parentNode; parent && !isChangelist; parent = parent.parentNode)
wlinrc_addWatchListLink(tds[i], a[0]);
isChangelist = $.inArray(parent.className, ["mw-changeslist-hidden","mw-changeslist-expanded"]) + 1;
if (!isChangelist)
wlinrc_addWatchListLink(tr.lastChild);
}
}
}
}


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