Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name RTB
- // @version 1.0.0
- // @grant unsafeWindow
- // @author me
- // @match http://play.pokemonshowdown.com/*
- // @match https://play.pokemonshowdown.com/*
- // @match http://*.psim.us/*
- // @match https://*.psim.us/*
- // ==/UserScript==
- var teams = {};
- var search = false;
- fetch('https://raw.githubusercontent.com/Maxouille64/database/main/teams.json')
- .then(response => response.json())
- .then(data => teams = data)
- .then(teams => app.send('/code RANDOMIZABLE FORMATS: \n' + Object.keys(teams)));
- const BYPASS_CORS = 'https://cors-anywhere-hd.herokuapp.com/https://drive.google.com/uc?id=' //à changer
- const cancel_button = document.getElementById("rtbcancelSearch");
- function getRandom(min, max) {
- let random = (Math.floor(Math.random() * max/2)+ min/2) * 2;
- return random;
- };
- function cancel_rtb() {
- cancel = true;
- cancel_button.style="display: none";
- };
- function getCookie(cname) {
- var name = cname + "=";
- var ca = document.cookie.split(';');
- for(var i = 0; i < ca.length; i++) {
- var c = ca[i];
- while (c.charAt(0) == ' ') {
- c = c.substring(1);
- }
- if (c.indexOf(name) == 0) {
- return c.substring(name.length, c.length);
- }
- }
- return "";
- };
- function rtb(Tier, txt){
- let myteams = txt.split("===");
- var team = myteams[getRandom(2, myteams.length)];
- //for node.js use global instead of window
- //var console = global.console;
- window.console.log = function(msg){
- if(msg.includes('|popup|Your team was rejected for the following reasons'))
- //app.closePopup();
- rtb(Tier,txt);
- return;
- };
- if (cancel == true) {
- cancel = false;
- cancel_button.style="display: none";
- return;
- } else if(team) {
- team.replace(/^\s\s*/, '');
- team.replace(/\s\s*$/, '');
- app.send("/code " + team);
- team_json = PokemonTeams.importTeam(team);
- app.sendTeam(team_json);
- app.send(`/battle! ${Tier}`);
- } else {
- cancel_button.style="display: none";
- app.send("/code request failed/unavailable tier, try with /rtb [tier] in a chatroom");
- return;
- };
- }
- function rta(Tier, team){
- if (cancel == true) {
- cancel = false;
- cancel_button.style="display: none";
- return;
- } else if(team) {
- team.replace(/^\s\s*/, '');
- team.replace(/\s\s*$/, '');
- app.send("/code " + team);
- team_json = PokemonTeams.importTeam(team);
- app.sendTeam(team_json);
- app.send(`/battle! ${Tier}`);
- } else {
- cancel_button.style="display: none";
- app.send("/code request failed/unavailable tier, try with /rtb [tier] in a chatroom");
- return;
- };
- }
- function rtc(Tier, User, txt) {
- let myteams = txt.split("===");
- var team = myteams[getRandom(2, myteams.length)];
- window.console.log = function(msg){
- if(msg.includes('|popup|Your team was rejected for the following reasons'))
- //app.closePopup();
- rtc(Tier,User,txt);
- return;
- };
- if (team) {
- team.replace(/^\s\s*/, '');
- team.replace(/\s\s*$/, '');
- app.send(`/code ${team}`);
- team_json = PokemonTeams.importTeam(team);
- app.sendTeam(team_json);
- app.send(`/challenge ${User}, ${Tier}`);
- } else {
- app.send("/code request failed/unavailable tier, try with /rtb [tier] in a chatroom");
- };
- };
- var cancel = false;
- ConsoleRoom.prototype.customCommands = {};
- ConsoleRoom.prototype.customCommands['rtb'] = function(Self, Tier) {
- var mod = getCookie("mod");
- cancel_button.style="";
- if (mod == "default") {
- fetch(BYPASS_CORS + teams[Tier])
- .then(rep => rep.text())
- .then(result => rtb(Tier, result))
- } else if (mod == "easy") {
- fetch(`https://maxouille.pythonanywhere.com/lunatic/?input={"tier":"${Tier}","mod":"easy"}`).then(r => r.text()).then(result => {
- console.log(result);
- rta(Tier, result);
- })
- } else if (mod == "normal") {
- fetch(`https://maxouille.pythonanywhere.com/lunatic/?input={"tier":"${Tier}","mod":"normal"}`).then(r => r.text()).then(result => {
- console.log(result);
- rta(Tier, result);
- })
- } else if (mod == "hard") {
- fetch(`https://maxouille.pythonanywhere.com/lunatic/?input={"tier":"${Tier}","mod":"hard"}`).then(r => r.text()).then(result => {
- console.log(result);
- rta(Tier, result);
- })
- } else if (mod == "lunatic") {
- fetch(`https://maxouille.pythonanywhere.com/lunatic/?input={"tier":"${Tier}","mod":"lunatic"}`).then(r => r.text()).then(result => {
- console.log(result);
- rta(Tier, result);
- })
- } else if (mod == "matrix") {
- fetch('https://maxouille.pythonanywhere.com/matrix/?input={"tier":"gen8ou"}').then(r => r.text()).then(result => {
- console.log(result);
- rta(Tier, result);
- })
- } else if (mod == "teambuilder") {
- fetch(`https://maxouille.pythonanywhere.com/teambuilder/?input={"tier":"${Tier}","data":${localStorage.getItem("showdown_teams")}}`).then(r => r.text()).then(result => {
- console.log(result);
- //rta(Tier, result);
- })
- } else {
- fetch(BYPASS_CORS + teams[Tier])
- .then(rep => rep.text())
- .then(result => rtb(Tier, result))};
- };
- ConsoleRoom.prototype.customCommands['rtc'] = function(Self, Tier, User) {
- fetch(BYPASS_CORS + teams[Tier])
- .then(rep => rep.text())
- .then(result => rtc(Tier, User, result))};
- ConsoleRoom.prototype.parseCommandOrig = ConsoleRoom.prototype.parseCommand;
- ConsoleRoom.prototype.parseCommand = function(Text) {
- var cmd = '';
- var target = '';
- var noSpace = false;
- var user = 'guest';
- if (Text.substr(0, 2) !== '//' && Text.substr(0, 3) === '/rt') {
- app.send('/utm');
- var spaceIndex = Text.indexOf(' ');
- var commaIndex = Text.indexOf(',');
- if (commaIndex > 0) {
- Text = Text.split(",")
- cmd = Text[0].substr(1, spaceIndex - 1);
- console.log("//CMD");
- console.log(cmd);
- target = Text[0].substr(spaceIndex + 1).toLowerCase();
- console.log("//TARGET");
- console.log(target);
- user = Text[1]
- console.log("//user");
- console.log(user);
- }
- else if (spaceIndex > 0) {
- cmd = Text.substr(1, spaceIndex - 1);
- console.log("//CMD");
- console.log(cmd);
- target = Text.substr(spaceIndex + 1).toLowerCase();
- console.log("//TARGET");
- console.log(target);
- } else {
- console.log("//CMD");
- cmd = Text.substr(1);
- console.log(cmd)
- target = '';
- noSpace = true;
- }
- };
- if (this.customCommands[cmd.toLowerCase()]) return this.customCommands[cmd.toLowerCase()](this, target, user);
- return this.parseCommandOrig(Text);
- };
Advertisement
Add Comment
Please, Sign In to add comment