Jump to content

User:Veko/common.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Veko (talk | contribs) at 03:38, 12 April 2025 (fix errors). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Enable caching for resource loads
if(!/\bnocache=\b/.test(location.href)){
  let e=(e,t,n)=>(e=e.replace(/special:mypage/i,"User:"+mw.config.get("wgUserName")),
    $.get("https://"+t+"/w/api.php?titles="+e+"&origin=*&format=json&formatversion=2&uselang=content&maxage=86400&smaxage=86400&action=query&prop=revisions|info&rvprop=content&rvlimit=1")
    .then((r=>{let o=r.query.pages[0];if(o.missing)return;let a=o.revisions[0].content;
    if(n&&"text/javascript"!==n||"javascript"!==o.contentmodel){
      if("text/css"!==n||"css"!==o.contentmodel)return $.Deferred().reject('Refused to load "'+e+'"@'+t+": content type mismatch");
      mw.loader.addStyleTag(a)
    }else{let e=document.createElement("script");e.innerHTML=a,document.head.appendChild(e)}}))),
  t=e=>{let t=/^(?:(?:https:)?\/\/(.*))?\/w\/index.php/.exec(e),
    n=/\btitle=([^=?&]*)/.exec(e);return t&&n&&/\baction=raw\b/.test(e)&&/\bctype=/.test(e)?[n[1],t[1]||mw.config.get("wgServerName")]:null};
  window.importScript=t=>{e(encodeURIComponent(t),mw.config.get("wgServerName"),"text/javascript")},
  window.importStyleSheet=t=>{e(encodeURIComponent(t),mw.config.get("wgServerName"),"text/css")};
  let n=mw.loader.load;
  mw.loader.load=function(r,o){let a=t(r);a?e(a[0],a[1],o):n.apply(mw.loader,[...arguments])};
  let r=mw.loader.getScript;
  mw.loader.getScript=function(n){let o=t(n);return o?e(o[0],o[1],"text/javascript"):r.apply(mw.loader,[...arguments])}
}

