User:علاء/common.js

importScript( 'User:Enterprisey/reply-link.js' ); // Backlink: User:Enterprisey/reply-link.js importScript('User:Kephir/gadgets/rater.js'); // User:Kephir/gadgets/rater

//https://en.wikipedia.org/wiki/User:Σ/Testing_facility/Archiver.js // Translated by: User:Zaher.Kadour/Archiver.js $(document).ready(function {   if (mw.config.get("wgNamespaceNumber") == -1)        // is a special page        return;    $("head").append(" a.arkylink { font-weight:bold } .arkyhighlight { background-color:#D9E9FF } ");    var validSections = new Object;    var fromTos = new Object;    var wikiText = "";    var revStamp;    var startArchiveButton = mw.util.addPortletLink("p-cactions", "#", "archiving", "pt-oeca", "Start/End the Archive Wizard", null, null);    var overlay = $(document.createElement("button"));    $(startArchiveButton).click(function(e) { $(".arkylink").click; $(".arky").toggle; $("#archivebutton").toggle; });   overlay.html("archiving all sections")        .attr("id", 'archivebutton')        .css("position", 'fixed')        .css("bottom", 0)        .css("height", '44px')        .css("width", '100%')        .css("font-size", '200%');    $(document.body).append(overlay);    overlay.toggle;    overlay.click(function(e) { var numOfThreads, archiveTarget; var sections, archiveThis; var cutOffset, revisedPage; function cut(s, start, end) { return s.substr(0, start) + s.substring(end); }       cutOffset = numOfThreads = 0; revisedPage = wikiText; sections = $("a.arkylink").map(function {           return $(this).attr("data-section");        }); if (!(numOfThreads = sections.length)) return alert("No section selected, Cancel"); archiveTarget = prompt("archiving" + numOfThreads + "Sections: What is the title of the archive page?", mw.config.get("wgPageName")); if (!archiveTarget || archiveTarget == mw.config.get("wgPageName")) return alert("No selected archive page, Cancel"); sections.each(function(i, n) {           revisedPage = cut( revisedPage, fromTos[n][0] - cutOffset, fromTos[n][1] - cutOffset );           cutOffset += fromTos[n][1] - fromTos[n][0];        }); archiveThis = sections.map(function {           return wikiText.substring(fromTos[this][0], fromTos[this][1]);        }).toArray.join(""); console.log("archive this:" + archiveThis); console.log("revised page:" + revisedPage); if (1) new mw.Api.postWithToken("csrf", {action: 'edit', title: mw.config.get("wgPageName"), text: revisedPage, summary: "archiving " + numOfThreads + " sections to " + archiveTarget + "", basetimestamp: revStamp, starttimestamp: revStamp}) .done(function(res1) {               alert("section successfully moved");                console.log(res1);                new mw.Api.postWithToken("csrf", {action: 'edit', title: archiveTarget, appendtext: "\n" + archiveThis, summary: "archiving from " + mw.config.get("wgPageName") + ""})                    .done(function(res2) { alert("Sections have been added to the archive page successfully"); })                   .fail(function(res2) { alert("Failed to add the sections to the archive page. Manual checking is required"); })                   .always(function(res2) { console.log(res2); window.location.reload; });           })            .fail(function(res1) {                alert("Failed to add the sections to the archive page. Canecel the archiving process.");                console.log(res1);                window.location.reload;            }); });   new mw.Api.get({action: 'parse', page: mw.config.get("wgPageName")}).done(function(dataShit) { new mw.Api.get({action: 'query', pageids: mw.config.get("wgArticleId"), prop: ['revisions'], rvprop: ['content', 'timestamp']}).done(function(shit) {           var rv;            rv = shit.query.pages[mw.config.get("wgArticleId")].revisions[0];            wikiText = rv["*"];            revStamp = rv['timestamp'];        }); $(dataShit.parse.sections) .filter(function(i, s) { return s.index == parseInt(s.index) }) .each(function(i, s) { validSections[s.index] = s }); for (var i in validSections) { i = parseInt(i); fromTos[i] = [ validSections[i].byteoffset, validSections.hasOwnProperty(i+1)?validSections[i+1].byteoffset:Infinity ];       }        $("#mw-content-text").find(":header").find("span.mw-headline").each(function(i, title) {            var header, editSection, sectionNumber;            header = $(this).parent;            editSection = header.find(".mw-editsection"); // 1st child            sectionNumber = header.find(".mw-editsection a:first");            if (sectionNumber[0]) {                sectionNumber = sectionNumber.attr("href").match(/&section=(\d+)/);                if (sectionNumber)                    sectionNumber = sectionNumber[1];            } else // eg not a real section                 sectionNumber = undefined;            if (validSections.hasOwnProperty(sectionNumber))                editSection[0].innerHTML += "  [ أرشف ]  ";        }); }); });