Jump to content

User:Ponor/patroller-name-in-page-history.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/*
Add patroller names with timestamp hints into page history
Author:Ponor, 2022-08-20
*/

$(document).ready(function() {
//"use strict";

if (mw.config.get("wgAction") !== "history" || window.pnph_running) {return}

//the script should not be loaded twice
window.pnph_running = true;

var mwPromise = new mw.Api().get({
  "action"   : "query",
  "format"   : "json",
  "list"     : "logevents",
  "leprop"   : "user|timestamp|details",
  "leaction" : "patrol/patrol",
  "lelimit"  :  20,
  "letitle"  :  mw.config.get("wgPageName")
  }
  );

mwPromise.done( function(jsondata){
  const allPatrols = jsondata.query.logevents
  $.each(allPatrols, function(i, v){
    let $patroller = $("<span />")
                       .css({"color":"green", "font-size":"72%", "margin":"0 3px"})
                       .attr("title","patrolled @ "+v.timestamp)
                       .text("p: "+v.user)
    $("li[data-mw-revid='"+v.params.curid+"']")
      .css("background-color","#f8fff2")
      .children("span.mw-changeslist-links").eq(1) // there are two mw-changeslist-links spans
      .after($patroller)
     }) // .each
}) // mwPromise.done

}); // if document ready