User:Ricewind/common.js: Difference between revisions

From Melvor Idle
(Created page with "$(document).ready(function() { // Create subpage link functionality function createSubpage() { var subpageTitle = prompt('Enter subpage title:'); if (!subpageTitle) return; var encodedTitle = encodeURIComponent(subpageTitle.trim()); var link = mw.config.get('wgScriptPath') + '/index.php?title=' + mw.config.get('wgPageName') + '/' + encodedTitle + '&action=edit&preload=Template:MoneyMakingGuide'; window.location.href = link;...")
 
No edit summary
Line 1: Line 1:
$(document).ready(function() {
document.addEventListener("DOMContentLoaded", function() {
     // Create subpage link functionality
     class MMGForm extends HTMLElement {
    function createSubpage() {
        constructor() {
        var subpageTitle = prompt('Enter subpage title:');
            super();
        if (!subpageTitle) return;
            const button = document.createElement('input');
        var encodedTitle = encodeURIComponent(subpageTitle.trim());
            button.type = 'button';
        var link = mw.config.get('wgScriptPath') + '/index.php?title=' + mw.config.get('wgPageName') + '/' + encodedTitle + '&action=edit&preload=Template:MoneyMakingGuide';
            button.value = 'Create Subpage';
        window.location.href = link;
            button.onclick = this.createSubpage;
            this.appendChild(button);
        }
 
        createSubpage() {
            var subpageTitle = prompt('Enter subpage title:');
            if (!subpageTitle) return;
            var encodedTitle = encodeURIComponent(subpageTitle.trim());
            var link = mw.config.get('wgScriptPath') + '/index.php?title=' + mw.config.get('wgPageName') + '/' + encodedTitle + '&action=edit&preload=Template:MoneyMakingGuide';
            window.location.href = link;
        }
     }
     }


     // Add a button to create a subpage dynamically
     customElements.define('mmgform', MMGForm);
    var createSubpageButton = '<input type="button" value="Create Subpage" onclick="createSubpage()">';
    $('#p-cactions').append(createSubpageButton);
});
});

Revision as of 18:05, 15 June 2024

document.addEventListener("DOMContentLoaded", function() {
    class MMGForm extends HTMLElement {
        constructor() {
            super();
            const button = document.createElement('input');
            button.type = 'button';
            button.value = 'Create Subpage';
            button.onclick = this.createSubpage;
            this.appendChild(button);
        }

        createSubpage() {
            var subpageTitle = prompt('Enter subpage title:');
            if (!subpageTitle) return;
            var encodedTitle = encodeURIComponent(subpageTitle.trim());
            var link = mw.config.get('wgScriptPath') + '/index.php?title=' + mw.config.get('wgPageName') + '/' + encodedTitle + '&action=edit&preload=Template:MoneyMakingGuide';
            window.location.href = link;
        }
    }

    customElements.define('mmgform', MMGForm);
});