מדיה ויקי:Gadget-watchlistMark.js: הבדלים בין גרסאות בדף
מראה
יותר קטן |
מ 12 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-watchlistMark.js יובאו |
||
| (6 גרסאות ביניים של 2 משתמשים אינן מוצגות) | |||
| שורה 7: | שורה 7: | ||
function readWatchList(continuation) { | function readWatchList(continuation) { | ||
var params = {action: 'query', list: 'watchlistraw', wrlimit: | var params = { action: 'query', list: 'watchlistraw', wrlimit: 'max', format: 'json', rawcontinue: 1 }; | ||
if (continuation) | if (continuation) | ||
params.wrcontinue = continuation; | params.wrcontinue = continuation; | ||
| שורה 18: | שורה 18: | ||
colorWatched(); | colorWatched(); | ||
}); | }); | ||
} | } | ||
function watchText(watch) { return (isCat ? ' ':'') + (watch ? '[עקוב]' : '[הסר]');} | function watchText(watch) { return (isCat ? ' ':'') + (watch ? '[עקוב]' : '[הסר]');} | ||
| שורה 24: | שורה 24: | ||
function colorWatched() { | function colorWatched() { | ||
var pagesList = isCat ? $('#mw-pages').find('li') : $(' | |||
var | |||
pagesList = isCat ? $('#mw-pages').find('li') : mw.util.$content.find('ul > li'), | |||
all = pagesList.each(function() { | |||
var li = $(this); | var li = $(this); | ||
var line = li.children().filter('a:last'); | var line = li.children().filter('a:last'); | ||
| שורה 35: | שורה 36: | ||
var watchLink = $('<span>', {'class': watched? 'unwatchit-link' : 'watchit-link', title: watchTitle( !watched)}) | var watchLink = $('<span>', {'class': watched? 'unwatchit-link' : 'watchit-link', title: watchTitle( !watched)}) | ||
.text(watchText(! watched)) | .text(watchText(! watched)) | ||
.click(function() {watchIt($(this), page | .click(function() {watchIt($(this), page)}); | ||
li.append(watchLink); | li.append(watchLink); | ||
}); | }), | ||
showLink = $('<a>', {href: '#', text:'הצג קישוריות מעקב'}).click( | |||
function(){ | |||
mw.util.addCSS('.unwatchit-link,.watchit-link{display:inline;}'); | |||
$(this).remove(); | |||
} | |||
); | |||
if ($('#contentSub a').length) | |||
$('#contentSub a:last').after(showLink).after(' | '); | |||
else | |||
$('#contentSub').append(showLink); | |||
} | } | ||
function watchIt(span, page | function watchIt(span, page) { | ||
var watched = span.hasClass('unwatchit-link'); | var watched = span.hasClass('unwatchit-link'); | ||
var params = {action: 'watch', title: page, format: 'json'}; | var params = {action: 'watch', title: page, format: 'json'}; | ||
| שורה 48: | שורה 60: | ||
params.token = mw.user.tokens.get('watchToken'); | params.token = mw.user.tokens.get('watchToken'); | ||
$.post(mw.util.wikiScript('api'), params, function() { | $.post(mw.util.wikiScript('api'), params, function() { | ||
span.toggleClass('unwatchit-link watchit-link') | var lines=$('a').filter(function(){return $(this).text()==page}); | ||
lines.parent().children('span.watchit-link, span.unwatchit-link') | |||
.toggleClass('unwatchit-link watchit-link') | |||
.text(watchText(watched)) | .text(watchText(watched)) | ||
.attr({title: watchTitle(watched)}); | .attr({title: watchTitle(watched)}); | ||
lines.toggleClass('iswatched'); | |||
}); | }); | ||
} | } | ||
mw.util.addCSS( | |||
".unwatchit-link{color:#a00; cursor: pointer; font-size: 70%;} \n" + | ".unwatchit-link{color:#a00; cursor: pointer; font-size: 70%;display:none} \n" + | ||
".watchit-link{color:#008; cursor: pointer; font-size: 70%;} \n" + | ".watchit-link{color:#008; cursor: pointer; font-size: 70%;display:none} \n" + | ||
".iswatched{font-weight: bolder;} | ".iswatched{font-weight: bolder;}" | ||
); | |||
readWatchList(); | |||
readWatchList(); | |||
}); // document ready | }); // document ready | ||
גרסה אחרונה מ־13:19, 5 בדצמבר 2022
// the usual prayer
if ((mw.config.get('wgNamespaceNumber') == -1 && mw.config.get('wgCanonicalSpecialPageName') == "Contributions")
|| (mw.config.get('wgNamespaceNumber') == 14))
$(document).ready(function() {
var isCat = mw.config.get('wgNamespaceNumber') == 14;
var watchList = {};
function readWatchList(continuation) {
var params = { action: 'query', list: 'watchlistraw', wrlimit: 'max', format: 'json', rawcontinue: 1 };
if (continuation)
params.wrcontinue = continuation;
$.getJSON(mw.util.wikiScript('api'), params, function(data) {
if (data && data.watchlistraw)
$.each(data.watchlistraw, function(key, val) { watchList[val.title] = true; });
if (data && data['query-continue'])
readWatchList(data['query-continue']['watchlistraw']['wrcontinue']);
else
colorWatched();
});
}
function watchText(watch) { return (isCat ? ' ':'') + (watch ? '[עקוב]' : '[הסר]');}
function watchTitle(watch){ return watch? 'הוסף לרשימת המעקב שלי' : 'הסר מרשימת המעקב שלי';}
function colorWatched() {
var
pagesList = isCat ? $('#mw-pages').find('li') : mw.util.$content.find('ul > li'),
all = pagesList.each(function() {
var li = $(this);
var line = li.children().filter('a:last');
var page = line.attr('title');
var watched = watchList[page] || false;
if (watched)
line.addClass('iswatched');
var watchLink = $('<span>', {'class': watched? 'unwatchit-link' : 'watchit-link', title: watchTitle( !watched)})
.text(watchText(! watched))
.click(function() {watchIt($(this), page)});
li.append(watchLink);
}),
showLink = $('<a>', {href: '#', text:'הצג קישוריות מעקב'}).click(
function(){
mw.util.addCSS('.unwatchit-link,.watchit-link{display:inline;}');
$(this).remove();
}
);
if ($('#contentSub a').length)
$('#contentSub a:last').after(showLink).after(' | ');
else
$('#contentSub').append(showLink);
}
function watchIt(span, page) {
var watched = span.hasClass('unwatchit-link');
var params = {action: 'watch', title: page, format: 'json'};
if (watched)
params.unwatch = '';
if (mw && mw.user && mw.user.tokens)
params.token = mw.user.tokens.get('watchToken');
$.post(mw.util.wikiScript('api'), params, function() {
var lines=$('a').filter(function(){return $(this).text()==page});
lines.parent().children('span.watchit-link, span.unwatchit-link')
.toggleClass('unwatchit-link watchit-link')
.text(watchText(watched))
.attr({title: watchTitle(watched)});
lines.toggleClass('iswatched');
});
}
mw.util.addCSS(
".unwatchit-link{color:#a00; cursor: pointer; font-size: 70%;display:none} \n" +
".watchit-link{color:#008; cursor: pointer; font-size: 70%;display:none} \n" +
".iswatched{font-weight: bolder;}"
);
readWatchList();
}); // document ready