לדלג לתוכן

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

מתוך צפונות ויקי
אין תקציר עריכה
אין תקציר עריכה
שורה 11: שורה 11:


$(function() {
$(function() {
    function i18n(name) {
function i18n(name) {
        var msg = {
var msg = {
            mark: ['סימון כעריכה שנקראה', 'Mark as read'],
mark: ['סימון כעריכה שנקראה', 'Mark as read'],
            unmark: ['סימון כעריכה שלא נקראה', 'Mark as unread'],
unmark: ['סימון כעריכה שלא נקראה', 'Mark as unread'],
            close: ['הסתרת העריכה', 'Hide revision'],
close: ['הסתרת העריכה', 'Hide revision'],
            markFlow: ['סימון זרימה כנקראה', 'Mark flow as read'],
markFlow: ['סימון זרימה כנקראה', 'Mark flow as read'],
            markCat: ['סימון קטגוריה כנקראה', 'Mark categorization as read'],
markCat: ['סימון קטגוריה כנקראה', 'Mark categorization as read'],
            manymarked: ['שורות סומנו', 'lines marked'],
manymarked: ['שורות סומנו', 'lines marked'],
            goldbutton: ['פתיחה וסימון של כל העריכות בדף הזה', 'Open and mark all this page revisions'],
goldbutton: ['פתיחה וסימון של כל העריכות בדף הזה', 'Open and mark all this page revisions'],
            jsonlost: ['קובץ קונפיגורציה לא אותר', 'Configuration file not found'],
jsonlost: ['קובץ קונפיגורציה לא אותר', 'Configuration file not found'],
            hideAll: ['הסתרת עריכות שנקראו', 'Hide all read'],
hideAll: ['הסתרת עריכות שנקראו', 'Hide all read'],
            showAll: ['הצגת עריכות שהוסתרו', 'Show all hidden'],
showAll: ['הצגת עריכות שהוסתרו', 'Show all hidden'],
            whatsnew: ['מה חדש?', "What's new?"],
whatsnew: ['מה חדש?', "What's new?"],
            loga: ['שימו לב: רשימת המעקב כוללת רשומת יומן שלא נקראה. הדף הוא ',
loga: ['שימו לב: רשימת המעקב כוללת רשומת יומן שלא נקראה. הדף הוא ',
                'Pay attention: the watchlist includes unread log entry. Page name: '
'Pay attention: the watchlist includes unread log entry. Page name: '
            ],
],
            logb: [', הפעולה שנעשתה היא: ', ', log action: '],
logb: [', הפעולה שנעשתה היא: ', ', log action: '],
            logc: ['(לפרטים)', '(details)'],
logc: ['(לפרטים)', '(details)'],
            logd: ['אם ברצונכם לסמן אותה כנקראה, בדקו כי אין עריכות אחרות של הדף הזה שלא נקראו,' +
logd: ['אם ברצונכם לסמן אותה כנקראה, בדקו כי אין עריכות אחרות של הדף הזה שלא נקראו,' +
                ' כי גם הן יסומנו. לאחר מכן לחצו ', 'If you want to mark it as read, check that there are' +
' כי גם הן יסומנו. לאחר מכן לחצו ', '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 '
' no other unwatched revisions of this page, because they will be marked too. Then click '
            ],
],
            loge: ['כאן', 'here'],
loge: ['כאן', 'here'],
            clear: ['ניקוי', 'clear'],
clear: ['ניקוי', 'clear'],
            help: ['לפרטים ראו עזרה:מנהל רשימת המעקב', '']
help: ['לפרטים ראו עזרה:מנהל רשימת המעקב', '']
        };
};
        return msg[name][lang || 0];
return msg[name][lang || 0];
    }
}


    function button(msg, icon) {
function button(msg, icon) {
        return $('<a>', {
return $('<a>', {
                text: '\u200f',
text: '\u200f',
                title: i18n(msg),
title: i18n(msg),
                href: '#nw'
href: '#nw'
            })
})
            .addClass(icon + ' WLM-icon');
.addClass(icon + ' WLM-icon');
    }
}


    function seen(obj) {
function seen(obj) {
        obj.filter(function() {
obj.filter(function() {
                return $(this)
return $(this)
                    .closest('.mw-changeslist-line-watched')
.closest('.mw-changeslist-line-watched')
                    .filter(notcat)
.filter(notcat)
                    .find('a[href*="diff"]')
.find('a[href*="diff"]')
                    .filter(notme)
.filter(notme)
                    .filter(function() {
.filter(function() {
                        return $(this)
return $(this)
                            .closest('.mw-enhanced-rc-nested')
.closest('.mw-enhanced-rc-nested')
                            .length <= 0;
.length <= 0;
                    })
})
                    .length > 0;
.length > 0;
            })
})
            .before(button('mark', 'mark-edits')
.before(button('mark', 'mark-edits')
                .click(function() {
.click(function() {
                    if (config.hidemarked.edit)
if (config.hidemarked.edit)
                        $('.yellowedit')
$('.yellowedit')
                        .hide();
.hide();
        var curid = /curid=([0-9]+)/.exec($(this)
var curid = /curid=([0-9]+)/.exec($(this)
        .closest('table, li')
.closest('table, li')
        .find('a[href*="curid"]')
.find('a[href*="curid"]')
        .filter(notme)
.filter(notme)
        .prop('href'))[1];
.prop('href'))[1];
                    var $this = $(this),
var $this = $(this),
                        diff = /diff=([0-9]+)/.exec($this.parent()
diff = /diff=([0-9]+)/.exec($this.parent()
                            .find('a[href*="diff"]')
.find('a[href*="diff"]')
                            .filter(notme)
.filter(notme)
                            .prop('href'))[1],
.prop('href'))[1],
                        name = $this.parent()
name = $this.parent()
                        .find('.mw-changeslist-title')
.find('.mw-changeslist-title')
                        .text(),
.text(),
                        all = $('.mw-changeslist-line-watched .mw-changeslist-title')
all = $('.mw-changeslist-line-watched .mw-changeslist-title')
                        .filter(function() {
.filter(function() {
                            var thediff = /.*diff=([0-9]+).*oldid.*/.exec($(this)
var thediff = /.*diff=([0-9]+).*oldid.*/.exec($(this)
                                .closest('.mw-changeslist-line-watched')
.closest('.mw-changeslist-line-watched')
                                .find('a[href*="diff"]')
.find('a[href*="diff"]')
                                .filter(notme)
.filter(notme)
                                .prop('href'));
.prop('href'));
                            return thediff && $(this)
return thediff && $(this)
                                .text() == name && thediff[1] <= diff;
.text() == name && thediff[1] <= diff;
                        })
})
                        .closest('.mw-changeslist-line-watched'),
.closest('.mw-changeslist-line-watched'),
                        allboth = $('.mw-changeslist-line-watched .mw-changeslist-title')
allboth = $('.mw-changeslist-line-watched .mw-changeslist-title')
                        .filter(function() {
.filter(function() {
                            return $(this)
return $(this)
                                .text() == name;
.text() == name;
                        })
})
                        .closest('.mw-changeslist-line-watched');
.closest('.mw-changeslist-line-watched');
                    new mw.Api()
new mw.Api()
                        .postWithToken('csrf', {
.postWithToken('csrf', {
                            action: 'setnotificationtimestamp',
action: 'setnotificationtimestamp',
                            titles: name,
titles: name,
                            newerthanrevid: diff
newerthanrevid: diff
                        })
})
                        .done(function() {
.done(function() {
                            if (all.length > 1)
if (all.length > 1)
                                $this.closest('table, li')
$this.closest('table, li')
                                .append($('<span>')
.append($('<span>')
                                    .text(' ' + all.length + ' ' + i18n('manymarked') + ' ')
.text(' ' + all.length + ' ' + i18n('manymarked') + ' ')
                                    .css({
.css({
                                        backgroundColor: 'red'
backgroundColor: 'red'
                                    }));
}));
                            all.removeClass('mw-changeslist-line-watched blueedit')
all.removeClass('mw-changeslist-line-watched blueedit')
                                .addClass('mw-changeslist-line-not-watched yellowedit')
.addClass('mw-changeslist-line-not-watched yellowedit')
                                .show()
.show()
                                .find('.mark-edits')
.find('.mark-edits')
                                .remove();
.remove();
                            allboth.find('.gold-button')
allboth.find('.gold-button')
                                .remove();
.remove();
                            $('#gold-little-' + curid)
$('#gold-little-' + curid)
                            .find('a')
.find('a')
                            .remove();
.remove();
                            defected[curid] = true;
defected[curid] = true;
                            unseen(all.find('span.mw-title'));
unseen(all.find('span.mw-title'));
                            if (!config.hidemarked.wait)
if (!config.hidemarked.wait)
                                all.hide();
all.hide();
                        });
});
                }));
}));
    }
}


    function unseen(obj) {
function unseen(obj) {
        obj.filter(function() {
obj.filter(function() {
                return $(this)
return $(this)
                    .closest('table, li')
.closest('table, li')
                    .filter(notcat)
.filter(notcat)
                    .find('a[href*="oldid"]')
.find('a[href*="oldid"]')
                    .length > 0;
.length > 0;
            })
})
            .before(button('unmark', 'unmark-edits')
.before(button('unmark', 'unmark-edits')
                .click(function() {
.click(function() {
        var curid = /curid=([0-9]+)/.exec($(this)
var curid = /curid=([0-9]+)/.exec($(this)
        .closest('table, li')
.closest('table, li')
        .find('a[href*="curid"]')
.find('a[href*="curid"]')
        .filter(notme)
.filter(notme)
        .prop('href'))[1];
.prop('href'))[1];
                    var $this = $(this),
var $this = $(this),
                        diffcond = $this
diffcond = $this
                        .closest('.mw-changeslist-line-not-watched')
.closest('.mw-changeslist-line-not-watched')
                        .find('abbr.newpage')
.find('abbr.newpage')
                        .length > 0,
.length > 0,
                        oldrev = diffcond ? 0 : /oldid=([0-9]+)/.exec($this
oldrev = diffcond ? 0 : /oldid=([0-9]+)/.exec($this
                            .parent()
.parent()
                            .find('a[href*="oldid"]')
.find('a[href*="oldid"]')
                            .filter(notme)
.filter(notme)
                            .prop('href'))[1],
.prop('href'))[1],
                        diff = diffcond ? 0 : /diff=([0-9]+)/.exec($this
diff = diffcond ? 0 : /diff=([0-9]+)/.exec($this
                            .parent()
.parent()
                            .find('a[href*="diff"]')
.find('a[href*="diff"]')
                            .filter(notme)
.filter(notme)
                            .prop('href'))[1],
.prop('href'))[1],
                        name = $this
name = $this
                        .next()
.next()
                        .text(),
.text(),
                        all = $('.mw-changeslist-line-not-watched .mw-changeslist-title')
all = $('.mw-changeslist-line-not-watched .mw-changeslist-title')
                        .filter(function() {
.filter(function() {
                            var thediff = /.*diff=([0-9]+).*oldid.*/.exec($(this)
var thediff = /.*diff=([0-9]+).*oldid.*/.exec($(this)
                                .closest('.mw-changeslist-line-not-watched')
.closest('.mw-changeslist-line-not-watched')
                                .find('a[href*="diff"]')
.find('a[href*="diff"]')
                                .filter(notme)
.filter(notme)
                                .prop('href'));
.prop('href'));
                            return thediff && $(this)
return thediff && $(this)
                                .text() == name && thediff[1] >= diff;
.text() == name && thediff[1] >= diff;
                        })
})
                        .closest('.mw-changeslist-line-not-watched'),
.closest('.mw-changeslist-line-not-watched'),
                        allboth = $('.mw-changeslist-line-watched .mw-changeslist-title')
allboth = $('.mw-changeslist-line-watched .mw-changeslist-title')
                        .filter(function() {
.filter(function() {
                            return $(this)
return $(this)
                                .text() == name;
.text() == name;
                        })
})
                        .closest('.mw-changeslist-line-watched');
.closest('.mw-changeslist-line-watched');
                    new mw.Api()
new mw.Api()
                        .postWithToken('csrf', {
.postWithToken('csrf', {
                            action: 'setnotificationtimestamp',
action: 'setnotificationtimestamp',
                            titles: name,
titles: name,
                            newerthanrevid: oldrev
newerthanrevid: oldrev
                        })
})
                        .done(function() {
.done(function() {
                            if (all.length > 1)
if (all.length > 1)
                                $this.closest('table, li')
$this.closest('table, li')
                                .append($('<span>')
.append($('<span>')
                                    .text(' ' + all.length + ' ' + i18n('manymarked') + ' ')
.text(' ' + all.length + ' ' + i18n('manymarked') + ' ')
                                );
);
                            all.removeClass('mw-changeslist-line-not-watched yellowedit')
all.removeClass('mw-changeslist-line-not-watched yellowedit')
                                .addClass('mw-changeslist-line-watched blueedit')
.addClass('mw-changeslist-line-watched blueedit')
                                .show()
.show()
                                .find('.unmark-edits')
.find('.unmark-edits')
                                .remove();
.remove();
                            allboth.find('.gold-button')
allboth.find('.gold-button')
                                .remove();
.remove();
                            $('#gold-little-' + curid)
$('#gold-little-' + curid)
                            .find('a')
.find('a')
                            .remove();
.remove();
                            defected[curid] = true;
defected[curid] = true;
                            seen(all.find('span.mw-title'));
seen(all.find('span.mw-title'));
                        });
});
                }));
}));
    }
}


    function flowseen() {
function flowseen() {
        $('.mw-changeslist-line-watched a.mw-title')
$('.mw-changeslist-line-watched a.mw-title')
            .parent()
.parent()
            .prepend(button('markFlow', 'mark-all-flow-edits')
.prepend(button('markFlow', 'mark-all-flow-edits')
                .click(function() {
.click(function() {
                    var $this = $(this),
var $this = $(this),
                        topic = /title=[^:]*:(.+)&/.exec($this.parent()
topic = /title=[^:]*:(.+)&/.exec($this.parent()
                            .find('a[href*="fromnotif"]')
.find('a[href*="fromnotif"]')
                            .prop('href')),
.prop('href')),
                        page = $this
page = $this
                        .closest('.mw-changeslist-line-watched')
.closest('.mw-changeslist-line-watched')
                        .find('a.mw-title')
.find('a.mw-title')
                        .prop('title'),
.prop('title'),
                        titles = topic ? page + '|נושא:' + topic[1] : page;
titles = topic ? page + '|נושא:' + topic[1] : page;
                    new mw.Api()
new mw.Api()
                        .postWithToken('csrf', {
.postWithToken('csrf', {
                            action: 'setnotificationtimestamp',
action: 'setnotificationtimestamp',
                            titles: titles,
titles: titles,
                        })
})
                        .done(function() {
.done(function() {
                            if (config.hidemarked.flow)
if (config.hidemarked.flow)
                                $this.closest('.mw-changeslist-line-watched')
$this.closest('.mw-changeslist-line-watched')
                                .hide();
.hide();
                            $this.closest('.mw-changeslist-line-watched')
$this.closest('.mw-changeslist-line-watched')
                                .removeClass('mw-changeslist-line-watched blueedit')
.removeClass('mw-changeslist-line-watched blueedit')
                                .addClass('mw-changeslist-line-not-watched yellowedit');
.addClass('mw-changeslist-line-not-watched yellowedit');
                            $this.remove();
$this.remove();
                        });
});
                }));
}));
    }
}


    function categoryseen() {
function categoryseen() {
        $('.mw-changeslist-line-watched span.mw-title')
$('.mw-changeslist-line-watched span.mw-title')
            .filter(function() {
.filter(function() {
                return ($(this)
return ($(this)
                        .closest('.mw-changeslist-line-watched')
.closest('.mw-changeslist-line-watched')
                        .find('a[href*="diff"]')
.find('a[href*="diff"]')
                        .length <= 0 && $(this)
.length <= 0 && $(this)
                        .closest('.mw-changeslist-line-watched')
.closest('.mw-changeslist-line-watched')
                        .find('abbr.newpage')
.find('abbr.newpage')
                        .length <= 0) ||
.length <= 0) ||
                    $(this)
$(this)
                    .find('a.mw-changeslist-title')
.find('a.mw-changeslist-title')
                    .parent()
.parent()
                    .next()
.next()
                    .text() == '. .';
.text() == '. .';
            })
})
            .before(button('markCat', 'mark-cat-edits')
.before(button('markCat', 'mark-cat-edits')
                .click(function() {
.click(function() {
                    var $this = $(this),
var $this = $(this),
                        page = $this.parent()
page = $this.parent()
                        .find('a.mw-changeslist-title')
.find('a.mw-changeslist-title')
                        .prop('title');
.prop('title');
                    new mw.Api()
new mw.Api()
                        .postWithToken('csrf', {
.postWithToken('csrf', {
                            action: 'setnotificationtimestamp',
action: 'setnotificationtimestamp',
                            titles: page,
titles: page,
                        })
})
                        .done(function() {
.done(function() {
                            if (config.hidemarked.categorization)
if (config.hidemarked.categorization)
                                $this.closest('.mw-changeslist-line-watched')
$this.closest('.mw-changeslist-line-watched')
                                .hide();
.hide();
                            $this.closest('.mw-changeslist-line-watched')
$this.closest('.mw-changeslist-line-watched')
                                .removeClass('mw-changeslist-line-watched blueedit')
.removeClass('mw-changeslist-line-watched blueedit')
                                .addClass('mw-changeslist-line-not-watched yellowedit');
.addClass('mw-changeslist-line-not-watched yellowedit');
                            $this.remove();
$this.remove();
                        });
});
                }));
}));
    }
}


    function checklog() {
function checklog() {
        new mw.Api()
new mw.Api()
            .get({
.get({
                action: 'query',
action: 'query',
                format: 'json',
format: 'json',
                list: 'watchlist',
list: 'watchlist',
                indexpageids: 1,
indexpageids: 1,
                wllimit: 500,
wllimit: 500,
                wlprop: 'title|loginfo',
wlprop: 'title|loginfo',
                wlshow: 'unread',
wlshow: 'unread',
                wltype: 'log'
wltype: 'log'
            })
})
            .done(function(data) {
.done(function(data) {
                var firstname = data.query.watchlist;
var firstname = data.query.watchlist;
                if (firstname.length > 0) {
if (firstname.length > 0) {
                    firstname = firstname[0];
firstname = firstname[0];
                    $('#hideAll')
$('#hideAll')
                        .after($('<div>', {
.after($('<div>', {
                                id: 'logmessage'
id: 'logmessage'
                            })
})
                            .addClass('blueedit')
.addClass('blueedit')
                            .append($('<span>')
.append($('<span>')
                                .text(i18n('loga')))
.text(i18n('loga')))
                            .append($('<span>')
.append($('<span>')
                                .text(firstname.title)
.text(firstname.title)
                                .css({
.css({
                                    fontWeight: 'bold',
fontWeight: 'bold',
                                }))
}))
                            .append($('<span>')
.append($('<span>')
                                .text(i18n('logb') + firstname.logaction + ' '))
.text(i18n('logb') + firstname.logaction + ' '))
                            .append($('<a>', {
.append($('<a>', {
                                href: 'https://he.wikipedia.org//w/api.php?action=query&format=rawfm&list=watchlist&' +
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',
'indexpageids=1&wllimit=500&wlprop=title%7Cloginfo&wlshow=unread&wltype=log',
                                text: i18n('logc')
text: i18n('logc')
                            }))
}))
                            .append($('<span>')
.append($('<span>')
                                .text('. ' + i18n('logd') + ' '))
.text('. ' + i18n('logd') + ' '))
                            .append($('<a>', {target: '_blank'})
.append($('<a>', {target: '_blank'})
                                .text(i18n('loge'))
.text(i18n('loge'))
                                .click(function() {
.click(function() {
                                    new mw.Api()
new mw.Api()
                                        .postWithToken('csrf', {
.postWithToken('csrf', {
                                            action: 'setnotificationtimestamp',
action: 'setnotificationtimestamp',
                                            titles: firstname.title
titles: firstname.title
                                        })
})
                                        .done(function() {
.done(function() {
                                            $('#logmessage')
$('#logmessage')
                                                .remove();
.remove();
                                            var all = $('.mw-changeslist-line-watched a.mw-changeslist-title')
var all = $('.mw-changeslist-line-watched a.mw-changeslist-title')
                                                .filter(function() {
.filter(function() {
                                                    return $(this)
return $(this)
                                                        .prop('title') == firstname.title;
.prop('title') == firstname.title;
                                                })
})
                                                .closest('.mw-changeslist-line-watched');
.closest('.mw-changeslist-line-watched');
                                            all.removeClass('mw-changeslist-line-watched blueedit')
all.removeClass('mw-changeslist-line-watched blueedit')
                                                .addClass('mw-changeslist-line-not-watched yellowedit')
.addClass('mw-changeslist-line-not-watched yellowedit')
                                                .show()
.show()
                                                .find('.unmark-edits')
.find('.unmark-edits')
                                                .remove();
.remove();
                                            if (config.hidemarked.edit)
if (config.hidemarked.edit)
                                                $('.yellowedit')
$('.yellowedit')
                                                .hide();
.hide();
                                            seen(all.find('span.mw-title'));
seen(all.find('span.mw-title'));
                                            if (all.length > 0)
if (all.length > 0)
                                                $('#hideAll')
$('#hideAll')
                                                .after($('<div>')
.after($('<div>')
                                                    .text(' ' + all.length + ' ' + i18n('manymarked') + ' ')
.text(' ' + all.length + ' ' + i18n('manymarked') + ' ')
                                                )
)
                                                .addClass('yellowedit');
.addClass('yellowedit');
                                            checklog();
checklog();
                                        });
});
                                }))
}))
                            .append($('<span>')
.append($('<span>')
                                .text('.')
.text('.')
                            ));
));
                }
}
            });
});
    }
}


    function goldbutton() {
function goldbutton() {
        $('.close-edit')
$('.close-edit')
            .filter(function() {
.filter(function() {
                return $(this)
return $(this)
                    .closest('.mw-changeslist-line-watched')
.closest('.mw-changeslist-line-watched')
                    .filter(notcat)
.filter(notcat)
                    .find('a[href*="diff"]')
.find('a[href*="diff"]')
                    .filter(notme)
.filter(notme)
                    .filter(function() {
.filter(function() {
                        return $(this)
return $(this)
                            .closest('.mw-enhanced-rc-nested')
.closest('.mw-enhanced-rc-nested')
                            .length <= 0;
.length <= 0;
                    })
})
                    .length > 0 &&
.length > 0 &&
                    $(this)
$(this)
                    .closest('.mw-changeslist-line-watched')
.closest('.mw-changeslist-line-watched')
                    .find('a.mw-title')
.find('a.mw-title')
                    .length <= 0;
.length <= 0;
            })
})
            .each(function() {
.each(function() {
            var curid = /curid=([0-9]+)/.exec($(this)
var curid = /curid=([0-9]+)/.exec($(this)
            .closest('table, li')
.closest('table, li')
            .find('a[href*="curid"]')
.find('a[href*="curid"]')
            .filter(notme)
.filter(notme)
            .prop('href'))[1];
.prop('href'))[1];
                var name = $(this)
var name = $(this)
                    .closest('.mw-changeslist-line-watched')
.closest('.mw-changeslist-line-watched')
                    .find('.mw-changeslist-title')
.find('.mw-changeslist-title')
                    .text(),
.text(),
                    checked = $('.mw-changeslist-title')
checked = $('.mw-changeslist-title')
                    .filter(function() {
.filter(function() {
                        return $(this)
return $(this)
                            .text() == name;
.text() == name;
                    })
})
                    .closest('.mw-changeslist-line-watched'),
.closest('.mw-changeslist-line-watched'),
                    nonew = checked
nonew = checked
                    .find('abbr.newpage')
.find('abbr.newpage')
                    .length <= 0,
.length <= 0,
                    min = Infinity;
min = Infinity;
                checked
checked
                    .find('a[href*="oldid"]')
.find('a[href*="oldid"]')
                    .filter(notme)
.filter(notme)
                    .filter(function() {
.filter(function() {
                        return ($(this)
return ($(this)
                                .text() == messages.diff || $(this)
.text() == messages.diff || $(this)
                                .text() == messages.last) &&
.text() == messages.last) &&
                            ($(this)
($(this)
                                .closest('.mw-enhanced-rc-nested')
.closest('.mw-enhanced-rc-nested')
                                .closest('.mw-enhanced-watched')
.closest('.mw-enhanced-watched')
                                .length > 0 ||
.length > 0 ||
                                $(this)
$(this)
                                .closest('.mw-enhanced-rc-nested')
.closest('.mw-enhanced-rc-nested')
                                .length <= 0);
.length <= 0);
                    })
})
                    .each(function() {
.each(function() {
                        var old = /oldid=([0-9]+)/.exec($(this)
var old = /oldid=([0-9]+)/.exec($(this)
                            .prop('href'));
.prop('href'));
                        min = old ? Math.min(min, old[1]) : min;
min = old ? Math.min(min, old[1]) : min;
                    });
});
                if (min > 0 && min != Infinity && nonew) {
if (min > 0 && min != Infinity && nonew) {
                    $(this)
$(this)
                        .after($('<a>', {
.after($('<a>', {
                                text: '\u200f',
text: '\u200f',
                                title: i18n('goldbutton'),
title: i18n('goldbutton'),
                                target: '_blank',
target: '_blank',
                                href: 'https://he.wikipedia.org/w/index.php?title=' + name +
href: 'https://he.wikipedia.org/w/index.php?title=' + name +
                                    '&redirect=no&diff=cur&oldid=' + min
'&redirect=no&diff=cur&oldid=' + min
                            })
})
                            .addClass('gold-button WLM-icon gold-' + curid)
.addClass('gold-button WLM-icon gold-' + curid)
                            .click(function() {
.click(function() {
                                if (config.hidemarked.edit)
if (config.hidemarked.edit)
                                    $('.yellowedit')
$('.yellowedit')
                                    .hide();
.hide();
                                var all = $('.mw-changeslist-line-watched .mw-changeslist-title')
var all = $('.mw-changeslist-line-watched .mw-changeslist-title')
                                    .filter(function() {
.filter(function() {
                                        return $(this)
return $(this)
                                            .text() == name;
.text() == name;
                                    })
})
                                    .closest('.mw-changeslist-line-watched');
.closest('.mw-changeslist-line-watched');
                                if (all.length > 1)
if (all.length > 1)
                                    $(this)
$(this)
                                    .closest('table, li')
.closest('table, li')
                                    .append($('<span>')
.append($('<span>')
                                        .text(' ' + all.length + ' ' + i18n('manymarked') + ' ')
.text(' ' + all.length + ' ' + i18n('manymarked') + ' ')
                                        .css({
.css({
                                            backgroundColor: 'red'
backgroundColor: 'red'
                                        }));
}));
                                all.removeClass('mw-changeslist-line-watched blueedit')
all.removeClass('mw-changeslist-line-watched blueedit')
                                    .addClass('mw-changeslist-line-not-watched yellowedit')
.addClass('mw-changeslist-line-not-watched yellowedit')
                                    .show()
.show()
                                    .find('.mark-edits, .gold-button')
.find('.mark-edits, .gold-button')
                                    .remove();
.remove();
                                $('.gold-' + curid)
$('.gold-' + curid)
                                .remove();
.remove();
                                $('#gold-little-' + curid)
$('#gold-little-' + curid)
                                .remove();
.remove();
                                unseen(all.find('span.mw-title'));
unseen(all.find('span.mw-title'));
                            }));
}));
                }
}
            });
});
    }
}


    function closeedit() {
function closeedit() {
        var btn = button('close', 'close-edit')
var btn = button('close', 'close-edit')
            .click(function() {
.click(function() {
                $(this)
$(this)
                    .closest('.mw-changeslist-line-not-watched, .mw-changeslist-line-watched')
.closest('.mw-changeslist-line-not-watched, .mw-changeslist-line-watched')
                    .hide();
.hide();
            });
});
        $('li span.mw-changeslist-date')
$('li span.mw-changeslist-date')
            .parent()
.parent()
            .prepend(btn);
.prepend(btn);
        $('td.mw-enhanced-rc')
$('td.mw-enhanced-rc')
            .parent()
.parent()
            .filter(function() {
.filter(function() {
                return $(this)
return $(this)
                    .find('td.mw-enhanced-rc-nested')
.find('td.mw-enhanced-rc-nested')
                    .length <= 0;
.length <= 0;
            })
})
            .prepend($('<td>')
.prepend($('<td>')
                .html(btn)
.html(btn)
                .css({
.css({
                    whiteSpace: 'nowrap'
whiteSpace: 'nowrap'
                }));
}));
        $('td.mw-enhanced-rc')
$('td.mw-enhanced-rc')
            .parent()
.parent()
            .find('td.mw-enhanced-rc-nested')
.find('td.mw-enhanced-rc-nested')
            .prev()
.prev()
            .before($('<td>'));
.before($('<td>'));
    }
}


    function notme() {
function notme() {
        return !$(this)
return !$(this)
            .hasClass('WLM-icon');
.hasClass('WLM-icon');
    }
}


    function notcat() {
function notcat() {
        return $(this)
return $(this)
            .find('a.mw-changeslist-title')
.find('a.mw-changeslist-title')
            .parent()
.parent()
            .next()
.next()
            .text() != '. .';
.text() != '. .';
    }
}


function whatsnew() {
function whatsnew() {
$('#newrevs').remove();
$('#newrevs').remove();
new mw.Api()
new mw.Api()
            .get({
.get({
action: 'query',
action: 'query',
format: 'json',
format: 'json',
שורה 517: שורה 517:
wlallrev: 1,
wlallrev: 1,
errorformat: 'wikitext'
errorformat: 'wikitext'
            })
})
            .done(function(data) {
.done(function(data) {
            var ans = data.query.watchlist;
var ans = data.query.watchlist;
$('#hideAll')
$('#hideAll')
            .after($('<div>', {id: 'newrevs', text: '['})
.after($('<div>', {id: 'newrevs', text: '['})
            .addClass('blueedit'));
.addClass('blueedit'));
        var newmap = {};
var newmap = {};
        Object.keys(ans).map(function(key) {
Object.keys(ans).map(function(key) {
        var id = ans[key].pageid;
var id = ans[key].pageid;
        if (id in newmap) {
if (id in newmap) {
        if (ans[key].old_revid < newmap[id].oldid)
if (ans[key].old_revid < newmap[id].oldid)
        newmap[id].oldid = ans[key].old_revid;
newmap[id].oldid = ans[key].old_revid;
        } else
} else
newmap[id] = {title: ans[key].title,
newmap[id] = {title: ans[key].title,
oldid: ans[key].old_revid};
oldid: ans[key].old_revid};
        });
});
            Object.keys(newmap).map(function(uuu) {
Object.keys(newmap).map(function(uuu) {
            var vvv = $('.gold-' + uuu).length;
var vvv = $('.gold-' + uuu).length;
            if (defected[uuu])
if (defected[uuu])
            $('#newrevs')
$('#newrevs')
            .append($('<span>', {text: newmap[uuu].title + ',\u200f '}));
.append($('<span>', {text: newmap[uuu].title + ',\u200f '}));
            else if (vvv > 0)  
else if (vvv > 0)  
            $('#newrevs')
$('#newrevs')
            .append($('<span>', {text: newmap[uuu].title + ',\u200f ', id: 'gold-little-' + uuu})
.append($('<span>', {text: newmap[uuu].title + ',\u200f ', id: 'gold-little-' + uuu})
            .prepend($('.gold-' + uuu).clone(true, true)[0]));
.prepend($('.gold-' + uuu).clone(true, true)[0]));
            else
else
            $('#newrevs')
$('#newrevs')
            .append($('<span>', {text: ',\u200f '})
.append($('<span>', {text: ',\u200f '})
            .prepend($('<a>', {text: newmap[uuu].title,
.prepend($('<a>', {text: newmap[uuu].title,
            href: 'https://he.wikipedia.org/w/index.php?title=' +
href: 'https://he.wikipedia.org/w/index.php?title=' +
            newmap[uuu].title +
newmap[uuu].title +
                                    '&redirect=no&diff=cur&oldid=' + newmap[uuu].oldid,
'&redirect=no&diff=cur&oldid=' + newmap[uuu].oldid,
            target: '_blank'
target: '_blank'
            })
})
            .click(function() {
.click(function() {
            $(this).parent().
$(this).parent().
            remove();
remove();
            })));
})));
            });
});
            $('#newrevs')
$('#newrevs')
            .append($('<span>', {
.append($('<span>', {
                                text: '\u200f☺',
text: '\u200f☺',
                                title: 'closenew',//TODO
title: 'closenew',//TODO
                                id: 'closenew'
id: 'closenew'
            })
})
                    .click(function() {
.click(function() {
                    $('#newrevs').remove();
$('#newrevs').remove();
                    })
})
            ).append(']');
).append(']');
            })
})
            .done(function() {
.done(function() {
            $( 'body' ).trigger( 'script-88-pretend-clicked' );
$( 'body' ).trigger( 'script-88-pretend-clicked' );
            });
});
}
}


    function hider(state) {
function hider(state) {
$('#newrevs').remove();
$('#newrevs').remove();
        if (config.edit[state])
if (config.edit[state])
            $('.mw-changeslist-line-not-watched')
$('.mw-changeslist-line-not-watched')
            .filter(function() {
.filter(function() {
                return $(this)
return $(this)
                    .find('abbr.wikibase-edit')
.find('abbr.wikibase-edit')
                    .length <= 0;
.length <= 0;
            })
})
            .hide();
.hide();
        if (config.log[state])
if (config.log[state])
            $('[class*="mw-changeslist-log"]')
$('[class*="mw-changeslist-log"]')
            .hide();
.hide();
        if (config.wikidata[state])
if (config.wikidata[state])
            $('abbr.wikibase-edit')
$('abbr.wikibase-edit')
            .closest('.mw-changeslist-line-watched, .mw-changeslist-line-not-watched')
.closest('.mw-changeslist-line-watched, .mw-changeslist-line-not-watched')
            .hide();
.hide();
        $('#logmessage')
$('#logmessage')
            .hide();
.hide();
        $('#watchlist-preamble')
$('#watchlist-preamble')
        .hide();
.hide();
        $('input[name="mw-watchlist-reset-submit"]')
$('input[name="mw-watchlist-reset-submit"]')
        .hide();
.hide();
    }
}


    function unhider() {
function unhider() {
whatsnew();
whatsnew();
        $('.mw-changeslist-line-watched')
$('.mw-changeslist-line-watched')
            .show();
.show();
        if (config.edit.show)
if (config.edit.show)
            $('.mw-changeslist-line-not-watched')
$('.mw-changeslist-line-not-watched')
            .filter(function() {
.filter(function() {
                return $(this)
return $(this)
                    .find('abbr.wikibase-edit')
.find('abbr.wikibase-edit')
                    .length <= 0;
.length <= 0;
            })
})
            .show();
.show();
        if (config.log.show)
if (config.log.show)
            $('[class*="mw-changeslist-log"]')
$('[class*="mw-changeslist-log"]')
            .show();
.show();
        if (config.wikidata.show)
if (config.wikidata.show)
            $('abbr.wikibase-edit')
$('abbr.wikibase-edit')
            .closest('.mw-changeslist-line-not-watched')
.closest('.mw-changeslist-line-not-watched')
            .show();
.show();
        $('#logmessage')
$('#logmessage')
            .show();
.show();
        $('#watchlist-preamble')
$('#watchlist-preamble')
        .show();
.show();
        $('input[name="mw-watchlist-reset-submit"]')
$('input[name="mw-watchlist-reset-submit"]')
        .show();
.show();
    }
}


    function main() {
function main() {
        seen($('.mw-changeslist-line-watched span.mw-title'));
seen($('.mw-changeslist-line-watched span.mw-title'));
        unseen($('.mw-changeslist-line-not-watched span.mw-title'));
unseen($('.mw-changeslist-line-not-watched span.mw-title'));
        flowseen();
flowseen();
        categoryseen();
categoryseen();
        closeedit();
closeedit();
        goldbutton();
goldbutton();
        hider('starthidden');
hider('starthidden');
    }
}


    function demo() {
function demo() {
        $('.mark-edits')
$('.mark-edits')
            .click(function() {
.click(function() {
                var id = $(this)
var id = $(this)
                    .parent()
.parent()
                    .prop('id');
.prop('id');
                $(this)
$(this)
                    .closest('table')
.closest('table')
                    .find('.mark-edits')
.find('.mark-edits')
                    .filter(function() {
.filter(function() {
                        return $(this)
return $(this)
                            .parent()
.parent()
                            .prop('id') <= id;
.prop('id') <= id;
                    })
})
                    .removeClass('mark-edits')
.removeClass('mark-edits')
                    .addClass('unmark-edits')
.addClass('unmark-edits')
                    .parent()
.parent()
                    .removeClass('blueedit')
.removeClass('blueedit')
                    .addClass('yellowedit');
.addClass('yellowedit');
                demo();
demo();
            });
});
        $('.unmark-edits')
$('.unmark-edits')
            .click(function() {
.click(function() {
                var id = $(this)
var id = $(this)
                    .parent()
.parent()
                    .prop('id');
.prop('id');
                $(this)
$(this)
                    .closest('table')
.closest('table')
                    .find('.unmark-edits')
.find('.unmark-edits')
                    .filter(function() {
.filter(function() {
                        return $(this)
return $(this)
                            .parent()
.parent()
                            .prop('id') >= id;
.prop('id') >= id;
                    })
})
                    .removeClass('unmark-edits')
.removeClass('unmark-edits')
                    .addClass('mark-edits')
.addClass('mark-edits')
                    .parent()
.parent()
                    .removeClass('yellowedit')
.removeClass('yellowedit')
                    .addClass('blueedit');
.addClass('blueedit');
                demo();
demo();
            });
});
    }
}


    if (mw.config.get('wgCanonicalSpecialPageName') == 'Watchlist') {
if (mw.config.get('wgCanonicalSpecialPageName') == 'Watchlist') {
        var langcode = mw.user.options.get('language'),
var langcode = mw.user.options.get('language'),
            lang = langcode == 'he' ? 0 : 1,
lang = langcode == 'he' ? 0 : 1,
            extendwatchlist = mw.user.options.get('extendwatchlist'),
extendwatchlist = mw.user.options.get('extendwatchlist'),
            defected = {}, config, messages;
defected = {}, config, messages;
        if (extendwatchlist == 1) {
if (extendwatchlist == 1) {
            $('.mw-body-content')
$('.mw-body-content')
                .addClass(typeof window.orientation == 'undefined' ? 'WLM-desktop' : 'WLM-mobile');
.addClass(typeof window.orientation == 'undefined' ? 'WLM-desktop' : 'WLM-mobile');
importStylesheet('מדיה ויקי:Gadget-WLM.css');
importStylesheet('מדיה ויקי:Gadget-WLM.css');
importStylesheet('משתמש:' + mw.config.get('wgUserName') + '/WLM.css');
importStylesheet('משתמש:' + mw.config.get('wgUserName') + '/WLM.css');
            importStylesheet('משתמש:' + mw.config.get('wgUserName') + '/common.css');
importStylesheet('משתמש:' + mw.config.get('wgUserName') + '/common.css');
            new mw.Api()
new mw.Api()
                .getMessages(['diff', 'last'], {
.getMessages(['diff', 'last'], {
                    amlang: langcode
amlang: langcode
                })
})
                .then(function(result) {
.then(function(result) {
                    messages = result;
messages = result;
                })
})
                .then(function() {
.then(function() {
                    $.get(mw.util.wikiScript(), {
$.get(mw.util.wikiScript(), {
                            title: 'מדיה ויקי:Gadget-WLM.json',
title: 'מדיה ויקי:Gadget-WLM.json',
                            action: 'raw'
action: 'raw'
                        })
})
                        .done(function(data) {
.done(function(data) {
                            config = JSON.parse(data);
config = JSON.parse(data);
                            $.get(mw.util.wikiScript(), {
$.get(mw.util.wikiScript(), {
                                    title: 'משתמש:' + mw.config.get('wgUserName') + '/WLM.json',
title: 'משתמש:' + mw.config.get('wgUserName') + '/WLM.json',
                                    action: 'raw'
action: 'raw'
                                })
})
                                .done(function(data1) {
.done(function(data1) {
                                    config = JSON.parse(data1);
config = JSON.parse(data1);
                                })
})
                                .always(main);
.always(main);
                        })
})
                        .fail(function() {
.fail(function() {
                            console.log('ERR: ' + i18n('jsonlost'));
console.log('ERR: ' + i18n('jsonlost'));
                        });
});
                });
});
            $('#mw-watchlist-form')
$('#mw-watchlist-form')
                .after($('<input>', {
.after($('<input>', {
                        id: 'hideAll',
id: 'hideAll',
                        type: 'submit',
type: 'submit',
                        title: i18n('help')
title: i18n('help')
                    })
})
                    .click(function() {
.click(function() {
                        hider('hide');
hider('hide');
                    }))
}))
                .after($('<span>', {
.after($('<span>', {
                        text: 'place',
text: 'place',
                        id: 'placeholder'
id: 'placeholder'
                    })
})
                    .css({
.css({
                        visibility: 'hidden',
visibility: 'hidden',
                    }))
}))
                .after($('<input>', {
.after($('<input>', {
                        id: 'showAll',
id: 'showAll',
                        type: 'submit',
type: 'submit',
                        title: i18n('help')
title: i18n('help')
                    })
})
                    .click(unhider))
.click(unhider))
                .after($('<span>', {
.after($('<span>', {
                        text: 'place',
text: 'place',
                        id: 'placeholder'
id: 'placeholder'
                    })
})
                    .css({
.css({
                        visibility: 'hidden',
visibility: 'hidden',
                    }))
}))
                .after($('<input>', {
.after($('<input>', {
                        id: 'whatsnew',
id: 'whatsnew',
                        type: 'submit',
type: 'submit',
                        title: i18n('help')
title: i18n('help')
                    })
})
                    .click(whatsnew))
.click(whatsnew))
                .after($('<div>', {
.after($('<div>', {
                        text: 'place',
text: 'place',
                        id: 'placeline'
id: 'placeline'
                    })
})
                    .css({
.css({
                        visibility: 'hidden',
visibility: 'hidden',
                        fontSize: '50%'
fontSize: '50%'
                    }));
}));
            $('#hideAll')
$('#hideAll')
                .attr('value', i18n('hideAll'));
.attr('value', i18n('hideAll'));
            $('#showAll')
$('#showAll')
                .attr('value', i18n('showAll'));
.attr('value', i18n('showAll'));
            $('#whatsnew')
$('#whatsnew')
                .attr('value', i18n('whatsnew'));
.attr('value', i18n('whatsnew'));
            checklog();
checklog();
        }
}
    } else if (mw.config.get('wgPageName') == 'עזרה:WLM') {
} else if (mw.config.get('wgPageName') == 'עזרה:WLM') {
        $('.prescell')
$('.prescell')
            .attr('align', 'center')
.attr('align', 'center')
            .each(function() {
.each(function() {
                $(this)
$(this)
                    .html($('<a>')
.html($('<a>')
                        .addClass($(this)
.addClass($(this)
                            .attr('class')));
.attr('class')));
                $(this)
$(this)
                    .removeClass('mark-edits unmark-edits');
.removeClass('mark-edits unmark-edits');
            });
});
        $('#clear')
$('#clear')
            .prepend($('<input>', {
.prepend($('<input>', {
                    id: 'clearbutton',
id: 'clearbutton',
                    type: 'submit'
type: 'submit'
                })
})
                .click(function() {
.click(function() {
                    $('.blueedit, .yellowedit')
$('.blueedit, .yellowedit')
                        .removeClass('blueedit yellowedit');
.removeClass('blueedit yellowedit');
                }));
}));
        $('#clearbutton')
$('#clearbutton')
            .attr('value', i18n('clear'));
.attr('value', i18n('clear'));
        demo();
demo();
    }
}
});
});

