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

מ 25 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-Watchlist.js יובאו
 
(7 גרסאות ביניים של משתמש אחר אחד אינן מוצגות)
שורה 1: שורה 1:
if ($.inArray(wgCanonicalSpecialPageName, ['Recentchanges', 'Watchlist', 'Newpages']) + 1)
if ($.inArray( mw.config.get('wgCanonicalSpecialPageName'), ['Recentchanges', 'Watchlist', 'Newpages']) + 1)
$(document).ready(function() {
$(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) {
שורה 11: שורה 11:


function wlinrc_done(span) {
function wlinrc_done(span) {
if (wgCanonicalSpecialPageName == 'Watchlist') {
if (cannonicalPageName == 'Watchlist') {
span.parentNode.removeChild(span);
span.parentNode.removeChild(span);
return;
return;
שורה 28: שורה 28:
params.token = mw.user.tokens.get('watchToken');
params.token = mw.user.tokens.get('watchToken');
var span = this;
var span = this;
$.post(mw.util.wikiScript('api'), params, function() { wlinrc_done(span); })
$.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';
שורה 34: שורה 34:


function wlinrc_addWatchListLink(element, anchor) {
function wlinrc_addWatchListLink(element, anchor) {
    if (!element)
        element = this;
var link, source;
var link, source;
if (anchor) {
if (anchor) {
שורה 42: שורה 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) {
שורה 57: שורה 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.
var inWatchList = wgCanonicalSpecialPageName == 'Watchlist';
var inWatchList = cannonicalPageName == 'Watchlist';
span.isWatched =  inWatchList || getElementsByClassName(element, 'strong', 'mw-watched').length > 0;
span.isWatched =  inWatchList || $(element).closest('.mw-changeslist-line-watched').length;
var stopFollowStr = inWatchList ? '[הסר]' : '[הפסק לעקוב]';
var stopFollowStr = inWatchList  
span.appendChild(document.createTextNode(span.isWatched ? stopFollowStr  : '[עקוב]'));
? (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.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});
שורה 68: שורה 69:


// this works in "regular" changes list
// this works in "regular" changes list
$('li.mw-line-even, li.mw-line-odd').each(wlinrc_addWatchListLink);
$('li.mw-line-even, li.mw-line-odd').each(function(i,e){wlinrc_addWatchListLink(e)});


// this works in "enhanced" changes list.
// this works in "enhanced" changes list.
שורה 76: שורה 77:
wlinrc_addWatchListLink(this, a[0]);
wlinrc_addWatchListLink(this, a[0]);
});
});
if (wgCanonicalSpecialPageName == 'Newpages') {
 
var lis = $(".mw-newpages-time").parent();
if (cannonicalPageName == 'Newpages') {
for (var i = 0; i < lis.length; i++) {
$(".mw-newpages-time").parent().each(function() {
var anchors = $(lis[i]).find(".mw-newpages-time").next();
var anchors = $(this).find(".mw-newpages-time").next();
if (anchors.length)
if (anchors.length)
wlinrc_addWatchListLink(lis[i], anchors[0]);
wlinrc_addWatchListLink(this, anchors[0]);
}
});
}
}


});
});