// Useful scripts
importScript('User:RedWarn/.js'); // Backlink: [[User:RedWarn/.js]]
importScript('User:Ingenuity/AntiVandal.js'); // Backlink: [[User:Ingenuity/AntiVandal.js]]
importScript('User:Awesome Aasim/rcpatrol.js'); // Backlink: [[User:Awesome Aasim/rcpatrol.js]]
importScript('User:Evad37/rater.js'); // Backlink: [[User:Evad37/rater.js]]
importScript('User:Qwertyytrewqqwerty/DisamAssist.js'); // Backlink: [[User:Qwertyytrewqqwerty/DisamAssist.js]]
importScript('User:Jackmcbarn/editProtectedHelper.js'); // Backlink: [[User:Jackmcbarn/editProtectedHelper.js]]
importScript('User:Evad37/duplinks-alt.js'); // Backlink: [[User:Evad37/duplinks-alt.js]]
importScript('User:GoldenRing/wordcount.js'); // Backlink: [[User:GoldenRing/wordcount.js]]
importScript('User:Ohconfucius/script/Common Terms.js'); // Backlink: [[User:Ohconfucius/script/Common Terms.js]]
importScript('User:Evad37/Thanky.js'); // Backlink: [[User:Evad37/Thanky.js]]
importScript('User:Headbomb/unreliable.js'); // Backlink: [[User:Headbomb/unreliable.js]]
importScript('User:Enterprisey/cv-revdel.js'); // Backlink: [[User:Enterprisey/cv-revdel.js]]
//importScript('User:MusikAnimal/responseHelper.js'); // Backlink: [[User:MusikAnimal/responseHelper.js]]
importScript('User:SD0001/StubSorter.js'); // Backlink: [[User:SD0001/StubSorter.js]]
importScript('User:Awesome Aasim/xfdvote.js'); // Backlink: [[User:Awesome Aasim/xfdvote.js]]
importScript('User:Mr. Stradivarius/gadgets/Draftify.js'); // Backlink: [[User:Mr. Stradivarius/gadgets/Draftify.js]]
importScript('User:Eejit43/scripts/rmtr-helper.js'); // Backlink: [[User:Eejit43/scripts/rmtr-helper.js]]
importScript('User:MPGuy2824/MoveToDraft.js'); // Backlink: [[User:MPGuy2824/MoveToDraft.js]]
importScript('User:Eejit43/scripts/redirect-helper.js'); // Backlink: [[User:Eejit43/scripts/redirect-helper.js]]
importScript('User:Bradv/Scripts/Superlinks.js'); // Backlink: [[User:Bradv/Scripts/Superlinks.js]]
importScript('User:SD0001/GAN-helper.js'); // Backlink: [[User:SD0001/GAN-helper.js]]
importScript('User:Novem Linguae/Scripts/GANReviewTool.js'); // Backlink: [[User:Novem Linguae/Scripts/GANReviewTool.js]]
importScript('User:The Earwig/copyvios.js'); // Backlink: [[User:The Earwig/copyvios.js]]
importScript('User:Xenocidic/statusChanger2.js'); // Backlink: [[User:Xenocidic/statusChanger2.js]]
importScript('User:DannyS712/Draft no cat.js'); // Backlink: [[User:DannyS712/Draft no cat.js]]
importScript('User:BrandonXLF/ReferenceExpander.js'); // Backlink: [[User:BrandonXLF/ReferenceExpander.js]]
importScript('User:Awesome Aasim/redirectcreator.js'); // Backlink: [[User:Awesome Aasim/redirectcreator.js]]
importScript('User:Qwerfjkl/scripts/CFDlister.js'); // Backlink: [[User:Qwerfjkl/scripts/CFDlister.js]]
importScript('User:Shubinator/DYKcheck.js'); // Backlink: [[User:Shubinator/DYKcheck.js]]
importScript('User:BrandonXLF/HotDefaultSort.js'); // Backlink: [[User:BrandonXLF/HotDefaultSort.js]]
importScript('User:Theleekycauldron/DYK_promoter.js'); // Backlink: [[User:Theleekycauldron/DYK_promoter.js]]
importScript('User:BrandonXLF/CollapseSections.js'); // Backlink: [[User:BrandonXLF/CollapseSections.js]]
importScript('User:Schminnte/PageCuration.js'); // Backlink: [[User:Schminnte/PageCuration.js]]
importScript('User:Nardog/CatChangesViewer.js'); // Backlink: [[User:Nardog/CatChangesViewer.js]]
importScript('User:קיפודנחש/cat-a-lot.js'); // Backlink: [[User:קיפודנחש/cat-a-lot.js]]
importScript('User:Enterprisey/orcp-helper.js'); // Backlink: [[User:Enterprisey/orcp-helper.js]]
importScript('User:Novem Linguae/Scripts/DontForgetG12.js'); // Backlink: [[User:Novem Linguae/Scripts/DontForgetG12.js]]
importScript('User:Writ Keeper/rollbackSummary.js'); // Backlink: [[User:Writ Keeper/rollbackSummary.js]]
importScript('User:BrandonXLF/CitationStyleMarker.js'); // Backlink: [[User:BrandonXLF/CitationStyleMarker.js]]
importScript('User:Andrybak/Archiver.js'); // Backlink: [[User:Andrybak/Archiver.js]]
importScript('User:PleaseStand/segregate-refs.js'); // Backlink: [[User:PleaseStand/segregate-refs.js]]
importScript('User:Ohconfucius/script/MOSNUM dates.js'); // Backlink: [[User:Ohconfucius/script/MOSNUM dates.js]]
importScript('User:JPxG/Difformatter.js'); // Backlink: [[User:JPxG/Difformatter.js]]
importScript('User:Qwerfjkl/scripts/editRedirect.js'); // Backlink: [[User:Qwerfjkl/scripts/editRedirect.js]]
importScript('User:Enterprisey/section-redir-note.js'); // Backlink: [[User:Enterprisey/section-redir-note.js]]
importScript('User:BrandonXLF/ShowUserGender.js'); // Backlink: [[User:BrandonXLF/ShowUserGender.js]]
importScript('User:Novem_Linguae/Scripts/VisualEditorEverywhere.js'); // Backlink: [[User:Novem_Linguae/Scripts/VisualEditorEverywhere.js]]
importScript('User:Ingenuity/MergeDuplicateRefs.js'); // Backlink: [[User:Ingenuity/MergeDuplicateRefs.js]]
importScript('User:Sohom_Datta/fastreview.js'); // Backlink: [[User:Sohom_Datta/fastreview.js]]
importScript('User:Nardog/RefRenamer.js'); // Backlink: [[User:Nardog/RefRenamer.js]]
importScript('User:Nardog/MoveHistory.js'); // Backlink: [[User:Nardog/MoveHistory.js]]
importScript('User:Trappist the monk/HarvErrors.js'); // Backlink: [[User:Trappist the monk/HarvErrors.js]]
importScript('User:Polygnotus/DuplicateReferences.js'); // Backlink: [[User:Polygnotus/DuplicateReferences.js]]

// Add "back to top" links to each section
$(function () {
  var elems = document.getElementsByClassName('editsection');
  for (let i = 0; i < elems.length; i++) {
    var span = document.createElement('span');
    var link = document.createElement('a');
    link.href = '#top';
    link.appendChild(document.createTextNode('back to top'));
    span.appendChild(document.createTextNode('['));
    span.appendChild(link);
    span.appendChild(document.createTextNode('] '));
    elems[i].insertBefore(span, elems[i].firstChild);
  }
});

