SHOW:
|
|
- or go back to the newest paste.
1 | - | var teamList = ["2hug","aceg","agdg","alg","civ4xg","d2g","dbg","ddlc","digi","domg","dng","drag","drg","egg","feg","fgoalter","fgog","gbfg","gbpen","gfg","gsg","hanny","hpgg","hsg","indie","ink","kfg","llsifg","lzg","mbg","mggg","mjg","nepgen","osg","pmmm","r6g", "revue", "rsg","skg","ssbg","tekgen","tf2g","tnm","utg","vitagen","vn","vrg","wtg","きらら"]; |
1 | + | var TeamLists = {}; |
2 | - | $('#vidchatcontrols').append("<span>Team Color: <select id='teamcolor' style='color:white;background:none;border-radius:5px;width:75px;padding:6px;'><option></option></select></span>"); |
2 | + | var AllTeams = {}; |
3 | var CurrentTeamList = null; | |
4 | - | for(var i =0, len = teamList.length; i< len; i++){ |
4 | + | var CurrentTeamListName; |
5 | - | if (teamList[i] == '@'){ |
5 | + | var defaultIconSrc = "https://implyingrigged.info/w/images/d/df/Vglg_icon.png"; |
6 | - | $('#teamcolor').append('<option value="imas">/@/</option>'); |
6 | + | var scrollingToTeam = false; |
7 | - | } else { |
7 | + | |
8 | - | $('#teamcolor').append('<option value="' + teamList[i] + '">/' + teamList[i] + '/</option>'); |
8 | + | function setTeamList(teamList){ |
9 | var teamListName = ""; | |
10 | if(typeof(teamList) === 'string'){ | |
11 | teamListName = teamList; | |
12 | teamList = TeamLists[teamList]; | |
13 | } | |
14 | ||
15 | if(teamList === CurrentTeamList) | |
16 | return; | |
17 | ||
18 | if(typeof(UserCustomTeamList) !== 'undefined') | |
19 | teamList = teamList.concat(UserCustomTeamList); | |
20 | ||
21 | var tmpTeamsCssLines = [ '<style type="text/css" id="iconcss_tmp">' ]; | |
22 | var selector = $('#teamcolor'); | |
23 | selector.html('<option></option>'); | |
24 | selector.removeClass("teamlist_" + CurrentTeamListName); | |
25 | selector.addClass("teamlist_" + teamListName); | |
26 | $("#messagebuffer").removeClass("teamlist_" + CurrentTeamListName); | |
27 | $("#messagebuffer").addClass("teamlist_" + teamListName); | |
28 | ||
29 | var newSelector = $("#selectteam ul"); | |
30 | newSelector.html('<li tabindex="0" data-val=""><img src="' + defaultIconSrc + '"></li>'); | |
31 | ||
32 | var selectedColorInList = false; | |
33 | var addOption = function(teamObj){ | |
34 | if(!teamObj.ExclusiveTo || teamObj.ExclusiveTo == CLIENT.name){ | |
35 | selector.append('<option value="' + teamObj.id + '">' + teamObj.name + '</option>'); | |
36 | newSelector.append('<li tabindex="0" data-val="' + teamObj.id + '"><img src="' + teamObj.icon + '"><p>' + teamObj.name + '</p></li>'); | |
37 | ||
38 | selectedColorInList = selectedColorInList || teamObj.id === TEAMCOLOR; | |
39 | } | |
40 | }; | |
41 | teamList.forEach(function(team){ | |
42 | if(typeof(team) === 'string' && AllTeams.hasOwnProperty(team)){ | |
43 | addOption(AllTeams[team]); | |
44 | } | |
45 | else if(typeof(team) === 'object'){ | |
46 | if(!AllTeams.hasOwnProperty(team.id)){ | |
47 | InitTeam(team); | |
48 | tmpTeamsCssLines.push(team.css); | |
49 | } | |
50 | addOption(team); | |
51 | } | |
52 | ||
53 | }); | |
54 | ||
55 | if (tmpTeamsCssLines.length > 1){ | |
56 | tmpTeamsCssLines.push('</style>'); | |
57 | $('#iconcss_tmp').remove(); | |
58 | $(document.head).append(tmpTeamsCssLines.join('\n')); | |
59 | } | |
60 | ||
61 | if(selectedColorInList){ | |
62 | selector.val(TEAMCOLOR); | |
63 | $("#selectteam li[data-val='"+TEAMCOLOR+"']").click(); | |
64 | } | |
65 | else{ | |
66 | selector.val(""); | |
67 | $("#selectteam li:first").click(); | |
68 | } | |
69 | ||
70 | CurrentTeamList = teamList; | |
71 | CurrentTeamListName = teamListName; | |
72 | }; | |
73 | ||
74 | function InitTeamLists(){ | |
75 | var cssLines = [ | |
76 | '<style type="text/css" id="iconcss">' | |
77 | ]; | |
78 | Object.keys(TeamLists).forEach(function(key){ | |
79 | var list = TeamLists[key]; | |
80 | cssLines.push("\n/* " + key + " */"); | |
81 | list.forEach(function(team){ | |
82 | if(typeof(team) === 'object'){ | |
83 | InitTeam(team); | |
84 | cssLines.push(team.css); | |
85 | } | |
86 | }); | |
87 | }); | |
88 | cssLines.push('</style>'); | |
89 | ||
90 | var css = cssLines.join('\n'); | |
91 | ||
92 | $("#iconcss").remove(); | |
93 | $(document.head).append(css); | |
94 | ||
95 | $("#selectteam").remove(); | |
96 | $("#chatline2").remove(); | |
97 | $('<textarea class="form-control" id="chatline2" rows="1"></textarea>').insertAfter('#chatline'); | |
98 | var dropup = $('<span class="dropup"></span>'); | |
99 | var selectteam = $('<div id="selectteam"></div>').insertBefore('#chatline').append(dropup); | |
100 | dropup.append('<img class="dropdown-toggle" data-toggle="dropdown" title="Team Icon">'); | |
101 | dropup.on('shown.bs.dropdown', function(){ | |
102 | var elm = $('#selectteam li[data-val="'+TEAMCOLOR+'"]'); | |
103 | if(elm && elm[0]){ | |
104 | elm[0].parentNode.scrollTop = elm[0].offsetTop; | |
105 | elm[0].focus({preventScroll:true}); | |
106 | } | |
107 | }); | |
108 | var iconsPerRow = 11; | |
109 | $('<ul class="dropdown-menu"></ul>').appendTo(dropup) | |
110 | .on("click", "li", function(){ | |
111 | TEAMCOLOR = this.dataset.val; | |
112 | setOpt(CHANNEL.name + "_TEAMCOLOR", TEAMCOLOR); | |
113 | if(TEAMCOLOR) | |
114 | $("#selectteam>span>img").attr("src", AllTeams[TEAMCOLOR].icon); | |
115 | else | |
116 | $("#selectteam>span>img").attr("src", defaultIconSrc); | |
117 | }).on("mouseover", "li", function(){ | |
118 | if(!scrollingToTeam) | |
119 | this.focus({preventScroll:true}); | |
120 | scrollingToTeam = false; | |
121 | }).on("keydown", function(event){ | |
122 | var selected = $(document.activeElement); | |
123 | var elm = null; | |
124 | switch (event.key){ | |
125 | case 'ArrowUp': case 'Up': | |
126 | if(selectteam.hasClass('grid')) { | |
127 | var length = selected.siblings().length; | |
128 | var iconsInLastRow = length % iconsPerRow; | |
129 | var indexAbove = selected.index() - iconsPerRow; | |
130 | if(iconsInLastRow != 0 && selected.index() >= (Math.floor(length / iconsPerRow) * iconsPerRow)) | |
131 | indexAbove += Math.floor((iconsPerRow - iconsInLastRow) / 2); | |
132 | if(indexAbove >= 0) | |
133 | elm = $(selected.parent().children()[indexAbove]); | |
134 | } else | |
135 | elm = selected.prev(); | |
136 | break; | |
137 | case 'ArrowDown': case 'Down': | |
138 | if(selectteam.hasClass('grid')) { | |
139 | var length = selected.siblings().length; | |
140 | var iconsInLastRow = length % iconsPerRow; | |
141 | var indexBelow = selected.index() + iconsPerRow; | |
142 | if(iconsInLastRow != 0 && indexBelow >= (Math.floor(length / iconsPerRow) * iconsPerRow)) { | |
143 | var lastRowAdjustment = Math.floor((iconsPerRow - iconsInLastRow) / 2); | |
144 | var indexInLastRow = indexBelow % iconsPerRow; | |
145 | if(indexInLastRow >= lastRowAdjustment) | |
146 | elm = $(selected.parent().children()[indexBelow - lastRowAdjustment]); | |
147 | } else if(indexBelow < selected.siblings().length) | |
148 | elm = $(selected.parent().children()[indexBelow]); | |
149 | } else | |
150 | elm = selected.next(); | |
151 | break; | |
152 | case 'ArrowLeft': case 'Left': | |
153 | if(selectteam.hasClass('grid') && selected.index() % iconsPerRow != 0) | |
154 | elm = selected.prev(); | |
155 | break; | |
156 | case 'ArrowRight': case 'Right': | |
157 | if(selectteam.hasClass('grid') && (selected.index()+1) % iconsPerRow != 0) | |
158 | elm = selected.next(); | |
159 | break; | |
160 | case 'Tab': | |
161 | elm = event.shiftKey ? selected.prev() : selected.next(); | |
162 | break; | |
163 | case 'Backspace': case 'Delete': | |
164 | elm = $('#selectteam li:first-child'); | |
165 | break; | |
166 | case 'Enter': | |
167 | event.stopPropagation(); | |
168 | if(selected.parentsUntil('#selectteam').length) | |
169 | selected.click(); | |
170 | break; | |
171 | case 'Escape': | |
172 | event.stopPropagation(); | |
173 | selectteam.children('.dropdown-toggle').click(); | |
174 | break; | |
175 | default: | |
176 | if(event.key.length == 1){ | |
177 | var itemSel = 'li[data-val^="'+event.key.toLowerCase()+'"]'; | |
178 | elm = $('#selectteam li:focus~'+itemSel).first(); | |
179 | if(!elm.length) elm = $('#selectteam '+itemSel).first(); | |
180 | } | |
181 | break; | |
182 | } | |
183 | if(elm && elm[0]){ | |
184 | event.stopPropagation(); | |
185 | event.preventDefault(); | |
186 | var liRect = elm[0].getBoundingClientRect(); | |
187 | var ulRect = elm.parent()[0].getBoundingClientRect(); | |
188 | if(liRect.top < ulRect.top || liRect.bottom > ulRect.bottom){ | |
189 | scrollingToTeam = true; | |
190 | elm[0].parentNode.scrollTop = elm[0].offsetTop; | |
191 | } | |
192 | elm[0].focus({preventScroll:true}); | |
193 | } | |
194 | }); | |
195 | ||
196 | } | |
197 | ||
198 | function InitTeam(team) { | |
199 | if(team.icon.startsWith("/")){ | |
200 | team.icon = "https://implyingrigged.info" + team.icon; | |
201 | } | |
202 | if(!team.hasOwnProperty('name')){ | |
203 | team.name = '/' + team.id + '/'; | |
204 | } | |
205 | ||
206 | var cssSel = (team.ExclusiveTo ? ".chat-msg-" + team.ExclusiveTo + " ": "") + ".team" + team.id; | |
207 | team.css = cssSel+"{ color:"+team.color+"!important;} "+cssSel+"::before{ background-image:url('"+team.icon+"');}"; | |
208 | ||
209 | if(!AllTeams.hasOwnProperty(team.id)) | |
210 | AllTeams[team.id] = team; | |
211 | } | |
212 | ||
213 | var TeamLists = { | |
214 | "4cc":[ | |
215 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
216 | {id:"2hug", color:"#7FAC75",icon:"/w/images/thumb/3/34/2hug_icon.png/25px-2hug_icon.png"}, | |
217 | {id:"aceg", color:"#CE5200",icon:"/w/images/thumb/e/e5/Aceg_icon.png/25px-Aceg_icon.png"}, | |
218 | {id:"agdg", color:"#000000",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
219 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
220 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
221 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
222 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
223 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
224 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
225 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
226 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
227 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
228 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
229 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
230 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
231 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
232 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
233 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
234 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
235 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
236 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
237 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
238 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
239 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
240 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
241 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
242 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
243 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
244 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
245 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
246 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
247 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
248 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
249 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
250 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
251 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
252 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
253 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
254 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
255 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
256 | {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"}, | |
257 | ||
258 | ] | |
259 | /* when somebody makes an invitational and the teams are all in a neat multi-column list on the page, | |
260 | inspect element > right-click > store as global variable > then in the console (edit as needed): | |
261 | [].slice.call(temp1.querySelectorAll('li')).map(function(li){ return { id:li.querySelector('b a').innerHTML.replace('/', '').replace('/', ''), color:'#999999', icon:li.querySelector('img').getAttribute('src') }; }) | |
262 | */ | |
263 | }; | |
264 | ||
265 | InitTeamLists(); | |
266 | ||
267 | if(getOrDefault(CHANNEL.name + "_SELECTTEAM_GRID", false)) | |
268 | $('#toggleTeamSelStyle').click(); | |
269 | var TEAMCOLOR = getOrDefault(CHANNEL.name + "_TEAMCOLOR", ''); | |
270 | setTeamList("4cc"); | |
271 | if (TEAMCOLOR){ | |
272 | $('#teamcolor').val(TEAMCOLOR); | |
273 | $("#selectteam>span>img").attr("src", AllTeams[TEAMCOLOR].icon); | |
274 | } | |
275 | else{ | |
276 | $("#selectteam>span>img").attr("src", defaultIconSrc); | |
277 | } | |
278 | $('#teamcolor').change(function(){ | |
279 | TEAMCOLOR = $(this).val(); | |
280 | setOpt(CHANNEL.name + "_TEAMCOLOR", TEAMCOLOR); | |
281 | }); | |
282 | ||
283 | //Format messages upon page load because they're handled differently and I can't find the function | |
284 | $('.teamColorSpan').each(function(){ | |
285 | var color = $(this).text().replace(new RegExp('-','g'),''); | |
286 | $(this).parent().parent().find('.username').addClass(color); | |
287 | }); |