Käyttäjä:MGA73/common.js

Wikipediasta
Siirry navigaatioon Siirry hakuun

Huomautus: Selaimen välimuisti pitää tyhjentää asetusten tallentamisen jälkeen, jotta muutokset tulisivat voimaan.

  • Firefox ja Safari: Napsauta Shift-näppäin pohjassa Päivitä, tai paina Ctrl-F5 tai Ctrl-R (⌘-R Macilla)
  • Google Chrome: Paina Ctrl-Shift-R (⌘-Shift-R Macilla)
  • Edge: Napsauta Ctrl-näppäin pohjassa Päivitä tai paina Ctrl-F5
$(document).ready(function() {
    function addButtons() {
        if (mw.config.get('wgNamespaceNumber') === 6 || mw.config.get('wgPageName') === 'Käyttäjä:MGA73/Sandbox') {
            var buttonContainer = $('<div>').css({'margin': '10px 0'});
            
            var relicenseButton = $('<button>')
                .text('Relicense')
                .css({
                    'cursor': 'pointer',
                    'margin-right': '10px'
                })
                .click(function(event) {
                    event.preventDefault();
                    // Redirect to the edit page with relicense marker
                    var editUrl = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', relicense: true });
                    window.location.href = editUrl;
                });
            
            var notEligibleButton = $('<button>')
                .text('Not-eligible')
                .css({
                    'cursor': 'pointer',
                    'margin-right': '10px'
                })
                .click(function(event) {
                    event.preventDefault();
                    // Redirect to the edit page with not-eligible marker
                    var editUrl = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', noteligible: true });
                    window.location.href = editUrl;
                });
            
            var redundantButton = $('<button>')
                .text('Redundant')
                .css({
                    'cursor': 'pointer'
                })
                .click(function(event) {
                    event.preventDefault();
                    // Redirect to the edit page with redundant marker
                    var editUrl = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', redundant: true });
                    window.location.href = editUrl;
                });
            
            buttonContainer.append(relicenseButton).append(notEligibleButton).append(redundantButton);
            
            var content = $('#content');
            if (content.length) {
                content.prepend(buttonContainer);
            }
        }
    }
    
    function applyChangesOnEditPage() {
        if (mw.config.get('wgAction') === 'edit') {
            var urlParams = new URLSearchParams(window.location.search);
            var relicense = urlParams.get('relicense');
            var noteligible = urlParams.get('noteligible');
            var redundant = urlParams.get('redundant');
            
            var newGFDLTemplate;
            var newGFDLWithDisclaimersTemplate;
            var summary;
            
            if (relicense) {
                newGFDLTemplate = '{{GFDL/Oma|migration=relicense}}';
                newGFDLWithDisclaimersTemplate = '{{GFDL-with-disclaimers|migration=relicense}}';
                summary = 'Eligible for [[:w:en:Wikipedia:Image license migration|GFDL relicense]]. Uploaded before August 2009.';
            } else if (noteligible) {
                newGFDLTemplate = '{{GFDL/Oma|migration=not-eligible}}';
                newGFDLWithDisclaimersTemplate = '{{GFDL-with-disclaimers|migration=not-eligible}}';
                summary = 'Not eligible for [[:w:en:Wikipedia:Image license migration|GFDL relicense]]. Uploaded after August 2009. Uploader please consider adding {{Cc-by-sa-4.0}}.';
            } else if (redundant) {
                newGFDLTemplate = '{{GFDL/Oma|migration=redundant}}';
                newGFDLWithDisclaimersTemplate = '{{GFDL-with-disclaimers|migration=redundant}}';
                summary = 'File is considered redundant for [[:w:en:Wikipedia:Image license migration|GFDL relicense]]..';
            }
            
            if (newGFDLTemplate && newGFDLWithDisclaimersTemplate) {
                var editBox = $('#wpTextbox1');
                var currentText = editBox.val();
                
                // Replace {{GFDL}} and {{GFDL-with-disclaimers}} with the new templates
                var updatedText = currentText
                    .replace(/{{GFDL\/Oma}}/g, newGFDLTemplate)
                    .replace(/{{GFDL-with-disclaimers}}/g, newGFDLWithDisclaimersTemplate);
                editBox.val(updatedText);
            }
            
            if (summary) {
                $('#wpSummary').val(summary);
            }
        }
    }

    addButtons();
    applyChangesOnEditPage();
});