User:KwisatzH/common.js

mw.loader.load( 'ext.gadget.VisualFileChange' );
window.AjaxDeleteExtraButtons = [{
		'label': 'Dupe',
		'tag': '{' + '{duplicate|1=%PARAMETER%|user=%USER%}}',
		'img_summary': 'Tagging as duplicate of  [[%PARAMETER%]]',
		'prompt_text': 'Which file is this a duplicate of?',
        'optin_notify': 1
	},
];
// User script to add "Add Template" button to the "Tools" section on Wikimedia Commons
(function() {
    // Only run this script in the Category namespace (namespace number 14)
    if (mw.config.get('wgNamespaceNumber') === 14) {
        // Function to add the "Wikidata Infobox" template to the page
        function addWikidataInfobox() {
            // Get the page title
            var pageTitle = mw.config.get('wgPageName');

            // Edit the page to add the template
            new mw.Api().postWithEditToken({
                action: 'edit',
                title: pageTitle,
                appendtext: '\n{{Wikidata Infobox}}',
                summary: 'Adding Wikidata Infobox template (by [[User:KwisatzH/common.js|user script]])'
            }).done(function() {
                mw.notify('Wikidata Infobox template has been added!');
                location.reload(); // Reload the page to show the changes
            }).fail(function(error) {
                console.error('An error occurred while adding the template:', error);
                mw.notify('An error occurred while adding the template.', { type: 'error' });
            });
        }

        // Create the "Add Template" button
        var button = $('<li><a href="#">Add Wikidata infobox</a></li>');

        // Append the button to the "Tools" section
        $('#p-tb ul').append(button);

        // Add click event handler to the button
        button.on('click', function(e) {
            e.preventDefault();
            addWikidataInfobox();
        });
    }
})();
Category:Uses of Wikidata Infobox with no item