Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Play x Games
- // @description closes the tab after a set number of games
- // (requested thread: https://redd.it/3pf4y0)
- // @version 0.1.2
- // @include http://tagpro-*.koalabeast.com*
- // @include http://tangent.jukejuice.com*
- // @include http://*.newcompte.fr*
- // @grant GM_setValue
- // @grant GM_getValue
- // @grant GM_deleteValue
- // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
- // @run-at document-end
- // @author nabby
- // ==/UserScript==
- console.log('START: ' + GM_info.script.name + ' (v' + GM_info.script.version + ' by ' + GM_info.script.author + ')');
- function WhichPageAreWeOn(){
- if (window.location.port) { //In a real game
- return('ingame');
- } else if (document.URL.indexOf('/games/find') > 0) { //Joining page
- return('joining');
- } else if ($('#play').length) { //Chosen server homepage
- return('server');
- } else if (document.URL.indexOf('/profile/') > 0) {
- if ($('#showSettings').length) {
- return('profile'); //Profile page and logged in
- } else {
- return('profileNotOurs'); //Profile page, but not our one (or we're logged out)
- }
- } else if ( ((window.location.host == 'tagpro.koalabeast.com') || (window.location.host == 'tagpro.gg')) && (window.location.pathname === '/') ) { //Choose server homepage
- return('home');
- }
- }
- var PageLoc = WhichPageAreWeOn();
- if (PageLoc === 'server') { //chosen server homepage
- GM_deleteValue('gamesCount');
- //$('#play').parent('div').prepend('<a id="playX" class="button" href="/games/find">Play X<span>pls</span></a>');
- $('#play').click(function(e) {
- e.preventDefault();
- e.stopPropagation();
- e.stopImmediatePropagation();
- var response = prompt("How many games do you want to play?");
- if (response !== null) { //cancel was not clicked
- if ($.isNumeric(response)) {
- GM_setValue('gamesCount', parseInt(response));
- window.location.href = "/games/find";
- } else { //enter or invalid was typed - just continue with no limit...
- GM_setValue('gamesCount', 'unlimited');
- window.location.href = "/games/find";
- }
- }
- });
- }
- if (PageLoc === 'joining') { //joiner
- $('#message').after('<div style="text-align:center; font-size:20px; color:#ff0; background:#b0b; border-radius:5px">Games Remaining: ' + GM_getValue('gamesCount') + '</div>');
- }
- tagpro.ready(function() {
- if (PageLoc === 'ingame') { //in a game
- tagpro.socket.on('settings', function(data) {
- if (!tagpro.spectator) {
- $('#exit').after('<div style="margin:10px 0 0 5px; font-size:10px; color:#ff0">Games Remaining: <span id="playX_Message">' + (GM_getValue('gamesCount') === 1 ? 'None! (last game!)' : ($.isNumeric(GM_getValue('gamesCount')) ? (GM_getValue('gamesCount')-1) + ' (after this one)' : 'Unlimited!')) + '</span></div>');
- }
- });
- tagpro.socket.on('end', function(data) {
- if (!tagpro.spectator) {
- if ($.isNumeric(GM_getValue('gamesCount'))) {
- var gamesCount = GM_getValue('gamesCount') - 1;
- GM_setValue('gamesCount', gamesCount);
- if (gamesCount <= 0) {
- var counter = 10;
- var redirectHandle = setInterval(function() {
- $('#playX_Message').html('None! (Quitting in '+(counter-1)+' Seconds)...').css('background', '#f00');
- if (counter > 0) {
- counter--;
- } else {
- clearInterval(redirectHandle);
- window.close();
- window.location.href = 'http://' + tagpro.serverHost; //just in case .close() doens't work
- }
- }, 1000);
- } else {
- $('#playX_Message').html(gamesCount + ' more to play...');
- }
- }
- }
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment