Jump to content

User:Anne drew/SetupAutoArchive.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Anne drew (talk | contribs) at 19:22, 30 September 2017 (fix time check). 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.
function addAutoArchive() {
    var talkHeader = document.editform.wpTextbox1.value.toLowerCase().indexOf("talk header") === -1 &&
        confirm("Also prepend standard {{talk header}} to page?") ? "yes" : "no";
    if ((document.editform.wpTextbox1.value.indexOf("User:MiszaBot/config") === -1 && document.editform.wpTextbox1.value.indexOf("User:ClueBot III/ArchiveThis") === -1) ||
        confirm("It looks like this page already is being automatically archived. Are you sure you want to continue?")) {
        document.editform.wpTextbox1.value = "{{subst:" + "Setup auto archiving|notice=yes|talk=" + talkHeader + "}}\n" + document.editform.wpTextbox1.value
            .replace(/{{archiveme}}|{{longtalk}}|{{long talk}}|{{Tpcleanup}}/ig, '');
        document.editform.wpSummary.value = "Adding automatic archival using [[User:( ͡~ ͜ʖ ͡o)/SetupAutoArchive]]";
        document.getElementById('wpSave').click();
    }
}

jQuery(document).ready(function($) {
    if (mw.config.get('wgCanonicalNamespace').toLowerCase().indexOf("talk") > -1) {
        if (document.editform) {
            var shouldContinue = new URLSearchParams(window.location.search).get("setupArchive");
            if (shouldContinue && Date.now() - shouldContinue < 1200000) {
                addAutoArchive();
            }
        } else {
            var editLink = window.location.protocol + "//" + window.location.host + "/w/index.php?title=" +
                encodeURIComponent(mw.config.get('wgPageName')) + "&action=edit&setupArchive=" + Date.now();
            mw.util.addPortletLink("p-cactions", editLink, "Setup Archive", "autoArchive", "Add auto archival", "");
        }
    }
});