MediaWiki:VerifyWikiUser.js

/** * VerifyUser - add Discord handle automatically to user profiles on Fandom. * To efficiently perform verification, provide a link in the form * https://community.fandom.com/wiki/Special:VerifyUser/?user=&tag= * * @author Noreplyz *Script is taken from the Fandom Developers Wiki and altered to make the command output be compatable with Wiki-Bot. All credit goes to Noreplyz. */   var templates = {}, verifyUser = {}, config = mw.config.get([        'wgPageName',        'wgTitle',        'wgUserId',        'wgUserName',        'wgNamespaceNumber'    ]); if (config.wgNamespaceNumber !== -1 || !config.wgTitle.match(/VerifyUser.*/)) return; /**    * Trims URL and other fluff from a username * @param {String} user the unclean username * @returns {String} the cleaned username */   var cleanUser = function (user) { if (!user) return ''; // Trim whitespaces and new lines user = user.replace(/^[\s\n]+|[\s\n]+$/g, ''); // Clean up links user = user.replace(/^https?:\/\//g, ''); user = user.replace(/^.*\.(wikia|fandom|gamepedia)\.(com|org|io)\/(wiki\/)?/g, ''); user = user.replace(/^(User:|Special:Contributions\/|Special:Contribs\/)/g, ''); // Replace spaces user = user.replace(/(%20|_)/g, ' '); // Uppercase first letter of the username user = user.charAt(0).toUpperCase + user.slice(1); return user; };   // Main template shown to all users templates.main = '' +  +             +                ' ' +                    'error-loggedin' + ' ' +            '' +            'verify-instructions  ' + ' ' + ' button-verify ' + ' verify-notice ' +  +         +             'verify-login verify-gamepedia  ' + '' + ' button-login ' + '' + '' +       ' ';    // Template shown after a Discord handle is submitted templates.complete = '' + 'verify-complete ' + ' ' + ' ';   templates.error = ' ' +           'general-error ' + '' +       ' ';    verifyUser.servicesHost = 'https://services.fandom.com/'; verifyUser._setDiscordHandle = function (userid, discordHandle) { return $.ajax(verifyUser.servicesHost + 'user-attribute/user/' + userid + '/attr/discordHandle', {           type: 'PUT',            format: 'json',            data: {                value: discordHandle            },            xhrFields: {                withCredentials: true            }        }); };   verifyUser._clearProfileCache = function { return $.nirvana.postJson('UserProfilePage', 'saveUserData', {           userId: mw.config.get('wgUserId'),            data: '{"birthday":""}',            token: mw.user.tokens.get('editToken')        }); };   verifyUser.toi18n = function  { return function (text, render) { return render(mw.html.escape(verifyUser.i18n.msg(text).plain)); };   };    // Starts the script verifyUser.init = function (i18n) { i18n.loadMessages('VerifyUser').done(function (i18n) {           verifyUser.i18n = i18n;            // Update header/title            $('.page-header__title').text(i18n.msg('title').plain);            $(document).prop('title', i18n.msg('title').plain + ' | Fandom');            var username = config.wgUserName,                pagename = config.wgPageName,                discordHandle = ,                providedUsername = pagename.indexOf('/') > -1 ? pagename.replace(/^.*\//g, ) : '',                userid = config.wgUserId;            if (mw.util.getParamValue('user') && mw.util.getParamValue('tag')) {                discordHandle = mw.util.getParamValue('user') + '#' + mw.util.getParamValue('tag');            }            // Place the form into the main content section of the page            $('#mw-content-text').replaceWith(Mustache.render(templates.main, {                username: username, backlink: encodeURIComponent(window.location), usernameCompare: cleanUser(providedUsername) === cleanUser(username) || cleanUser(providedUsername) === '', discordHandle: discordHandle, i18n: verifyUser.toi18n }));           // On click of verify, set Discord handle $('#verify').on('click', function {                verifyUser._setDiscordHandle(userid, $('#verify-input').val).done(function (data) { verifyUser._clearProfileCache; // async, but no need to check if it actually goes through $('#WikiaArticle').empty.append(Mustache.render(templates.complete, { username: username, i18n: verifyUser.toi18n }));               }).fail(function (e) { $('#WikiaArticle').empty.append(Mustache.render(templates.error, { error: JSON.parse(e.responseText).title, i18n: verifyUser.toi18n }));               });                $('#WikiaArticle').empty.append(i18n.msg('loading').plain);            }); // On Enter keypress, perform verification $('#verify-input').keypress(function (e) {               if (e.which === 13) {                    $('#verify').click;                }            }); });   };    importArticle({ type: 'script', article: 'u:dev:MediaWiki:I18n-js/code.js' });   mw.hook('dev.i18n').add(verifyUser.init); })(window, jQuery, mediaWiki, Mustache);
 * (function(window, $, mw, Mustache) {