Quick Patrol

Quick Patrol in MediaWiki

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Quick Patrol
// @namespace    http://rabbi.town/
// @version      0.2
// @description  Quick Patrol in MediaWiki
// @author       Milkory
// @match        *://*.huijiwiki.com/*
// @match        *://*.fandom.com/*
// @match        *://*.wikipedia.org/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  let mwApi;

  window.addEventListener('load', init, false);

  async function init() {
    mwApi = new mw.Api();
    let rights = (
      await mwApi.get({
        action: 'query',
        meta: 'userinfo',
        uiprop: 'rights',
      })
    ).query.userinfo.rights;

    if (rights.includes('patrol')) {
      $('.mw-changeslist-unpatrolled').attr('data-mw-revid', function (_i, value) {
        $(this)
          .find('.unpatrolled')
          .css('cursor', 'pointer')
          .attr('title', 'Click to partoll')
          .click(function () {
            let me = $(this);
            if ($(this).text() == '!') {
              $(this).text('~').css('color', 'darkgreen').attr('title', 'Patrolling...');
              patrol(
                value,
                function () {
                  me.text('✔')
                    .css({
                      'text-decoration': 'none',
                      'border-bottom': 'none',
                      color: 'green',
                      cursor: 'default',
                    })
                    .attr('title', 'Successfully partolled');
                },
                function () {
                  console.log(`[QuickPatrol] FAILED (revid: ${value})`);
                  me.text('!').css('color', 'red').attr('title', 'Click to partol');
                }
              );
            }
          });
        return value;
      });
    }
  }

  function patrol(revid, successFallback, failFallback) {
    mwApi
      .get({
        action: 'query',
        meta: 'tokens',
        type: 'patrol',
        format: 'json',
      })
      .done(function (data) {
        console.log(`[QuickPatrol] TRYING (revid: ${revid})`);
        mwApi
          .post({
            action: 'patrol',
            revid: revid,
            token: data.query.tokens.patroltoken,
            format: 'json',
          })
          .done(function () {
            console.log(`[QuickPatrol] SUCCESS (revid: ${revid})`);
            successFallback();
          })
          .fail(failFallback);
      })
      .fail(failFallback);
  }
})();