User:MonkeysHK/common.js

/** * AjaxHeadRender * @description Adds the texture ID to a file quickly * @author Eejit43 * * @notes Modified from u:dev:AjaxRedirect (Author: Ozuzanna) * */

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

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

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

function respHandler(res) { if (res === true) { console.log('Success'); if (isUCP) { mw.notify('Sucess'); } else { new BannerNotification(encodeURI('Success'), 'confirm').show; }           setTimeout(function {                window.location.reload;            }, 3000); } else { console.log('Fail'); if (isUCP) { mw.notify('Fail', {                   type: 'error'                }); } else { new BannerNotification(encodeURI('Fail'), 'error').show; }       }    }

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

if (!texture) { console.log('Input box empty'); 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);        }); }

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