// ORES Article Quality Predictor
$.getScript(
  '//meta.wikimedia.org/w/index.php?title=User:EpochFail/ArticleQuality-system.js&action=raw&ctype=text/javascript',
  function () {
    articleQuality = new ArticleQuality({
      ores_host: "https://ores.wikimedia.org",
      weights: {
        Stub: 1,
        Start: 2,
        C: 3,
        B: 4,
        GA: 5,
        FA: 6
      },
      names: {
        Stub: "{{icon|Stub}}",
        Start: "{{icon|Start}}",
        C: "{{icon|C}}",
        B: "{{icon|B}}",
        GA: "{{icon|GA}}",
        FA: "{{icon|FA}}"
      },
      assessment_system: "Pseudoscience",
      dbname: "enwiki"
    });
    if (mw.config.get('wgAction') === "view" &&
        (mw.config.get('wgNamespaceNumber') === 0 ||
         mw.config.get('wgNamespaceNumber') === 2 ||
         mw.config.get('wgNamespaceNumber') === 118)) {
      articleQuality.getAndRenderScoreHeader();
    }
    articleQuality.addScoresToArticleLinks();
  }
);
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User%3AEpochFail%2FArticleQuality.css&action=raw&ctype=text/javascript');
importScript('User:DreamRimmer/User not around.js'); // Backlink: [[User:DreamRimmer/User not around.js]]
importScript('User:DreamRimmer/EasySubpage.js'); // Backlink: [[User:DreamRimmer/EasySubpage.js]]

(function () {
    if (mw.config.get("wgDBname") !== "enwiki") return;

    let seen = new Set();
    let count = 0;
    const baseInterval = 30000; // target interval: 30 seconds
    const minDelay = 5000;      // at least 5 seconds between checks

    // Create container in top-right styled like Wikipedia's built-in notifications
    const notifContainer = $('<div>')
        .css({
            position: "fixed",
            top: "0.5em",
            right: "3em",
            zIndex: 9999,
            fontFamily: "sans-serif"
        });

    const notifIcon = $('<span>')
        .text("🔔")
        .css({
            cursor: "pointer",
            fontSize: "16px",
            background: "#fff",
            border: "1px solid #ccc",
            borderRadius: "50%",
            padding: "4px 8px",
            fontWeight: "bold",
            position: "relative",
            boxShadow: "0 1px 4px rgba(0,0,0,0.1)"
        });

    const notifCount = $('<span>')
        .text("0")
        .css({
            position: "absolute",
            top: "-6px",
            right: "-6px",
            background: "#d33",
            color: "#fff",
            borderRadius: "50%",
            padding: "2px 6px",
            fontSize: "10px",
            display: "none"
        });

    const notifDropdown = $('<div>')
        .css({
            display: "none",
            position: "absolute",
            top: "30px",
            right: "0",
            width: "320px",
            maxHeight: "400px",
            overflowY: "auto",
            background: "#fff",
            border: "1px solid #ccc",
            borderRadius: "6px",
            boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
            padding: "10px"
        });

    // Toggle the dropdown on bell icon click
    notifIcon.on("click", function () {
        notifDropdown.toggle();
    });

    notifIcon.append(notifCount);
    notifContainer.append(notifIcon).append(notifDropdown);
    $("body").append(notifContainer);

    async function checkPending() {
        const start = performance.now();
        const url = "https://en.wikipedia.org/w/api.php?action=query&list=recentchanges&rcprop=title|ids|tags&rclimit=50&rcshow=!bot&format=json&origin=*";

        try {
            const res = await fetch(url);
            const data = await res.json();
            // Using optional chaining; most modern browsers support this.
            const changes = data?.query?.recentchanges || [];

            for (const change of changes) {
                if (change.tags.includes("flaggedrevs-pending") && !seen.has(change.revid)) {
                    seen.add(change.revid);
                    count++;

                    const pageTitle = change.title;
                    // Build a URL that’s safe for spaces, etc.
                    const pageUrl = `https://en.wikipedia.org/wiki/${encodeURIComponent(pageTitle.replace(/ /g, "_"))}`;

                    // Prepend a new alert item to the dropdown list
                    notifDropdown.prepend(
                        $("<div>")
                            .css({
                                marginBottom: "8px",
                                paddingBottom: "8px",
                                borderBottom: "1px solid #eee"
                            })
                            .append(
                                $("<a>")
                                    .attr("href", pageUrl)
                                    .attr("target", "_blank")
                                    .text(pageTitle)
                                    .css({ fontWeight: "bold", color: "#0645ad" })
                            )
                    );

                    // Update badge counter
                    notifCount.text(count).show();

                    // Optional extra notification using mw.notify
                    mw.notify(
                        $("<a>")
                            .attr("href", pageUrl)
                            .attr("target", "_blank")
                            .text("Pending: " + pageTitle)[0],
                        {
                            title: "Pending Change Alert",
                            autoHide: false
                        }
                    );
                }
            }
        } catch (e) {
            console.error("Pending changes check failed:", e);
        } finally {
            const duration = performance.now() - start;
            // Ensure a minimum delay even if the API call is slow
            const delay = Math.max(minDelay, baseInterval - duration);
            setTimeout(checkPending, delay);
        }
    }

    checkPending();
})();