Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Avatar Change
- // @namespace http://use.i.E.your.homepage/
- // @version 1.1
- // @description Pokemon Showdown! moderator's best friend
- // @include http://play.pokemonshowdown.com/
- // @include https://play.pokemonshowdown.com/
- // @include http://play.pokemonshowdown.com/*
- // @include https://play.pokemonshowdown.com/*
- // @include http://*.psim.us/
- // @include https://*.psim.us/
- // @include http://*.psim.us/*
- // @include https://*.psim.us/*
- // ==/UserScript==
- /////////////////////////////////////////
- // PS Custom Avi script by sparkychild //
- /////////////////////////////////////////
- // replace the preset url with whatever you want your avatar to display as for yourself.
- // please note only you can see the custom avatar!
- var customAvatarUrl = "https://i.imgur.com/YxUyTDB.png";
- Tools.resolveAvatar = function (avatar) {
- if (avatar === customAvatarUrl)
- return customAvatarUrl;
- var avatarnum = Number(avatar);
- if (!isNaN(avatarnum)) {
- // default avatars
- return Tools.resourcePrefix + 'sprites/trainers/' + avatarnum + '.png';
- }
- if (avatar.charAt(0) === '#') {
- return Tools.resourcePrefix + 'sprites/trainers/' + toId(avatar.substr(1)) + '.png';
- }
- if (window.Config && Config.server && Config.server.registered) {
- // custom avatar served by the server
- var protocol = (Config.server.port === 443) ? 'https' : 'http';
- return protocol + '://' + Config.server.host + ':' + Config.server.port +
- '/avatars/' + _.map(avatar.split('?', 2), encodeURIComponent).join('?');
- }
- // just pick a random avatar
- var sprites = [1, 2, 101, 102, 169, 170];
- return Tools.resolveAvatar(sprites[Math.floor(Math.random() * sprites.length)]);
- };
- try {
- function main2() {
- probeInterval2 = setInterval(function () {
- if (unsafeWindow.app && unsafeWindow.app.socket && unsafeWindow.app.socket.onmessage &&
- (unsafeWindow.app.socket.onmessage.toString().indexOf("self.receive") >= 0 || unsafeWindow.app.socket._onmessage)) {
- clearInterval(probeInterval2);
- unsafeWindow.app.socket._onmessage2 = unsafeWindow.app.socket.onmessage;
- unsafeWindow.app.socket.onmessage = function (msg) {
- try {
- var data = JSON.parse(msg.data);
- // console
- data = filterLogEntry2(data);
- // init
- if (data.log)
- data.log = filterLog2(data.log);
- // update
- if (/*data.logUpdate || */data.updates)
- data.updates = filterLog2(data.updates);
- msg.data = JSON.stringify(data);
- } catch (e) {
- msg.data = filterLog2(msg.data.split("\n")).join("\n");
- }
- return this._onmessage2(msg);
- };
- }
- }, 0);
- }
- function filterLog2(log) {
- for (var l = 0; l < log.length; ++l)
- log[l] = filterLogEntry2(log[l]);
- return log;
- }
- function filterLogEntry2(entry) {
- if (typeof entry === "string") {
- if (entry.startsWith('|player|')) {
- var [nothing, nothing2, side, name, avatar] = entry.split('|');
- if (name === unsafeWindow.app.user.attributes.name) avatar = customAvatarUrl;
- return [nothing, nothing2, side, name, avatar].join('|');
- } else if (entry.startsWith("|queryresponse|userdetails|")) {
- var json = JSON.parse(entry.slice(27));
- if (json.userid === unsafeWindow.app.user.attributes.userid)
- json.avatar = customAvatarUrl;
- return "|queryresponse|userdetails|" + JSON.stringify(json);
- }
- }
- return entry;
- }
- setTimeout(function () {
- main2();
- }, 2000);
- } catch (e) {
- console.log(e);
- }
- // ==/UserScript==
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement