MediaWiki:Gadget-AjaxTextureID.js

(function {   var config = mw.config.get([ 'wgCanonicalNamespace', 'wgCanonicalSpecialPageName', 'wgPageName' ]),   i18n;

if (       config.wgCanonicalNamespace === "File" ||        config.wgCanonicalSpecialPageName ||        window.AjaxTextureIDLoaded    ) { return; }

window.AjaxTextureIDLoaded = true; var isUCP = mw.config.get('wgVersion') !== '1.19.24';

function respHandler(res) { if (res === true) { console.log(i18n.msg('success').plain); if (isUCP) { mw.notify(i18n.msg('success').plain); } else { new BannerNotification(i18n.msg('success').escape, 'confirm').show; }           setTimeout(function {                window.location.reload;            }, 3000); } else { console.log(i18n.msg('fail').plain); if (isUCP) { mw.notify(i18n.msg('fail').plain, {                   type: 'error'                }); } else { new BannerNotification(i18n.msg('fail').escape, 'error').show; }       }    }

function click { var texture = prompt(i18n.msg('enterTexture').plain);

if (!texture) { console.log(i18n.msg('specify').plain); return; }

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

function init(lang) { i18n = lang;

$('.page-header__contribution-buttons .wds-list, .page-header__actions .wds-list').first.append(           $('').append( $('', {                   css: {                        cursor: 'pointer'                    },                    text: i18n.msg('textureID').plain,                    click: click                }) )       );    }

mw.hook('dev.i18n').add(function(lib) {       $.when( lib.loadMessages('AjaxTextureID'), mw.loader.using([               'mediawiki.api',                'mediawiki.user'            ].concat(isUCP ? ['mediawiki.notify'] : [])) ).then(init);   });

importArticle({       type: 'script',        article: 'u:dev:MediaWiki:I18n-js/code.js'    }); });