-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathteamspirit.user.js
141 lines (119 loc) · 3.8 KB
/
teamspirit.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// ==UserScript==
// @name Team Spirit!
// @namespace http://tampermonkey.net/
// @version 1.7.4
// @description Actually hate each other for no reason.
// @author Teh Flamin' Taco
// @contributor Mego
// @include *://chat.stackexchange.com/rooms/240/the-nineteenth-byte*
// @run-at document-end
// @grant none
// @updateURL https://rawgit.com/TehFlaminTaco/TacosUserscripts/blob/master/teamspirit.user.js
// ==/UserScript==
/* global $ */
(function() {
'use strict';
function getHref(jEle,d) {
d=d||0
if(d>30)
return ""
return jEle.attr("href") || getHref(jEle.parent(),d+1);
}
setInterval(function() {
$(".username").each((a, b) => {
var jB = $(b);
if($(b).parent(".user-popup").length) {
var href = $(b).parent(".user-popup").children("a");
if (!$(b).find(".stars").length) {
jB.prepend(`<span class='stars vote-count-container'><span class='img vote' style='background-image: url(${($(href).attr("href").match(/\/users\/-?(\d+)/)||["","0"])[1]%2===0 ? 'http://i.imgur.com/6RZ23Ak.png' : 'http://i.imgur.com/6jKoAti.png'}) !important; background-position:0px 0px; background-size:10px 10px !important;'></span></span>`);
}
} else {
if (!jB.find(".stars").length) {
jB.prepend(`<span class='stars vote-count-container'><span class='img vote' style='background-image: url(${(getHref(jB).match(/\/users\/-?(\d+)/)||["","0"])[1]%2===0 ? 'http://i.imgur.com/6RZ23Ak.png' : 'http://i.imgur.com/6jKoAti.png'}) !important; background-position:0px 0px; background-size:10px 10px !important;'></span></span>`);
}
}
});
var cRed = 0;
var cBlue = 0;
$(".votesummary .collapsible").children()
.each(
(a,b)=>{
var links = $(b).find('a');
var jLink = $(links[links.length-1]);
var match = jLink.attr("href").match(/users\/(\d+)/);
if(!match)
return;
if(!jLink.find(".stars").length){
jLink.prepend(`<span class='stars vote-count-container'><span class='img vote' style='background-image: url(${match[1]%2===0 ? 'http://i.imgur.com/6RZ23Ak.png' : 'http://i.imgur.com/6jKoAti.png'}) !important; background-position:0px 0px; background-size:10px 10px !important;'></span></span>`);
}
var votes = $(b).find(".vote-count-container .times").text();
var valid = !$(b).find(".owner-star").length;
if(!valid)
return;
if (votes === "")
votes = 1;
if (match[1] % 2 === 0)
cRed += Number(votes);
else
cBlue += Number(votes);
}
);
var total = cRed + cBlue;
var redPercent = Math.ceil((cRed / total) * 100);
var bluPercent = 100 - redPercent;
$("#scoreholder").attr("title", "Red: " + cRed + ", Blue: " + cBlue);
$("#red_score_text").text(cRed);
$("#blue_score_text").text(cBlue);
$("#redscore").css({
width: `${redPercent}%`
});
$("#bluescore").css({
width: `${bluPercent}%`
});
}, 2000);
$(".chat-input").append('<div id="scoreholder"><div id="redscore" class="scoreholder"></div><div id="bluescore" class="scoreholder"></div></div>');
$("#chat-buttons").append(`<div id="scores"><span id="red_score_text">?</span>/<span id="blue_score_text">?</span></div>`);
$("head").append(`<style>
#scoreholder{
height:3px;
padding:1px;
background-color:#000;
}
#redscore{
background-color:#F00;
width:50%;
}
.scoreholder{
height:3px;
float:left;
transition:all linear 1s;
}
#bluescore{
background-color:#00F;
width:50%;
}
#scores{
position:absolute;
background-color:#FFFFFF;
border-radius:8px;
padding: 0px 8px;
font-size:16pt;
font-family:Century Gothic;
overflow:hidden;
transition: all linear 0.5s;
text-align:center;
}
#red_score_text{
color:#F00;
}
#blue_score_text{
color:#00F;
}
.signature{
width:15% !important;
}
.messages{
width:82% !important;
}
</style>`);
})();