Jump to content

User:Ilmari Karonen/fixdontknow.js

From Wikipedia, the free encyclopedia
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.
// DELETE / FIX IMAGES WITH UNKNOWN COPYRIGHT:

if (mw.config.get('wgPageName') == "Category:Uploader_unsure_of_copyright_status") addOnloadHook(function () {
    var mediaDiv = document.getElementById('mw-category-media');
    if (!mediaDiv) return;
    var links = mediaDiv.getElementsByTagName('a');
    for (var i = 0; i < links.length; i++) {     
        if (!/^(Image|File):/i.test(links[i].title)) continue;
        if (!/(^|\s)gallerytext(\s|$)/.test(links[i].parentNode.className)) continue;

        var encTitle = encodeURIComponent(links[i].title);

        var frag = document.createDocumentFragment();
        frag.appendChild(document.createElement('br'));
        frag.appendChild(document.createTextNode(" ("));

        var delLink = document.createElement('a');
        delLink.href = mw.config.get('wgScript') + "?title=" + encTitle + "&action=delete&wpReason=Copyright+status+not+confirmed+within+a+week+of+uploading";
        delLink.appendChild(document.createTextNode("del"));
        frag.appendChild(delLink);
        frag.appendChild(document.createTextNode(") ("));

        var logoLink = document.createElement('a');
        logoLink.href = mw.config.get('wgScript') + "?title=" + encTitle + "&action=edit&fixdontknow=Non-free%20logo";
        logoLink.appendChild(document.createTextNode("logo"));
        frag.appendChild(logoLink);
        frag.appendChild(document.createTextNode(") "));

        links[i].parentNode.insertBefore(frag, links[i].nextSibling);
    }
});

if (mw.config.get('wgAction') == "edit" && /[?&]fixdontknow=/.test(window.location.search)) addOnloadHook(function () {
    var editForm = document.forms.editform;
    if (!editForm) return;
    var tag = /[?&]fixdontknow=([^&]*)/.exec(window.location.search);
    if (!tag) return;
    tag = "{{" + decodeURIComponent(tag[1]) + "}}";
    var oldText = editForm.wpTextbox1.value;
    var newText = oldText.replace(/\{\{[\s_]*(don't[ _]?know|some[ _]?web[ _]?site)[\s_]*\}\}/ig, tag);
    editForm.wpTextbox1.value = newText;
    editForm.wpSummary.value = tag;
    editForm.wpMinoredit.checked = true;
    if (oldText != newText) editForm.wpDiff.click();  // I'm NOT feeling lucky!
});