User:逆襲的天邪鬼/+1s.js

(function {    if (mw.config.get('wgUserGroups').indexOf('sysop') === -1) {        return;    }

var SUMMARY = 'Test +1s by +1s.js';

document.styleSheets[0].insertRule('.donate1second { color:red; }'); document.styleSheets[0].insertRule('a.donating1second { color:grey; }');

var block = function (username) { return $.ajax({           url: mw.util.wikiScript('api'),            data: {                format: 'json',                action: 'block',                user: username,                expiry: '1 second',                reason: SUMMARY,                allowusertalk: '',                token: mw.user.tokens.get('editToken'),            },            dataType: 'json',            type: 'POST',        }); };

var startHaMode = function { var getUserName = function (item) { var title = item.getAttribute('title'); // deal with markblocked if (title.indexOf(';') > -1) { return title.substr(5, title.indexOf(';') - 5); } else { return title.substr(5); }       };

var donate1second = function (e) { e.preventDefault; var username = this.getAttribute('data-username'); var that = this;

if (that.className.indexOf('donating1second') !== -1) { return; }

that.classList.add('donating1second');

block(username).then(function (data) {               if (data.error) {                    mw.notify("Failed to donate " + username + "'s 1 second.");                } else {                    mw.notify("+1s succeeded.");                }            }).always(function  {                that.classList.remove('donating1second');            }); };

$('a[title^="User:"]', '#mw-content-text').each(function (index, item) {           var username = getUserName(item);            var x = $('+1s')                        .attr('data-username', username)                        .click(donate1second);            $(item).after(x);        }); };

var isHaMode = function { return localStorage['+1s'] !== undefined && localStorage['+1s'] !== 'false'; }; var label = function { return isHaMode ? '[√] +1s Mode' : '[　] +1s Mode'; };

var node = mw.util.addPortletLink('p-cactions', '#', label); $(node).click(function (e) {       e.preventDefault;        localStorage['+1s'] = !isHaMode;        $('a', this).text(label);

if (isHaMode) { if ($('.donate1second').length === 0) { startHaMode; }       } else { $('.donate1second').remove; }   });

if (isHaMode) { startHaMode; } });