גרסה מ־15:15, 14 במרץ 2017

var timestamp;
new mw.Api()
.get({
	action: 'query',
	format: 'json',
	curtimestamp: 1
})
.done(function(data) {
	timestamp = data.curtimestamp;
});

$(function() {
	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?"],
			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: '\u200f',
				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');
					new mw.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');
					new mw.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;
					new mw.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');
					new mw.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() {
		new mw.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() {
									new mw.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() {
		$('.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;
				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: '\u200f',
								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();
		new mw.Api()
			.get({
				action: 'query',
				format: 'json',
				list: 'watchlist',
				indexpageids: 1,
				wldir: 'newer',
				wllimit: 500,
				wlprop: 'title|ids',
				wlshow: 'unread|!bot',
				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(uuu) {
					var vvv = $('.gold-' + uuu).length;
					if (defected[uuu])
						$('#newrevs')
							.append($('<span>', {text: newmap[uuu].title + ',\u200f '}));
					else if (vvv > 0) 
						$('#newrevs')
							.append($('<span>', {text: newmap[uuu].title + ',\u200f ', id: 'gold-little-' + uuu})
								.prepend($('.gold-' + uuu).clone(true, true)[0]));
					else
						$('#newrevs')
							.append($('<span>', {text: ',\u200f '})
								.prepend($('<a>', {text: newmap[uuu].title,
									href: 'https://he.wikipedia.org/w/index.php?title=' +
									newmap[uuu].title +
									'&redirect=no&diff=cur&oldid=' + newmap[uuu].oldid,
									target: '_blank'
								})
								.click(function() {
									$(this).parent().
										remove();
						})));
				});
				$('#newrevs')
					.append($('<span>', {
								text: '\u200f☺',
								title: 'closenew',//TODO
								id: 'closenew'
					})
					.click(function() {
						$('#newrevs').remove();
					})
				).append(']');
			})
			.done(function() {
				$( 'body' ).trigger( 'script-88-pretend-clicked' );
			});
	}

	function hider(state) {
		$('#newrevs').remove();
		if (config.edit[state])
			$('.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();
		$('input[name="mw-watchlist-reset-submit"]')
			.hide();
	}

	function unhider() {
		whatsnew();
		$('.mw-changeslist-line-watched')
			.show();
		if (config.edit.show)
			$('.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() {
		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.user.options.get('language'),
			lang = langcode == 'he' ? 0 : 1,
			extendwatchlist = mw.user.options.get('extendwatchlist'),
			defected = {}, config, messages;
		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');
			new mw.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();
	}
});