Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var TeamLists = {};
- var AllTeams = {};
- var CurrentTeamList = null;
- var CurrentTeamListName;
- var defaultIconSrc = "https://implyingrigged.info/w/images/d/df/Vglg_icon.png";
- var scrollingToTeam = false;
- function setTeamList(teamList){
- var teamListName = "";
- if(typeof(teamList) === 'string'){
- teamListName = teamList;
- teamList = TeamLists[teamList];
- }
- if(teamList === CurrentTeamList)
- return;
- if(typeof(UserCustomTeamList) !== 'undefined')
- teamList = teamList.concat(UserCustomTeamList);
- var tmpTeamsCssLines = [ '<style type="text/css" id="iconcss_tmp">' ];
- var selector = $('#teamcolor');
- selector.html('<option></option>');
- selector.removeClass("teamlist_" + CurrentTeamListName);
- selector.addClass("teamlist_" + teamListName);
- $("#messagebuffer").removeClass("teamlist_" + CurrentTeamListName);
- $("#messagebuffer").addClass("teamlist_" + teamListName);
- var newSelector = $("#selectteam ul");
- newSelector.html('<li tabindex="0" data-val=""><img src="' + defaultIconSrc + '"></li>');
- var selectedColorInList = false;
- var addOption = function(teamObj){
- if(!teamObj.ExclusiveTo || teamObj.ExclusiveTo == CLIENT.name){
- selector.append('<option value="' + teamObj.id + '">' + teamObj.name + '</option>');
- newSelector.append('<li tabindex="0" data-val="' + teamObj.id + '"><img src="' + teamObj.icon + '"><p>' + teamObj.name + '</p></li>');
- selectedColorInList = selectedColorInList || teamObj.id === TEAMCOLOR;
- }
- };
- teamList.forEach(function(team){
- if(typeof(team) === 'string' && AllTeams.hasOwnProperty(team)){
- addOption(AllTeams[team]);
- }
- else if(typeof(team) === 'object'){
- if(!AllTeams.hasOwnProperty(team.id)){
- InitTeam(team);
- tmpTeamsCssLines.push(team.css);
- }
- addOption(team);
- }
- });
- if (tmpTeamsCssLines.length > 1){
- tmpTeamsCssLines.push('</style>');
- $('#iconcss_tmp').remove();
- $(document.head).append(tmpTeamsCssLines.join('\n'));
- }
- if(selectedColorInList){
- selector.val(TEAMCOLOR);
- $("#selectteam li[data-val='"+TEAMCOLOR+"']").click();
- }
- else{
- selector.val("");
- $("#selectteam li:first").click();
- }
- CurrentTeamList = teamList;
- CurrentTeamListName = teamListName;
- };
- function InitTeamLists(){
- var cssLines = [
- '<style type="text/css" id="iconcss">'
- ];
- Object.keys(TeamLists).forEach(function(key){
- var list = TeamLists[key];
- cssLines.push("\n/* " + key + " */");
- list.forEach(function(team){
- if(typeof(team) === 'object'){
- InitTeam(team);
- cssLines.push(team.css);
- }
- });
- });
- cssLines.push('</style>');
- var css = cssLines.join('\n');
- $("#iconcss").remove();
- $(document.head).append(css);
- $("#selectteam").remove();
- $("#chatline2").remove();
- $('<textarea class="form-control" id="chatline2" rows="1"></textarea>').insertAfter('#chatline');
- var dropup = $('<span class="dropup"></span>');
- var selectteam = $('<div id="selectteam"></div>').insertBefore('#chatline').append(dropup);
- dropup.append('<img class="dropdown-toggle" data-toggle="dropdown" title="Team Icon">');
- dropup.on('shown.bs.dropdown', function(){
- var elm = $('#selectteam li[data-val="'+TEAMCOLOR+'"]');
- if(elm && elm[0]){
- elm[0].parentNode.scrollTop = elm[0].offsetTop;
- elm[0].focus({preventScroll:true});
- }
- });
- var iconsPerRow = 11;
- $('<ul class="dropdown-menu"></ul>').appendTo(dropup)
- .on("click", "li", function(){
- TEAMCOLOR = this.dataset.val;
- setOpt(CHANNEL.name + "_TEAMCOLOR", TEAMCOLOR);
- if(TEAMCOLOR)
- $("#selectteam>span>img").attr("src", AllTeams[TEAMCOLOR].icon);
- else
- $("#selectteam>span>img").attr("src", defaultIconSrc);
- }).on("mouseover", "li", function(){
- if(!scrollingToTeam)
- this.focus({preventScroll:true});
- scrollingToTeam = false;
- }).on("keydown", function(event){
- var selected = $(document.activeElement);
- var elm = null;
- switch (event.key){
- case 'ArrowUp': case 'Up':
- if(selectteam.hasClass('grid')) {
- var length = selected.siblings().length;
- var iconsInLastRow = length % iconsPerRow;
- var indexAbove = selected.index() - iconsPerRow;
- if(iconsInLastRow != 0 && selected.index() >= (Math.floor(length / iconsPerRow) * iconsPerRow))
- indexAbove += Math.floor((iconsPerRow - iconsInLastRow) / 2);
- if(indexAbove >= 0)
- elm = $(selected.parent().children()[indexAbove]);
- } else
- elm = selected.prev();
- break;
- case 'ArrowDown': case 'Down':
- if(selectteam.hasClass('grid')) {
- var length = selected.siblings().length;
- var iconsInLastRow = length % iconsPerRow;
- var indexBelow = selected.index() + iconsPerRow;
- if(iconsInLastRow != 0 && indexBelow >= (Math.floor(length / iconsPerRow) * iconsPerRow)) {
- var lastRowAdjustment = Math.floor((iconsPerRow - iconsInLastRow) / 2);
- var indexInLastRow = indexBelow % iconsPerRow;
- if(indexInLastRow >= lastRowAdjustment)
- elm = $(selected.parent().children()[indexBelow - lastRowAdjustment]);
- } else if(indexBelow < selected.siblings().length)
- elm = $(selected.parent().children()[indexBelow]);
- } else
- elm = selected.next();
- break;
- case 'ArrowLeft': case 'Left':
- if(selectteam.hasClass('grid') && selected.index() % iconsPerRow != 0)
- elm = selected.prev();
- break;
- case 'ArrowRight': case 'Right':
- if(selectteam.hasClass('grid') && (selected.index()+1) % iconsPerRow != 0)
- elm = selected.next();
- break;
- case 'Tab':
- elm = event.shiftKey ? selected.prev() : selected.next();
- break;
- case 'Backspace': case 'Delete':
- elm = $('#selectteam li:first-child');
- break;
- case 'Enter':
- event.stopPropagation();
- if(selected.parentsUntil('#selectteam').length)
- selected.click();
- break;
- case 'Escape':
- event.stopPropagation();
- selectteam.children('.dropdown-toggle').click();
- break;
- default:
- if(event.key.length == 1){
- var itemSel = 'li[data-val^="'+event.key.toLowerCase()+'"]';
- elm = $('#selectteam li:focus~'+itemSel).first();
- if(!elm.length) elm = $('#selectteam '+itemSel).first();
- }
- break;
- }
- if(elm && elm[0]){
- event.stopPropagation();
- event.preventDefault();
- var liRect = elm[0].getBoundingClientRect();
- var ulRect = elm.parent()[0].getBoundingClientRect();
- if(liRect.top < ulRect.top || liRect.bottom > ulRect.bottom){
- scrollingToTeam = true;
- elm[0].parentNode.scrollTop = elm[0].offsetTop;
- }
- elm[0].focus({preventScroll:true});
- }
- });
- }
- function InitTeam(team) {
- if(team.icon.startsWith("/")){
- team.icon = "https://implyingrigged.info" + team.icon;
- }
- if(!team.hasOwnProperty('name')){
- team.name = '/' + team.id + '/';
- }
- var cssSel = (team.ExclusiveTo ? ".chat-msg-" + team.ExclusiveTo + " ": "") + ".team" + team.id;
- team.css = cssSel+"{ color:"+team.color+"!important;} "+cssSel+"::before{ background-image:url('"+team.icon+"');}";
- if(!AllTeams.hasOwnProperty(team.id))
- AllTeams[team.id] = team;
- }
- var TeamLists = {
- "4cc":[
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"2hug", color:"#7FAC75",icon:"/w/images/thumb/3/34/2hug_icon.png/25px-2hug_icon.png"},
- {id:"aceg", color:"#CE5200",icon:"/w/images/thumb/e/e5/Aceg_icon.png/25px-Aceg_icon.png"},
- {id:"agdg", color:"#000000",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- {id:"imas", color:"#F20972",icon:"/w/images/thumb/7/7a/%40_icon.png/25px-%40_icon.png"},
- ]
- /* when somebody makes an invitational and the teams are all in a neat multi-column list on the page,
- inspect element > right-click > store as global variable > then in the console (edit as needed):
- [].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') }; })
- */
- };
- InitTeamLists();
- if(getOrDefault(CHANNEL.name + "_SELECTTEAM_GRID", false))
- $('#toggleTeamSelStyle').click();
- var TEAMCOLOR = getOrDefault(CHANNEL.name + "_TEAMCOLOR", '');
- setTeamList("4cc");
- if (TEAMCOLOR){
- $('#teamcolor').val(TEAMCOLOR);
- $("#selectteam>span>img").attr("src", AllTeams[TEAMCOLOR].icon);
- }
- else{
- $("#selectteam>span>img").attr("src", defaultIconSrc);
- }
- $('#teamcolor').change(function(){
- TEAMCOLOR = $(this).val();
- setOpt(CHANNEL.name + "_TEAMCOLOR", TEAMCOLOR);
- });
- //Format messages upon page load because they're handled differently and I can't find the function
- $('.teamColorSpan').each(function(){
- var color = $(this).text().replace(new RegExp('-','g'),'');
- $(this).parent().parent().find('.username').addClass(color);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement