-
Notifications
You must be signed in to change notification settings - Fork 11
/
specmode.user.js
84 lines (71 loc) · 2.62 KB
/
specmode.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// ==UserScript==
// @name Specatator Mode
// @namespace http://reddit.com/u/samwilber
// @updateURL https://github.com/mcgrogan91/TagProScripts/raw/master/specmode.user.js
// @description Never accidentally join a game again
// @include http://tangent.jukejuice.com*
// @include https://tagpro.koalabeast.com*
// @include http://tagpro-*.koalabeast.com*
// @author turtlemansam and help from bizkut's script
// @contributor bizkut
// @contributor OmicroN
// @version 2.3.3
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
function querystring(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)");
var results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
$(document).ready(function(){
if(document.URL.endsWith(".com/") === true || document.URL.endsWith("/?spectator=true") === true ) {
$('#play-now').parent().append("<br/><input type='checkbox' id='tglSpec'> Spectator Mode</input>");
$('#optionsName').append("<input type='checkbox' id='tglSpec'>Spectator Mode</input>");
}
if (GM_getValue("specMode") === true) {
$("#tglSpec").prop('checked', true);
}
$("#tglSpec").on('change', function () {
if ($(this).is(":checked")) {
GM_setValue("specMode", true);
} else {
GM_setValue("specMode", false);
}
});
if (GM_getValue("specMode") === true) {
if(document.URL.search('games/find') >= 0) {
window.location.href = "/";
}
}
var gameloaded, player, intervalFunc;
if (player = querystring('player_id')) {
intervalFunc = function() {
if ( ! $.isEmptyObject(tagpro.players)) {
clearInterval(gameloaded);
tagpro.playerId = player;
}
};
} else if (player = querystring('target')) {
intervalFunc = function() {
if ( ! $.isEmptyObject(tagpro.players)) {
clearInterval(gameloaded);
for (var playerId in tagpro.players) {
if (tagpro.players[playerId].name.toLowerCase() == player.toLowerCase()) {
tagpro.playerId = playerId;
break;
}
}
}
};
}
if (player && intervalFunc) {
tagpro.ready(function() {
gameloaded = setInterval(intervalFunc, 100);
});
}
});