Jump to content

User:DimensionalFusion/common.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by DimensionalFusion (talk | contribs) at 22:27, 5 August 2024. 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.
importScript( 'User:Novem Linguae/Scripts/GANReviewTool.js' ); // Backlink: [[User:Novem Linguae/Scripts/GANReviewTool.js]]

mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Awesome_Aasim/rcpatrol.js&action=raw&ctype=text/javascript');

importScript('User:Shubinator/DYKcheck.js'); //DYKcheck tool

mw.loader.load( '/w/index.php?title=User:Evad37/duplinks-alt.js&action=raw&ctype=text/javascript' ); // Backlink: [[User:Evad37/duplinks-alt.js]]

mw.loader.using('ext.discussionTools.init').then(function() {
    // Wait for DiscussionTools to load
    mw.hook('ext.discussionTools.init').add(function() {
        function addTemplateButton(name, template) {
            const button = document.createElement('button');
            button.className = 'tool';
            button.type = 'button';
            button.innerText = name;
            button.addEventListener('click', function() {
                const textarea = document.querySelector('.ve-ui-wikitextAnnotationInputWidget textarea');
                if (textarea) {
                    const selectionStart = textarea.selectionStart;
                    const selectionEnd = textarea.selectionEnd;
                    const selectedText = textarea.value.substring(selectionStart, selectionEnd);
                    const wrappedText = `{{${template}|${selectedText}}}`;
                    textarea.setRangeText(wrappedText, selectionStart, selectionEnd, 'end');
                }
            });

            const toolbar = document.querySelector('.ve-init-mw-desktopArticleTarget-toolbar');
            if (toolbar) {
                toolbar.appendChild(button);
            }
        }

        // Add buttons for each template
        addTemplateButton('tq', 'tq');
        addTemplateButton('!tq', '!tq');
        addTemplateButton('tqi', 'tqi');
        addTemplateButton('tbqm', 'tbqm');
    });
});