User:Anne drew Andrew and Drew/rchelper.js

function getDiffId(url) { return Number(url.match(/[\?&]diff=([0-9]+)/)[0].replace(/\D/g, "")); }

function patrolRc { const patrolledLinks = []; const delay = 1000; const interval = 1000; let time = Date.now; let diffSelector;

if (   prompt("Just open highlighted diffs? (yes or no)")      .toLowerCase      .indexOf("y") === 0  ) { diffSelector = "li.mw-rcfilters-highlighted a.mw-changeslist-diff"; } else { diffSelector = "a.mw-changeslist-diff"; } const liveButton = document.querySelector(    ".mw-rcfilters-ui-liveUpdateButtonWidget > a"  );

alert('Press the "Live updates" button to begin'); setInterval( => {   if (liveButton.getAttribute("aria-pressed") === "true") {      if (document.hasFocus && Date.now - time > delay) {        const link = Array.from(document.querySelectorAll(diffSelector)).find( el => patrolledLinks.indexOf(getDiffId(el.href)) === -1 );       if (link) {          window.open(link.href);          time = Date.now + interval;          patrolledLinks.push(getDiffId(link.href));          if (patrolledLinks.length > 100) {            patrolledLinks.splice(0, 10);          }        }      } else if (!document.hasFocus) {        time = Date.now + interval;      }    }  }, interval); }

jQuery(document).ready( => { if (mw.config.get("wgPageName") === "Special:RecentChanges") {    mw.util.addPortletLink( "p-cactions", "javascript:patrolRc", "RC Helper", "rcHelper", "Patrol Recent Changes", ""   );  } });