מדיה ויקי:Gadget-Watchlist.js: הבדלים בין גרסאות בדף
מראה
גם הסר, למה לא. |
עכשיו עובד גם ב"משופרת" |
||
| שורה 1: | שורה 1: | ||
// Adds Watch/Unwatch links to recent-changes list. | |||
function wlinrc_setText(element, text) { | |||
if (typeof element.innerText != "undefined") | |||
element.innerText = text; | |||
if (typeof element.textContent != "undefined") | |||
element.textContent = text; | |||
} | |||
function wlinrc_done() { | function wlinrc_done() { | ||
if (this.readyState != 4) // this is some ajax incantation - ony "4" is good. | if (this.readyState != 4) // this is some ajax incantation - ony "4" is good. | ||
return; | return; | ||
var span = this.span; | var span = this.span; | ||
wlinrc_setText(span.firstChild, span.isWatched ? '[עקוב]' : '[הסר]'); | |||
span.source.style.fontWeight = span.isWatched ? 'normal' : 'bolder'; | |||
span.style.color = span.isWatched ? 'blue' : 'red'; | |||
span.source.style.fontWeight = span. | span.isWatched ^= true; | ||
span.style.color = span. | |||
span. | |||
} | } | ||
| שורה 15: | שורה 21: | ||
ajax.open('GET', 'http://he.wikipedia.org/w/api.php?action=watch' + | ajax.open('GET', 'http://he.wikipedia.org/w/api.php?action=watch' + | ||
'&title=' + this.target.replace(' ', '_') + | '&title=' + this.target.replace(' ', '_') + | ||
(this. | (this.isWatched ? '&unwatch=' : '')); | ||
ajax.onreadystatechange = wlinrc_done; | ajax.onreadystatechange = wlinrc_done; | ||
ajax.span = this; | ajax.span = this; | ||
this.firstChild | wlinrc_setText(this.firstChild, '[נשלח...]'); | ||
this.style.color = 'orange'; | this.style.color = 'orange'; | ||
ajax.send(null); | ajax.send(null); | ||
} | } | ||
function wlinrc_addWatchListLink( | function wlinrc_addWatchListLink(element) { | ||
var anchors = | var anchors = element.getElementsByTagName('a'); | ||
var link = '', source = null; | var link = '', source = null; | ||
for (var i = 0; i < anchors.length; i++) { | for (var i = 0; i < anchors.length; i++) { | ||
| שורה 38: | שורה 44: | ||
return; | return; | ||
var span = document.createElement(span); | var span = document.createElement(span); | ||
span. | // this is a kludge: we take advantage of the fact that watched pages appear in boldface | ||
span.appendChild(document.createTextNode(span. | // in last changes page, with className of "'mw-watched'" to deduc that this page is watched. | ||
$.extend(span.style, {cursor: 'pointer', color: span. | span.isWatched = (getElementsByClassName(element, 'strong', 'mw-watched').length > 0); | ||
span.appendChild(document.createTextNode(span.isWatched ? '[הסר]' : '[עקוב]')); | |||
$.extend(span.style, {cursor: 'pointer', color: span.isWatched ? 'red' : 'blue'}); | |||
$.extend(span, {onclick: wlinrc_watchme, target: link, source: source}); | $.extend(span, {onclick: wlinrc_watchme, target: link, source: source}); | ||
element.appendChild(span); | |||
} | } | ||
function wlinrc_addWatchListLinks() { | function wlinrc_addWatchListLinks() { | ||
// this works in "regular" changes list | |||
var kinds = ['mw-line-even', 'mw-line-odd']; | var kinds = ['mw-line-even', 'mw-line-odd']; | ||
for (var i in kinds) { | for (var i in kinds) { | ||
| שורה 52: | שורה 61: | ||
wlinrc_addWatchListLink(links[l]); | wlinrc_addWatchListLink(links[l]); | ||
} | } | ||
// this works in "enhanced" changes list. | |||
var trs = document.getElementsByTagName('tr'); | |||
for (var i = 0; i < trs.length; i++) { | |||
var isChangelist = 0; | |||
var tr = trs[i]; | |||
for (var parent = tr.parentNode; parent && !isChangelist; parent = parent.parentNode) | |||
isChangelist = $.inArray(parent.className, ["mw-changeslist-hidden","mw-changeslist-expanded"]) + 1; | |||
if (!isChangelist) | |||
wlinrc_addWatchListLink(tr.lastChild); | |||
} | |||
} | } | ||
if (wgCanonicalSpecialPageName == 'Recentchanges') | if (wgCanonicalSpecialPageName == 'Recentchanges') | ||
hookEvent("load", wlinrc_addWatchListLinks); | hookEvent("load", wlinrc_addWatchListLinks); | ||
גרסה מ־17:30, 31 במרץ 2011
// Adds Watch/Unwatch links to recent-changes list.
function wlinrc_setText(element, text) {
if (typeof element.innerText != "undefined")
element.innerText = text;
if (typeof element.textContent != "undefined")
element.textContent = text;
}
function wlinrc_done() {
if (this.readyState != 4) // this is some ajax incantation - ony "4" is good.
return;
var span = this.span;
wlinrc_setText(span.firstChild, span.isWatched ? '[עקוב]' : '[הסר]');
span.source.style.fontWeight = span.isWatched ? 'normal' : 'bolder';
span.style.color = span.isWatched ? 'blue' : 'red';
span.isWatched ^= true;
}
function wlinrc_watchme() {
var ajax = sajax_init_object();
ajax.open('GET', 'http://he.wikipedia.org/w/api.php?action=watch' +
'&title=' + this.target.replace(' ', '_') +
(this.isWatched ? '&unwatch=' : ''));
ajax.onreadystatechange = wlinrc_done;
ajax.span = this;
wlinrc_setText(this.firstChild, '[נשלח...]');
this.style.color = 'orange';
ajax.send(null);
}
function wlinrc_addWatchListLink(element) {
var anchors = element.getElementsByTagName('a');
var link = '', source = null;
for (var i = 0; i < anchors.length; i++) {
var anchor = anchors[i];
var linkString = anchor.href;
if (linkString && linkString.indexOf('/wiki/', 0) > 0) {
link = anchor.title;
source = anchor;
break;
}
}
if (!link)
return;
var span = document.createElement(span);
// 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.
span.isWatched = (getElementsByClassName(element, 'strong', 'mw-watched').length > 0);
span.appendChild(document.createTextNode(span.isWatched ? '[הסר]' : '[עקוב]'));
$.extend(span.style, {cursor: 'pointer', color: span.isWatched ? 'red' : 'blue'});
$.extend(span, {onclick: wlinrc_watchme, target: link, source: source});
element.appendChild(span);
}
function wlinrc_addWatchListLinks() {
// this works in "regular" changes list
var kinds = ['mw-line-even', 'mw-line-odd'];
for (var i in kinds) {
var links = getElementsByClassName(document, 'li', kinds[i]);
for (var l in links)
wlinrc_addWatchListLink(links[l]);
}
// this works in "enhanced" changes list.
var trs = document.getElementsByTagName('tr');
for (var i = 0; i < trs.length; i++) {
var isChangelist = 0;
var tr = trs[i];
for (var parent = tr.parentNode; parent && !isChangelist; parent = parent.parentNode)
isChangelist = $.inArray(parent.className, ["mw-changeslist-hidden","mw-changeslist-expanded"]) + 1;
if (!isChangelist)
wlinrc_addWatchListLink(tr.lastChild);
}
}
if (wgCanonicalSpecialPageName == 'Recentchanges')
hookEvent("load", wlinrc_addWatchListLinks);