MediaWiki:Gadget-AjaxTextureID.js

mw.loader.using(['mediawiki.util', 'mediawiki.Uri', 'ext.fandom.ContentReview.legacyLoaders.js'], function {   var config = mw.config.get([ 'wgCanonicalNamespace', 'wgCanonicalSpecialPageName', 'wgPageName' ]);

if (       config.wgCanonicalNamespace !== "File" ||        config.wgCanonicalSpecialPageName ||        window.AjaxTextureIDLoaded    ) { return; }   const logger = (function {    	Object.keys(this).forEach(function(method) { var oldMethod = this[method]; this[method] = function { var args = Array.from(arguments); if (args[args.length-1] === true) { args.pop; mw.notify(args.join(' ')); oldMethod.apply(null, ['[AjaxTextureID] [' + method.toUpperCase + ']:'].concat(args)); } else { oldMethod.apply(null, ['[AjaxTextureID] [' + method.toUpperCase + ']:'].concat(args)); }   		}.bind(this); }, this);   	return this;    }).call({    	log: console.log,    	warn: console.warn,    	error: console.error,    });

window.AjaxTextureIDLoaded = true;

function respHandler(res, d) { if (res === true) { logger.log("Successfully added the texture id to the file!", true); setTimeout(function {               window.location.reload;            }, 3000); } else { logger.warn("Failed to add the texture id to the file: " + d.error.info); }   }

function click { var texture = prompt('Enter Texture ID');

if (!texture) { logger.warn('Input box empty', true); return; }

if (!/^[a-f0-9]{59,64}$/i.test(texture)) { logger.warn('Not a valid texture ID: ' + texture, true); return; }

new mw.Api.post({           action: 'edit',            watchlist: 'nochange',            title: config.wgPageName,            minor: true,            bot: true,            text: '',            token: mw.user.tokens.get('editToken')        }).then(function(d) {            respHandler(true, d);        }, function(_, e) {            respHandler(false, e);        }); }

$('.page-header__contribution-buttons .wds-list, .page-header__actions .wds-list').first.append(       $('').append( $('', {               css: {                    cursor: 'pointer'                },                text: 'Add Texture ID',                click: click            }) )   ); });