מדיה ויקי:Gadget-WLM-draft.js
הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.
- פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload), או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
- גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
- אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh), או ללחוץ על צירוף המקשים Ctrl-F5.
- אופרה: ללחוץ על Ctrl-F5.
$(function() { var timestamp, langmark; var api = new mw.Api(); api.get({ action: 'query', format: 'json', curtimestamp: 1 }) .done(function(data) { timestamp = data.curtimestamp; }); function i18n(name) { var msg = { mark: ['סימון כעריכה שנקראה', 'Mark as read'], unmark: ['סימון כעריכה שלא נקראה', 'Mark as unread'], close: ['הסתרת העריכה', 'Hide revision'], markFlow: ['סימון זרימה כנקראה', 'Mark flow as read'], markCat: ['סימון קטגוריה כנקראה', 'Mark categorization as read'], manymarked: ['שורות סומנו', 'lines marked'], goldbutton: ['פתיחה וסימון של כל העריכות בדף הזה', 'Open and mark all this page revisions' ], jsonlost: ['קובץ קונפיגורציה לא אותר', 'Configuration file not found'], hideAll: ['הסתרת עריכות שנקראו', 'Hide all read'], showAll: ['הצגת עריכות שהוסתרו', 'Show all hidden'], whatsnew: ['מה חדש?', "What's new?"], closenew: ['סגירת רשימת החדשים', "Close the bar"], loga: ['שימו לב: רשימת המעקב כוללת רשומת יומן שלא נקראה. הדף הוא ', 'Pay attention: the watchlist includes unread log entry. Page name: ' ], logb: [', הפעולה שנעשתה היא: ', ', log action: '], logc: ['(לפרטים)', '(details)'], logd: [ 'אם ברצונכם לסמן אותה כנקראה, בדקו כי אין עריכות אחרות של הדף הזה שלא נקראו,' + ' כי גם הן יסומנו. לאחר מכן לחצו ', 'If you want to mark it as read, check that there are' + ' no other unwatched revisions of this page, because they will be marked too. Then click ' ], loge: ['כאן', 'here'], clear: ['ניקוי', 'clear'], help: ['לפרטים ראו עזרה:מנהל רשימת המעקב', ''] }; return msg[name][lang || 0]; } function button(msg, icon) { return $('<a>', { text: langmark, title: i18n(msg), href: '#nw' }) .addClass(icon + ' WLM-icon'); } function seen(obj) { obj.filter(function() { return $(this) .closest('.mw-changeslist-line-watched') .filter(notcat) .find('a[href*="diff"]') .filter(notme) .filter(function() { return $(this) .closest('.mw-enhanced-rc-nested') .length <= 0; }) .length > 0; }) .before(button('mark', 'mark-edits') .click(function() { if (config.hidemarked.edit) $('.yellowedit') .hide(); var curid = /curid=([0-9]+)/.exec($(this) .closest('table, li') .find('a[href*="curid"]') .filter(notme) .prop('href'))[1]; var $this = $(this), diff = /diff=([0-9]+)/.exec($this.parent() .find('a[href*="diff"]') .filter(notme) .prop('href'))[1], name = $this.parent() .find('.mw-changeslist-title') .text(), all = $('.mw-changeslist-line-watched .mw-changeslist-title') .filter(function() { var thediff = /.*diff=([0-9]+).*oldid.*/.exec($(this) .closest('.mw-changeslist-line-watched') .find('a[href*="diff"]') .filter(notme) .prop('href')); return thediff && $(this) .text() == name && thediff[1] <= diff; }) .closest('.mw-changeslist-line-watched'), allboth = $('.mw-changeslist-line-watched .mw-changeslist-title') .filter(function() { return $(this) .text() == name; }) .closest('.mw-changeslist-line-watched'); api.postWithToken('csrf', { action: 'setnotificationtimestamp', titles: name, newerthanrevid: diff }) .done(function() { if (all.length > 1) $this.closest('table, li') .append($('<span>') .text(' ' + all.length + ' ' + i18n('manymarked') + ' ') .css({ backgroundColor: 'red' })); all.removeClass('mw-changeslist-line-watched blueedit') .addClass('mw-changeslist-line-not-watched yellowedit') .show() .find('.mark-edits') .remove(); allboth.find('.gold-button') .remove(); $('#gold-little-' + curid) .find('a') .remove(); defected[curid] = true; unseen(all.find('span.mw-title')); if (!config.hidemarked.wait) all.hide(); }); })); } function unseen(obj) { obj.filter(function() { return $(this) .closest('table, li') .filter(notcat) .find('a[href*="oldid"]') .length > 0; }) .before(button('unmark', 'unmark-edits') .click(function() { var curid = /curid=([0-9]+)/.exec($(this) .closest('table, li') .find('a[href*="curid"]') .filter(notme) .prop('href'))[1]; var $this = $(this), diffcond = $this .closest('.mw-changeslist-line-not-watched') .find('abbr.newpage') .length > 0, oldrev = diffcond ? 0 : /oldid=([0-9]+)/.exec($this .parent() .find('a[href*="oldid"]') .filter(notme) .prop('href'))[1], diff = diffcond ? 0 : /diff=([0-9]+)/.exec($this .parent() .find('a[href*="diff"]') .filter(notme) .prop('href'))[1], name = $this .next() .text(), all = $('.mw-changeslist-line-not-watched .mw-changeslist-title') .filter(function() { var thediff = /.*diff=([0-9]+).*oldid.*/.exec($(this) .closest('.mw-changeslist-line-not-watched') .find('a[href*="diff"]') .filter(notme) .prop('href')); return thediff && $(this) .text() == name && thediff[1] >= diff; }) .closest('.mw-changeslist-line-not-watched'), allboth = $('.mw-changeslist-line-watched .mw-changeslist-title') .filter(function() { return $(this) .text() == name; }) .closest('.mw-changeslist-line-watched'); api.postWithToken('csrf', { action: 'setnotificationtimestamp', titles: name, newerthanrevid: oldrev }) .done(function() { if (all.length > 1) $this.closest('table, li') .append($('<span>') .text(' ' + all.length + ' ' + i18n('manymarked') + ' ') ); all.removeClass('mw-changeslist-line-not-watched yellowedit') .addClass('mw-changeslist-line-watched blueedit') .show() .find('.unmark-edits') .remove(); allboth.find('.gold-button') .remove(); $('#gold-little-' + curid) .find('a') .remove(); defected[curid] = true; seen(all.find('span.mw-title')); }); })); } function flowseen() { $('.mw-changeslist-line-watched a.mw-title') .parent() .prepend(button('markFlow', 'mark-all-flow-edits') .click(function() { var $this = $(this), topic = /title=[^:]*:(.+)&/.exec($this.parent() .find('a[href*="fromnotif"]') .prop('href')), page = $this .closest('.mw-changeslist-line-watched') .find('a.mw-title') .prop('title'), titles = topic ? page + '|נושא:' + topic[1] : page; api.postWithToken('csrf', { action: 'setnotificationtimestamp', titles: titles, }) .done(function() { if (config.hidemarked.flow) $this.closest('.mw-changeslist-line-watched') .hide(); $this.closest('.mw-changeslist-line-watched') .removeClass('mw-changeslist-line-watched blueedit') .addClass('mw-changeslist-line-not-watched yellowedit'); $this.remove(); }); })); } function categoryseen() { $('.mw-changeslist-line-watched span.mw-title') .filter(function() { return ($(this) .closest('.mw-changeslist-line-watched') .find('a[href*="diff"]') .length <= 0 && $(this) .closest('.mw-changeslist-line-watched') .find('abbr.newpage') .length <= 0) || $(this) .find('a.mw-changeslist-title') .parent() .next() .text() == '. .'; }) .before(button('markCat', 'mark-cat-edits') .click(function() { var $this = $(this), page = $this.parent() .find('a.mw-changeslist-title') .prop('title'); api.postWithToken('csrf', { action: 'setnotificationtimestamp', titles: page, }) .done(function() { if (config.hidemarked.categorization) $this.closest('.mw-changeslist-line-watched') .hide(); $this.closest('.mw-changeslist-line-watched') .removeClass('mw-changeslist-line-watched blueedit') .addClass('mw-changeslist-line-not-watched yellowedit'); $this.remove(); }); })); } function checklog() { api.get({ action: 'query', format: 'json', list: 'watchlist', indexpageids: 1, wllimit: 500, wlprop: 'title|loginfo', wlshow: 'unread', wltype: 'log' }) .done(function(data) { var firstname = data.query.watchlist; if (firstname.length > 0) { firstname = firstname[0]; $('#hideAll') .after($('<div>', { id: 'logmessage' }) .addClass('blueedit') .append($('<span>') .text(i18n('loga'))) .append($('<span>') .text(firstname.title) .css({ fontWeight: 'bold', })) .append($('<span>') .text(i18n('logb') + firstname.logaction + ' ')) .append($('<a>', { href: 'https://he.wikipedia.org//w/api.php?action=query&format=rawfm&list=watchlist&' + 'indexpageids=1&wllimit=500&wlprop=title%7Cloginfo&wlshow=unread&wltype=log', text: i18n('logc') })) .append($('<span>') .text('. ' + i18n('logd') + ' ')) .append($('<a>', { target: '_blank' }) .text(i18n('loge')) .click(function() { api.postWithToken('csrf', { action: 'setnotificationtimestamp', titles: firstname.title }) .done(function() { $('#logmessage') .remove(); var all = $( '.mw-changeslist-line-watched a.mw-changeslist-title') .filter(function() { return $(this) .prop('title') == firstname.title; }) .closest('.mw-changeslist-line-watched'); all.removeClass('mw-changeslist-line-watched blueedit') .addClass('mw-changeslist-line-not-watched yellowedit') .show() .find('.unmark-edits') .remove(); if (config.hidemarked.edit) $('.yellowedit') .hide(); seen(all.find('span.mw-title')); if (all.length > 0) $('#hideAll') .after($('<div>') .text(' ' + all.length + ' ' + i18n('manymarked') + ' ') ) .addClass('yellowedit'); checklog(); }); })) .append($('<span>') .text('.') )); } }); } function goldbutton() { $('.mw-changeslist-line-watched') .find('abbr.newpage') .each(function() { var curid = /curid=([0-9]+)/.exec($(this) .closest('table, li') .find('a[href*="curid"]') .filter(notme) .prop('href')); if (curid !== null && curid.length > 1) defected[curid[1]] = true; }); $('.close-edit') .filter(function() { return $(this) .closest('.mw-changeslist-line-watched') .filter(notcat) .find('a[href*="diff"]') .filter(notme) .filter(function() { return $(this) .closest('.mw-enhanced-rc-nested') .length <= 0; }) .length > 0 && $(this) .closest('.mw-changeslist-line-watched') .find('a.mw-title') .length <= 0; }) .each(function() { var curid = /curid=([0-9]+)/.exec($(this) .closest('table, li') .find('a[href*="curid"]') .filter(notme) .prop('href'))[1]; var name = $(this) .closest('.mw-changeslist-line-watched') .find('.mw-changeslist-title') .text(), checked = $('.mw-changeslist-title') .filter(function() { return $(this) .text() == name; }) .closest('.mw-changeslist-line-watched'), nonew = checked .find('abbr.newpage') .length <= 0, min = Infinity; if (nonew) { checked .find('a[href*="oldid"]') .filter(notme) .filter(function() { return ($(this) .text() == messages.diff || $(this) .text() == messages.last) && ($(this) .closest('.mw-enhanced-rc-nested') .closest('.mw-enhanced-watched') .length > 0 || $(this) .closest('.mw-enhanced-rc-nested') .length <= 0); }) .each(function() { var old = /oldid=([0-9]+)/.exec($(this) .prop('href')); min = old ? Math.min(min, old[1]) : min; }); } if (min > 0 && min != Infinity && nonew) { $(this) .after($('<a>', { text: langmark, title: i18n('goldbutton'), target: '_blank', href: 'https://he.wikipedia.org/w/index.php?title=' + name + '&redirect=no&diff=cur&oldid=' + min }) .addClass('gold-button WLM-icon gold-' + curid) .click(function() { if (config.hidemarked.edit) $('.yellowedit') .hide(); var all = $('.mw-changeslist-line-watched .mw-changeslist-title') .filter(function() { return $(this) .text() == name; }) .closest('.mw-changeslist-line-watched'); if (all.length > 1) $(this) .closest('table, li') .append($('<span>') .text(' ' + all.length + ' ' + i18n('manymarked') + ' ') .css({ backgroundColor: 'red' })); all.removeClass('mw-changeslist-line-watched blueedit') .addClass('mw-changeslist-line-not-watched yellowedit') .show() .find('.mark-edits, .gold-button') .remove(); $('.gold-' + curid) .remove(); $('#gold-little-' + curid) .remove(); unseen(all.find('span.mw-title')); })); } }); } function closeedit() { var btn = button('close', 'close-edit') .click(function() { $(this) .closest( '.mw-changeslist-line-not-watched, .mw-changeslist-line-watched') .hide(); }); $('li span.mw-changeslist-date') .parent() .prepend(btn); $('td.mw-enhanced-rc') .parent() .filter(function() { return $(this) .find('td.mw-enhanced-rc-nested') .length <= 0; }) .prepend($('<td>') .html(btn) .css({ whiteSpace: 'nowrap' })); $('td.mw-enhanced-rc') .parent() .find('td.mw-enhanced-rc-nested') .prev() .before($('<td>')); } function notme() { return !$(this) .hasClass('WLM-icon'); } function notcat() { return $(this) .find('a.mw-changeslist-title') .parent() .next() .text() != '. .'; } function whatsnew() { $('#newrevs') .remove(); api.get({ action: 'query', format: 'json', list: 'watchlist', indexpageids: 1, wldir: 'newer', wllimit: 500, wlprop: 'title|ids', wlshow: 'unread', wltype: 'edit|new', wlstart: timestamp, wlallrev: 1, errorformat: 'wikitext' }) .done(function(data) { var ans = data.query.watchlist; $('#hideAll') .after($('<div>', { id: 'newrevs', text: '[' }) .addClass('blueedit')); var newmap = {}; Object.keys(ans) .map(function(key) { var id = ans[key].pageid; if (id in newmap) { if (ans[key].old_revid < newmap[id].oldid) newmap[id].oldid = ans[key].old_revid; } else newmap[id] = { title: ans[key].title, oldid: ans[key].old_revid }; }); Object.keys(newmap) .map(function(data) { var vvv = $('.gold-' + data) .length; if (defected[data]) $('#newrevs') .append($('<span>', { text: newmap[data].title + ',' + langmark + ' ' })); else if (vvv > 0) $('#newrevs') .append($('<span>', { text: newmap[data].title + ',' + langmark + ' ', id: 'gold-little-' + data }) .prepend($('.gold-' + data) .clone(true, true)[0])); else $('#newrevs') .append($('<span>', { text: ',' + langmark + ' ' }) .prepend($('<a>', { text: newmap[data].title, href: 'https://he.wikipedia.org/w/index.php?title=' + newmap[data].title + '&redirect=no&diff=cur&oldid=' + newmap[data].oldid, target: '_blank' }) .click(function() { $(this) .parent() . remove(); $('.yellowedit') .hide(); $('body') .trigger('script-88-pretend-clicked'); }))); }); $('#newrevs') .append($('<span>', { text: langmark, title: i18n('closenew'), id: 'closenew' }) .click(function() { $('#newrevs') .remove(); $('body') .trigger('script-88-pretend-clicked'); }) ) .append(']'); }) .done(function() { $('body') .trigger('script-88-pretend-clicked'); }); } function hider(state) { $('#newrevs') .remove(); if (config.edit[state]) $('table.mw-changeslist-line-not-watched, li.mw-changeslist-line-not-watched') .filter(function() { return $(this) .find('abbr.wikibase-edit') .length <= 0; }) .hide(); if (config.log[state]) $('[class*="mw-changeslist-log"]') .hide(); if (config.wikidata[state]) $('abbr.wikibase-edit') .closest('.mw-changeslist-line-watched, .mw-changeslist-line-not-watched') .hide(); $('#logmessage') .hide(); $('#watchlist-preamble') .hide(); $('.WLM-mobile input[name="mw-watchlist-reset-submit"]') .hide(); } function unhider() { whatsnew(); $('table.mw-changeslist-line-watched, li.mw-changeslist-line-watched') .show(); if (config.edit.show) $('table.mw-changeslist-line-not-watched, li.mw-changeslist-line-not-watched') .filter(function() { return $(this) .find('abbr.wikibase-edit') .length <= 0; }) .show(); if (config.log.show) $('[class*="mw-changeslist-log"]') .show(); if (config.wikidata.show) $('abbr.wikibase-edit') .closest('.mw-changeslist-line-not-watched') .show(); $('#logmessage') .show(); $('#watchlist-preamble') .show(); $('input[name="mw-watchlist-reset-submit"]') .show(); } function main() { $('a.mw-unwatch-link') .each(function() { $(this) .prepend('\xa0\xa0\xa0') .insertAfter($(this) .parent() .parent() .children() .children() .last()); }); seen($('.mw-changeslist-line-watched span.mw-title')); unseen($('.mw-changeslist-line-not-watched span.mw-title')); flowseen(); categoryseen(); closeedit(); goldbutton(); hider('starthidden'); } function demo() { $('.mark-edits') .click(function() { var id = $(this) .parent() .prop('id'); $(this) .closest('table') .find('.mark-edits') .filter(function() { return $(this) .parent() .prop('id') <= id; }) .removeClass('mark-edits') .addClass('unmark-edits') .parent() .removeClass('blueedit') .addClass('yellowedit'); demo(); }); $('.unmark-edits') .click(function() { var id = $(this) .parent() .prop('id'); $(this) .closest('table') .find('.unmark-edits') .filter(function() { return $(this) .parent() .prop('id') >= id; }) .removeClass('unmark-edits') .addClass('mark-edits') .parent() .removeClass('yellowedit') .addClass('blueedit'); demo(); }); } if (mw.config.get('wgCanonicalSpecialPageName') == 'Watchlist') { var langcode = mw.config.get('wgUserLanguage'), lang = langcode == 'he' ? 0 : 1, extendwatchlist = mw.user.options.get('extendwatchlist'), defected = {}, config, messages; langmark = langcode == 'he' ? '\u200f' : '\u200e'; if (extendwatchlist == 1) { $('.mw-body-content') .addClass(typeof window.orientation == 'undefined' ? 'WLM-desktop' : 'WLM-mobile'); importStylesheet('מדיה ויקי:Gadget-WLM.css'); importStylesheet('משתמש:' + mw.config.get('wgUserName') + '/WLM.css'); importStylesheet('משתמש:' + mw.config.get('wgUserName') + '/common.css'); api.getMessages(['diff', 'last'], { amlang: langcode }) .then(function(result) { messages = result; }) .then(function() { $.get(mw.util.wikiScript(), { title: 'מדיה ויקי:Gadget-WLM.json', action: 'raw' }) .done(function(data) { config = JSON.parse(data); $.get(mw.util.wikiScript(), { title: 'משתמש:' + mw.config.get('wgUserName') + '/WLM.json', action: 'raw' }) .done(function(data1) { config = JSON.parse(data1); }) .always(main); }) .fail(function() { console.log('ERR: ' + i18n('jsonlost')); }); }); $('#mw-watchlist-form') .after($('<input>', { id: 'hideAll', type: 'submit', title: i18n('help') }) .click(function() { hider('hide'); })) .after($('<span>', { text: 'place', id: 'placeholder' }) .css({ visibility: 'hidden', })) .after($('<input>', { id: 'showAll', type: 'submit', title: i18n('help') }) .click(unhider)) .after($('<span>', { text: 'place', id: 'placeholder' }) .css({ visibility: 'hidden', })) .after($('<input>', { id: 'whatsnew', type: 'submit', title: i18n('help') }) .click(whatsnew)) .after($('<div>', { text: 'place', id: 'placeline' }) .css({ visibility: 'hidden', fontSize: '50%' })); $('#hideAll') .attr('value', i18n('hideAll')); $('#showAll') .attr('value', i18n('showAll')); $('#whatsnew') .attr('value', i18n('whatsnew')); checklog(); } } else if (mw.config.get('wgPageName') == 'עזרה:WLM') { $('.prescell') .attr('align', 'center') .each(function() { $(this) .html($('<a>') .addClass($(this) .attr('class'))); $(this) .removeClass('mark-edits unmark-edits'); }); $('#clear') .prepend($('<input>', { id: 'clearbutton', type: 'submit' }) .click(function() { $('.blueedit, .yellowedit') .removeClass('blueedit yellowedit'); })); $('#clearbutton') .attr('value', i18n('clear')); demo(); } });