Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Pokemon Showdown
- // @namespace pokemonshowdown
- // @include http://play.pokemonshowdown.com/*
- // @include https://play.pokemonshowdown.com/*
- // @include http://*.psim.us/*
- // @version 1
- // @grant unsafeWindow
- // ==/UserScript==
- try {
- function toId(s) {
- return s.toLowerCase().replace(/[^a-z0-9]+/g, "");
- }
- var ding = (function () {
- function sin(f, t) { return Math.sin(f * 2 * Math.PI * t); }
- function waveform(t) {
- var b = 880;
- return sin(b * 1.25, t) + sin(b * 1.5, t) + sin(b * 2, t);
- }
- function envelope(t) {
- var a = 40;
- var n = 1.3;
- return Math.pow(t, n - 1) / Math.pow(a * Math.pow(t, n) + 1, 2);
- }
- function round(n, by) {
- var r = n % by;
- if (r <= (by / 2))
- return n - r;
- else
- return n + by - r;
- }
- var sampleRate = 44100;
- var length = 2;
- var context = new AudioContext();
- var buffer = context.createBuffer(1, sampleRate * length, sampleRate);
- var samples = buffer.getChannelData(0);
- var maxSample = 0;
- for (var t = 0.000001, s = 0; t < length; t += 1 / sampleRate, ++s) {
- samples[s] = envelope(t) * waveform(t);
- maxSample = Math.max(Math.abs(samples[s]), maxSample);
- }
- for (var s = 0; s < samples.length; ++s)
- samples[s] /= maxSample;
- return function () {
- console.log("ding!");
- var node = context.createBufferSource();
- node.buffer = buffer;
- node.connect(context.destination);
- node.start(0);
- }
- })();
- unsafeWindow.ding = ding;
- function main() {
- probeInterval = setInterval(function () {
- if (unsafeWindow.app && unsafeWindow.app.socket && unsafeWindow.app.socket.onmessage &&
- unsafeWindow.app.socket.onmessage.toString().indexOf("self.receive") >= 0) {
- clearInterval(probeInterval);
- unsafeWindow.Tools.interstice.isWhitelisted = function () { return true; };
- unsafeWindow.app.socket._onmessage = unsafeWindow.app.socket.onmessage;
- unsafeWindow.app.socket.onmessage = function (msg) {
- if (unsafeWindow.logMessages)
- unsafeWindow.console.log(msg.data);
- try {
- var data = JSON.parse(msg.data);
- // console
- data = filterLogEntry(data);
- // init
- if (data.log)
- data.log = filterLog(data.log);
- // update
- if (/*data.logUpdate || */data.updates)
- data.updates = filterLog(data.updates);
- msg.data = JSON.stringify(data);
- } catch (e) {
- msg.data = filterLog(msg.data.split("\n")).join("\n");
- }
- return this._onmessage(msg);
- };
- unsafeWindow.app.rooms['']._addPM = unsafeWindow.app.rooms[''].addPM;
- unsafeWindow.app.rooms[''].addPM = function (user, message, pm) {
- if (!unsafeWindow.app.focused)
- ;
- return this._addPM(user, message, pm);
- };
- var botCounter = {n: 0, nSpamCheck: 0, t: 0};
- unsafeWindow.ChatRoom.prototype._add = unsafeWindow.ChatRoom.prototype.add;
- unsafeWindow.ChatRoom.prototype.add = function (log) {
- this._add(log);
- if (typeof log === "string")
- log = log.split("\n");
- if (log.length !== 1)
- return;
- var parts = log[0].split("|");
- if (parts[1] === "c") {
- if (Date.now() > botCounter.t + 5 * 60 * 1000)
- botCounter.n = 0;
- if (Date.now() > botCounter.t + 30 * 1000)
- botCounter.nSpamCheck = 0;
- var reply = (function(message) {
- botCounter.t = Date.now();
- this.send(message + new Array(++botCounter.n + 1).join("\u200c"));
- ++botCounter.nSpamCheck;
- }).bind(this);
- if (botCounter.nSpamCheck >= 3)
- return;
- }
- }
- probeInterval = setInterval(function () {
- if (unsafeWindow.app.socket.readyState !== 1 || unsafeWindow.app.user.attributes.userid.indexOf("guest") === 0)
- return;
- clearInterval(probeInterval);
- if (unsafeWindow.Config.server.id === "showdown") {
- unsafeWindow.app.socket.send("|/join WiFi");
- unsafeWindow.app.socket.send("|/join Lobby");
- unsafeWindow.app.socket.send("|/join Freetime");
- unsafeWindow.app.socket.send("|/join Textquest");
- setTimeout(function(){
- unsafeWindow.app.socket.send("|/join Overused");
- unsafeWindow.app.socket.send("|/join Ubers");
- unsafeWindow.app.socket.send("|/join Meteorfalls");
- unsafeWindow.app.socket.send("|/join Academics");
- }, 3000);
- setTimeout(function(){
- unsafeWindow.app.socket.send("|/msg smelliott, Sharon is hot")
- unsafeWindow.app.socket.send("|/msg Shgeldz, ( ͡° ͜ʖ ͡°)")
- }, 3000);
- }
- if (unsafeWindow.app.user.attributes.userid !== avatarNick && nicks[unsafeWindow.app.user.attributes.userid]) {
- var oldNick = unsafeWindow.app.user.attributes.userid;
- unsafeWindow.app.user.rename(avatarNick);
- probeInterval = setInterval(function () {
- if (unsafeWindow.app.user.attributes.userid !== avatarNick)
- return;
- clearInterval(probeInterval);
- unsafeWindow.app.user.rename(oldNick);
- }, 0);
- }
- }, 0);
- }
- }, 0);
- }
- function isContainsJavascript(text) {
- return text.toLowerCase().indexOf("<script") >= 0 || text.toLowerCase().match(/<[^>]+on[a-z]+=/);
- }
- function filterLog(log) {
- for (var l = 0; l < log.length; ++l)
- log[l] = filterLogEntry(log[l]);
- return log;
- }
- function filterLogEntry(entry) {
- if (typeof entry === "string") {
- if (entry[0] === '|' && entry.indexOf("|", 1) >= 0) {
- var command = entry.split("|");
- if ((command[1] === "raw" && isContainsJavascript(entry)) ||
- (command[1] === "c" && command[3].indexOf("/warn") === 0)) {
- command[1] = "";
- entry = command.join("|");
- }
- }
- if (entry.indexOf("|refresh") == 0 || entry.indexOf("|deinit") == 0 || entry.match(/\|noinit\|?$/))
- return "||" + entry;
- }
- if (entry.evalRawMessage) {
- entry.message = entry.evalRawMessage;
- delete entry.evalRawMessage;
- }
- if (entry.evalRulesRedirect) {
- entry.message = "evalRulesRedirect";
- delete entry.evalRulesRedirect;
- }
- if (entry.rawMessage && isContainsJavascript(entry.rawMessage)) {
- entry.message = entry.rawMessage;
- delete entry.rawMessage;
- }
- return entry;
- }
- main();
- } catch (e) { console.log(e); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement