// ==UserScript== // @name Tidy up your Dashboard // @namespace https://greasyfork.org/users/10154 // @grant none // @match https://www.warlight.net/* // @description Customizable Userscript which tidies up your Dashboard! // @version 1.9.5.10 // @icon http://i.imgur.com/XzA5qMO.png /*jslint browser: true, regexp: true*/ /*global $, jQuery*/ // @downloadURL none // ==/UserScript== var version = "1.9.5.10"; function checkVersion() { var currentVersion = localStorage.getItem('version'); if (currentVersion == version) { //Script Up to date } else if (currentVersion == undefined) { //Script new installed $(".userscript-show").fadeIn(); $(".overlay").fadeIn(); } else { //Script Updated // $("label[for='hidePromotedGames']").addClass('newSetting'); // $("label[for='hideCoinsGlobally']").addClass('newSetting'); // $(".userscript-show").fadeIn(); // $(".overlay").fadeIn(); } localStorage.setItem('version', version); } var lastRefresh; var delayedFunction; var myGamesTable = $("#MyGamesTable"); var openGamesTable = $("#OpenGamesTable"); var promotedGamesTable = $("#PromotedGamesTable"); var lastClick = new Date(); var openGamesFilters; var userscriptSettings = [ {id: 'scrollGames', text: 'Fixed Window with scrollable Games', selected: false, title: 'Dashboard', addBreak: false}, {id: 'hideMyGamesIcons', text: 'Hide Icons in "My Games"', selected: false, title: '', addBreak: false}, {id: 'autoRefreshOnFocus', text: 'Automatically refresh Games on Tab-Focus', selected: false, title: '', addBreak: false}, {id: 'highlightTournaments', text: 'Highlight Tournament invites', selected: false, title: '', addBreak: false}, {id: 'highlightNewForumPosts', text: 'Highlight new Clan Posts', selected: false, title: '', addBreak: false}, {id: 'hideRightColumn', text: 'Hide Right Column', selected: false, title: '', addBreak: false}, {id: 'showOpenGamesFilter', text: 'Enable Open Games Filter', selected: false, title: '', addBreak: false}, {id: 'hidePromotedGames', text: 'Hide Promoted Games', selected: false, title: '', addBreak: false}, {id: 'useDefaultBootLabel', text: 'Use the Default Boot Time Label', selected: false, title: '', addBreak: false}, {id: 'showOpenGamesTab', text: 'Show Open Games Tab in Menu Bar', selected: false, title: 'Global', addBreak: false}, {id: 'hideCoinsGlobally', text: 'Hide Coins Globally', selected: false, title: '', addBreak: false} ]; var showGamesActive = "ShowMyGames"; //Expand Games Buttons var showAllGames = ""; var showAllCoinGames = ""; var openGames = []; readLocalstorage(); setGlobalStyles(); setupUserscriptMenu(); checkVersion(); $.fn.settingIsEnabled = function (setting) { var selected = false; $.each(userscriptSettings, function (key, set) { if (set.id == setting) { selected = set.selected; } }); return selected; }; if (pageIsMultiplayer()) { //Show Open Games Link if (isEnabled('showOpenGamesTab')) { showOpenGamesLink(); } } if (pageIsDashboard()) { setupRefreshFunction(); expandGames(); markJoinedGames(); hideBlacklistedThreads(); setupBasicDashboardStyles(); if (isEnabled('showOpenGamesFilter')) { setupOpenGamesFilter(); } if (isEnabled('highlightTournaments')) { createSelector("#MyTournamentsTable tbody", "background:#4C4C33;"); } if (isEnabled('hidePromotedGames') || isEnabled('hideCoinsGlobally')) { createSelector("#PromotedGamesTable", "display:none"); } if (isEnabled('hideMyGamesIcons')) { createSelector("#MyGamesTable td div img, #MyGamesTable td div a img", "display:none;"); } if (isEnabled('highlightNewForumPosts')) { hightlightNewClanForumPosts(); } if (isEnabled('scrollGames')) { setupFixedWindowWithScrollableGames(); } if (isEnabled('hideRightColumn')) { hideRightColumn(); } $("label[for='MultiDayRadio']").on("click", function () { registerGameTabClick() }); $("label[for='RealTimeRadio']").on("click", function () { registerGameTabClick() }); $("label[for='BothRadio']").on("click", function () { registerGameTabClick() }); $(window).resize(function () { if (isEnabled('scrollGames')) { refreshSingleColumnSize(); } }); } if (pageIsClanThread()) { registerClanThread(); } /** * Globally Hide Coins */ if (isEnabled('hideCoinsGlobally')) { $("#CoinsBtn").parent().next().css('left', 512); $("#CoinsBtn").parent().next().next().css('left', 635); $("#CoinsBtn").parent().next().next().next().css('left', 740); $("#LeaderboardTable").prev().remove(); $("#LeaderboardTable").css({opacity:0, cursor:'default'}); $("#LeaderboardTable a").css('display', 'none'); $(".TopRightBar").find("a[href='/Coins/']").css('display', 'none'); $(".dropdown-menu a[href='/Coins/']").parent().remove() $("a[href='/Win-Money']").css('display', 'none'); $("#OpenTournamentsTable").css('display', 'none'); } /** * Reads the User-Settings from Localstorage */ function readLocalstorage() { //Settings $.each(userscriptSettings, function (key, setting) { setting.selected = localStorage.getItem(setting.id) == "true"; }); //Filters var filters = localStorage.getItem("openGamesFilters"); if (filters) { openGamesFilters = $.parseJSON(filters); } else { openGamesFilters = {}; } hideCoinSymbol = true; } /** * Creates the Userscript-Menu */ function setupUserscriptMenu() { var inputs = ''; $.each(userscriptSettings, function (key, setting) { if (setting.title != '') { inputs += '' + setting.title + '
'; } inputs += '
'; if (setting.addBreak) { inputs += '
'; } }); inputs += '
Close and Refresh
'; $("body").append(""); $(".userscript-show").on("change", function () { storeSettingsVariables(); }); $("#TopRightDropDown .dropdown-divider").before('
  • Userscript
  • '); $(".userscript-menu").on("click", function () { $(".userscript-show").fadeIn(); $(".overlay").fadeIn(); $("#TopRightDropDown").fadeOut(); $("embed#main").attr('wmode', 'transparent'); $("embed#main").css('opacity', '0'); $("embed#main").attr('align', 'left'); }); $(".close-userscript").on("click", function () { $(".userscript-show").fadeOut(); $(".overlay").fadeOut(); location.reload(); }); $(".close-popup-img").on("click", function () { $(".userscript-show").fadeOut(); $(".overlay").fadeOut(); $("embed#main").css('opacity', '1'); }); checkUserscriptMenuButtons(); } function checkUserscriptMenuButtons() { $.each(userscriptSettings, function (key, setting) { $("#"+setting.id).prop("checked", setting.selected); }); } function StickyTitles(stickies) { var thisObj = this; thisObj.load = function () { stickies.each(function () { var thisSticky = $(this).wrap('
    '); thisSticky.parent().height(thisSticky.outerHeight()); var pos = parseInt(thisSticky.offset().top, 10) - parseInt($(".showSide").offset().top, 10); $.data(thisSticky[0], 'pos', pos); }); $(".showSide").off("scroll.stickies").on("scroll.stickies", function () { thisObj.scroll(); }); }; thisObj.scroll = function () { stickies.each(function (i) { var thisSticky = $(this), nextSticky = stickies.eq(i + 1), prevSticky = stickies.eq(i - 1), pos = $.data(thisSticky[0], 'pos'); var showSide = $(".showSide"); if (pos <= showSide.scrollTop()) { thisSticky.addClass("fixed"); if (nextSticky.length > 0 && thisSticky.offset().top >= $.data(nextSticky[0], 'pos') - thisSticky.outerHeight()) { thisSticky.addClass("absolute").css("top", jQuery.data(nextSticky[0], 'pos') - thisSticky.outerHeight()); } } else { thisSticky.removeClass("fixed"); if (prevSticky.length > 0 && showSide.scrollTop() <= $.data(thisSticky[0], 'pos') - prevSticky.outerHeight()) { prevSticky.removeClass("absolute").removeAttr("style"); } } }); } } jQuery.fn.outerHTML = function (s) { return s ? this.before(s).remove() : jQuery("

    ").append(this.eq(0).clone()).html(); }; /** * Triggers a click on the expand Games Button */ function triggerExpandGames() { if (showAllGames == "" || showAllGames.length == 0) { showAllGames = $("#ShowMoreOpenGamesLink"); showAllGames.trigger("click"); } if (showAllCoinGames == "") { showAllCoinGames = $("#ShowMorePromotedGamesLink"); showAllCoinGames.trigger("click"); } } function markJoinedGames() { var gamesSwitch = setInterval(function (){ applyOpenGameFilters(); updateOpenGamesCounter(); var name = $(".TopRightBar a:nth-of-type(2)").text(); var playerLabel = ' You already joined' $.each($("#OpenGamesTable tr"), function (key, tableRow) { $.each($(tableRow).find("span span"), function (key2, player) { if ($(player).attr("title") == name && $(tableRow).html().indexOf("You already joined") < 0) { $(tableRow).find("td:nth-of-type(2) a").append(playerLabel) } }); }) }, 5); setTimeout(function () { clearInterval(gamesSwitch); }, 400) } /** * Delayed function for expanding Games */ function expandGames() { numOfGames = 0; delayedFunction = setInterval(triggerExpandGames, 100); setTimeout(function () { clearInterval(delayedFunction); }, 3000); } /** * Stores User-Settings to local Storage */ function storeSettingsVariables() { $.each(userscriptSettings, function (key, setting) { localStorage.setItem(setting.id, $("#"+setting.id).prop("checked")); }); } /** * Refreshes Width & Height of Columns */ function refreshSingleColumnSize() { var showSide = $(".showSide"); var showGames = $(".showGames"); showSide.scrollTop(0); /** * Sticky Titles */ $(".followMeBar").each(function () { $(this).removeClass("fixed"); if ($(this).parent().hasClass("followWrap")) { $(this).unwrap(); } var thisSticky = $(this).wrap('

    '); thisSticky.parent().height(thisSticky.outerHeight()); var pos = parseInt(thisSticky.offset().top) - parseInt(showSide.offset().top); $.data(thisSticky[0], 'pos', pos); }); var width = $("#ForumTable").width(); createSelector(".followMeBar", "width:" + width + "px;"); showGames.find("table").css({ height: window.innerHeight - 150 }); //var height = showGames.find("table thead tr").height() + 30; var height = 48; createSelector(".showGames table tbody tr:first-of-type td", "padding-top:" + height + "px"); showSide.css({ height: window.innerHeight - 150 }); showGames.find("table tbody tr:first-of-type td").css("padding-top", height); $(".showGames thead tr td div").unwrap(); } /** * Create a CSS selector * @param name The name of the object, which the rules are applied to * @param rules The CSS rules */ function createSelector(name, rules) { var style = document.createElement('style'); style.type = 'text/css'; document.getElementsByTagName('head')[0].appendChild(style); if (!(style.sheet || {}).insertRule) { (style.styleSheet || style.sheet).addRule(name, rules); } else { style.sheet.insertRule(name + "{" + rules + "}", 0); } } /** * Reloads all Games */ function refreshAllGames(force) { if ($(".popup").is(":visible") && !force) { return; } if (isEnabled('scrollGames')) { openGamesTable.scrollTop(0); myGamesTable.scrollTop(0); promotedGamesTable.scrollTop(0); } $('table').css('overflow-y','hidden') myGamesTable.find("tbody").fadeTo('slow', 0.15); openGamesTable.find("tbody").fadeTo('slow', 0.15); promotedGamesTable.find("tbody").fadeTo('slow', 0.15); var page = $('
    ').load('https://www.warlight.net/MultiPlayer/ ', function () { var myGames = page.find('#MyGamesTable tbody tr'); //var openGames = page.find('#OpenGamesTable tbody tr'); var promotedGames = page.find('#PromotedGamesTable tbody tr'); showAllGames = page.find("#ShowMoreOpenGamesLink"); promotedGamesTable.find("tbody tr").remove(); $.each(myGamesTable.find("tbody tr"), function (key, value) { if ($(value).html().indexOf("PastGames") == -1) { $(value).remove(); } }); myGamesTable.find("tbody").prepend(myGames); //$("#OpenGamesTable").find("tbody").prepend(openGames); promotedGamesTable.find("tbody").prepend(promotedGames); $("#MorePromotedGamesHorizontalRow").remove(); $("#ShowMorePromotedGamesLinkContainer").remove(); $.each($(".TournamentRow td"), function () { $(this).find("font:first-of-type").appendTo($(this).find("a")).css("font-size", "10px"); }); myGamesTable.find("tbody").fadeTo('slow', 1, function() { myGamesTable.css('overflow-y','scroll'); }); //openGamesTable.find("tbody").fadeTo('slow', 1); promotedGamesTable.find("tbody").fadeTo('slow', 1, function() { promotedGamesTable.css('overflow-y','scroll'); }); markJoinedGames(); if (isEnabled('scrollGames')) { refreshSingleColumnSize(); } }); var activeTabLoad; var activeTabClass; openGames = []; var active = $("#OpenGamesTable .ui-buttonset .ui-state-active").text(); if (active.indexOf('Both') > -1) { activeTabLoad = ["BothRadio", "RealTimeRadio", "MultiDayRadio"]; activeTabClass = ["bothOpenGames", "realOpenGames", "multiOpenGames"]; } else if (active.indexOf('Real') > -1) { activeTabLoad = ["RealTimeRadio", "MultiDayRadio", "BothRadio"]; activeTabClass = ["realOpenGames", "multiOpenGames", "bothOpenGames"]; } else { activeTabLoad = ["MultiDayRadio", "RealTimeRadio", "BothRadio"]; activeTabClass = ["multiOpenGames", "realOpenGames", "bothOpenGames"]; } $("#iframeiii").remove(); //Reload open games var ifr = $('