// ==UserScript==
// @name Tidy up your Dashboard
// @namespace https://greasyfork.org/users/10154
// @grant none
// @run-at document-start
// @match https://www.warlight.net/*
// @description Customizable Userscript which tidies up your Dashboard!
// @version 1.14.7
// @icon http://i.imgur.com/XzA5qMO.png
// @require https://code.jquery.com/jquery-1.11.2.min.js
// @require https://code.jquery.com/ui/1.11.3/jquery-ui.min.js
// @require https://cdn.bootcss.com/datatables/1.10.10/js/jquery.dataTables.min.js
// @require https://cdn.bootcss.com/datatables/1.10.10/js/dataTables.bootstrap.js
// @require https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js
// @downloadURL none
// ==/UserScript==
window.timeUserscriptStart = new Date().getTime();
var version = "1.14.7";
this.$$$ = jQuery.noConflict(true);
var logData = "";
function log(entry) {
var time = moment(new Date()).format('h:mm:ss');
logData += `\n${time} | ${entry}`;
}
function logError(entry) {
var time = moment(new Date()).format('h:mm:ss');
logData += `\n${time} | ${entry}`;
}
//ctrl+shift+2
$$$(document).keydown(function(e){
if( e.which === 50 && e.ctrlKey && e.shiftKey ){
getLog()
}
});
window.logDialog = undefined;
window.getLog = function() {
if(logDialog) {
logDialog.html(``)
logDialog.dialog('open')
} else {
logDialog = $$$(`
`).dialog({
width: 800,
title: "Userscript log",
height: 400});
}
}
window.onerror = windowError
function windowError(message, source, lineno, colno, error) {
logError(`Error on line ${lineno} col ${colno} in ${source}`)
logError(`${JSON.stringify(error)} ${message}`)
if(typeof $().dialog == "function") {
window.wlerror(message, source, lineno, colno, error)
}
}
if(pageIsDashboard()) {
createSelector("#MainSiteWrapper", "display: none")
createSelector("body", "overflow: hidden")
}
document.addEventListener("DOMContentLoaded", DOM_ContentReady);
function checkVersion() {
Database.readIndex(Database.Table.Settings, Database.Row.Settings.Name, "version", function(v) {
var currentVersion = v != undefined ? v.value: undefined
log("Current version " + currentVersion)
if (currentVersion == version) {
//Script Up to date
} else if (currentVersion == undefined) {
//Script new installed
addDefaultBookmark();
setupSettingsDatabase();
} else {
setUserInvalid()
//Script Updated
//$("label[for='showPrivateNotesOnProfile']").addClass('newSetting');
//showPopup(".userscript-show");
// window.setTimeout(function() {
// warlight_shared_viewmodels_AlertVM.DoPopup("Tidy up Your Dashboard was sucessfully updated to version " + version + "! Check out the forum thread to see what changed.");
// }, 1000)
}
addVersionLabel()
if(sessionStorage.getItem("showUserscriptMenu")) {
showUserscriptMenu();
sessionStorage.removeItem("showUserscriptMenu")
}
})
Database.update(Database.Table.Settings, {name: "version", value: version}, undefined, function() {
})
}
setupImages();
window.userscriptSettings = [
{
id: 'scrollGames',
text: 'Fixed Window with scrollable Games',
selected: true,
title: 'Dashboard',
addBreak: false,
help: 'This Option displays My-, Open-, Coin-Games in a scrollable box, which removes lots of unesessary scrolling. You can find tabs to switch between the different type of games. '
},
{
id: 'hideMyGamesIcons',
text: 'Hide Icons in "My Games"',
selected: false,
title: '',
addBreak: false,
help: 'This Option hides Game-Icons like ( , , etc) in "My Games"'
},
{
id: 'autoRefreshOnFocus',
text: 'Automatically refresh Games on Tab-Focus',
selected: true,
title: '',
addBreak: false,
help: 'This Option automatically refreshes your Games after switching back to Warlight from a different tab / program. This only applies if Warlight was idle for 30 or more seconds.'
},
{
id: 'highlightTournaments',
text: 'Highlight Tournament invites',
selected: false,
title: '',
addBreak: false,
},
{
id: 'hideRightColumn',
text: 'Hide Right Column',
selected: false,
title: '',
addBreak: false,
help: 'This Option hides the right column completely and leaves you alone with My-, Open- and Coin-Games.'
},
{
id: 'hidePromotedGames',
text: 'Hide Promoted Games',
selected: false,
title: '',
addBreak: false,
help: 'This Option hides the Promoted Games on the Dashboard'
},
{
id: 'showOpenGamesTab',
text: 'Show Open Games Tab in Menu Bar',
selected: false,
title: 'Global',
addBreak: false,
help: 'This Option displays a link to the "Open Games" site right next to the "Past Games" Link.'
},
{
id: 'hideCoinsGlobally',
text: 'Hide Coins Globally',
selected: false,
title: '',
addBreak: false,
help: 'This Option removes everything from Warlight related to Coins'
},
{
id: 'showPrivateNotesOnProfile',
text: 'Show Private Notes on Profile',
selected: true,
title: '',
addBreak: false,
help: 'This Option will show you your Private Notes which you made on a player directly on their Profile page. You can find them on the left side under the profile picture.'
},
{
id: 'unlinkDashboard',
text: 'Link Dashboard to "old" My-Games Site',
selected: false,
title: '',
addBreak: false,
help: 'This Option links the Dashboard to the "old" My-Games Site'
},
{
id: 'useDefaultBootLabel',
text: 'Use the Default Boot Time Label',
selected: false,
title: 'Advanced',
addBreak: false
},
{
id: 'hideRefreshButton',
text: 'Hide Refresh Button',
selected: false,
title: '',
addBreak: false,
help: 'Hide the Refresh Button. You can still refresh with R'
},
{
id: 'hideOffTopic',
text: 'Automatically hide Off-topic threads',
selected: false,
title: '',
addBreak: false,
help: 'This Option automatically hides all Off-topic threads everytime you visit the "All Forum Posts"-Page'
},
{
id: 'disableHideThreadOnDashboard',
text: 'Disable right-click on the Forum Table',
selected: false,
title: '',
addBreak: false,
help: 'This Option will allow you right-click Forum Thread on the Dashboard and use the Default Options.'
},
{
id: 'hideCreateRandomGameForm',
text: 'Hide Randomized Bonuses Game Form',
selected: false,
title: '',
addBreak: false,
help: 'This Option will hide the Randomized Bonuses Game Form which is located on the Profile Page.'
},
{
id: 'burningHot',
text: 'Disable burning words',
selected: false,
title: '',
addBreak: false,
help: 'Certain words will receive a flame affect.'
},
{
id: 'showSnow',
text: 'Show Snow',
selected: false,
title: '',
addBreak: false,
help: 'Shows the snow animation on all sites'
},
{
id: 'snowLight',
text: 'Reduce the number of Snowflakes',
selected: false,
title: '',
addBreak: false,
help: 'Reduce the number of Snowflakes for a better performance'
}
];
window.filters = [
{
id: "disableAll",
text: "Disable All Filters",
selected: false,
type: "checkbox"
},
{
id: "",
text: "
");
} else {
//Render MyGames
for (var f = 0; f < myGames.length;) {
var g = myGames[f];
++f;
g = (new warlight_shared_viewmodels_main_MyGamesGameVM).Init(warlight_shared_viewmodels_ConfigurationVM.Settings, 0, g, warlight_shared_viewmodels_SignIn.get_CurrentPlayer());
d.append(warlight_shared_viewmodels_main_MultiPlayerDashboardVM.RenderGameHtml(warlight_shared_viewmodels_ConfigurationVM.Settings, g, null) + "
Hallo
")
}
//Setup time left in GameRow
if(sortType != 1) {
$.each(dueGames, function(key, game) {
var id = game.GameID
var timeLeft = Math.min(game.AutoBoot._totalMilliseconds, game.VoteToBoot._totalMilliseconds, game.DirectBoot._totalMilliseconds) - game.WaitingFor._totalMilliseconds
var bootTime = new Date().getTime() + parseInt(timeLeft)
$("[gameid='" + id + "']").find("td div + span").append(` (${getTimeLeft(timeLeft)} left)`)
})
}
//Setup time left tooltip
$.each(myGames, function(key, game) {
var id = game.GameID
var timeLeft = Math.min(game.AutoBoot._totalMilliseconds, game.VoteToBoot._totalMilliseconds, game.DirectBoot._totalMilliseconds) - game.WaitingFor._totalMilliseconds;
var bootTime = new Date().getTime() + parseInt(timeLeft)
var label = $("[gameid='" + id + "']").find(".BootTimeLabel")
label.attr("title", getTimeLeft(timeLeft, true) + " left")
label.tooltip({ show: {delay: 100}, hide: 100 });
label.attr("data-boottime", bootTime)
})
//Setup NextGameId
var nextGameIds = [];
$.each(myGames, function(key, game) {
var id = game.GameID
if(gameCanBeNextGame(game)){
nextGameIds.push(id)
}
})
$.each(myGames, function(key, game) {
var id = game.GameID
if(nextGameIds.length > 0 && nextGameIds[0]) {
var ids = [];
var url = "https://www.warlight.net/MultiPlayer?GameID=" + id + (nextGameIds.length > 1 ? ("&NextGameIDs=" + nextGameIds.slice(1, nextGameIds.length).join()) : "");
$("[gameid='" + id + "'] td > a").attr("href", url)
nextGameIds.push(nextGameIds.shift())
}
})
}
myGamesTable.find("tbody").fadeTo('fast', 1, function () {
myGamesTable.css('overflow-y', 'scroll');
});
$(window).trigger('resize');
}
function removeMyGames() {
d = $("#MyGamesTable").children("tbody");
d.children().remove();
}
function setMyGamesTimeLeft() {
$.each($("[data-boottime]"), function(key, target) {
var timeLeft = $(target).attr("data-boottime") - new Date().getTime()
if($(target).is("[data-inline]")) {
$(target).text(` (${getTimeLeft(timeLeft)} left)`)
} else {
$(target).tooltip( "option", "content", getTimeLeft(timeLeft, true) + " left")
}
})
}
function getTimeLeft(time, detailed) {
var hours1 = 1 * 60 * 60 * 1000
var hours5 = 5 * 60 * 60 * 1000
var days5 = 5 * 25 * 60 * 60 * 1000
var secs = time / 1000
var mins = secs / 60
var hours = mins / 60
var days = hours / 24
if(time < 0) {
return "Hurry up! No time"
} else if(time < hours1) {
var m = Math.round(Math.floor(mins) % 60);
var s = Math.round(Math.floor(secs) % 60);
return m > 0 ? (m + (m == 1 ? " minute " : " minutes ")) : "" + s + (s == 1 ? " second" : " seconds")
} else if(time < hours5) {
var m = Math.round(Math.floor(mins) % 60)
var h = Math.floor(hours);
return h + (h == 1 ? " hour " : " hours ") + m + (m == 1 ? " minute" : " minutes")
} else if(time < days5 && !detailed) {
var d = Math.floor(days)
var h = Math.round(Math.floor(hours) % 24)
return (d > 0 ? d + (d == 1 ? " day " : " days ") : "") + h + (h == 1 ? " hour" : " hours")
} else if(time >= days5 && !detailed) {
return Math.round(days) + " days "
} else if(detailed) {
var d = Math.floor(days)
var h = Math.round(Math.floor(hours) % 24)
var m = Math.round(Math.floor(mins) % 60)
return (d > 0 ? d + (d == 1 ? " day " : " days ") : "") + h + (h == 1 ? " hour " : " hours ") + m + (m == 1 ? " minute" : " minutes")
} else {
return "undefined left " + time
}
}
function gameSort(a,b){
var sortType = sessionStorage.getItem("customSort")
var gameA = (new warlight_shared_viewmodels_main_MyGamesGameVM).Init(warlight_shared_viewmodels_ConfigurationVM.Settings, 0, a, warlight_shared_viewmodels_SignIn.get_CurrentPlayer())
var gameB = (new warlight_shared_viewmodels_main_MyGamesGameVM).Init(warlight_shared_viewmodels_ConfigurationVM.Settings, 0, b, warlight_shared_viewmodels_SignIn.get_CurrentPlayer())
var aRealTime = gameA.Game.RealTimeGame
var aPlaying = (gameA.Game.State == 3 || gameA.Game.State == 5) && gameA.UsOpt.State == 2
var aPrio0 = gameA.Game.PrivateMessagesWaiting || gameA.Game.PublicChatWaiting || gameA.Game.TeamChatWaiting
var aPrio1 = gameA.Game.State == 2 && gameA.UsOpt.State == 1 //Waiting to join
var aPrio4 = gameA.Game.State == 2 && gameA.Game.WaitingForYouToStart //Waiting for you to start
var aPrio3 = aPlaying && !gameA.UsOpt.HasCommittedOrders //Your turn 3 = turn, 5 = picking
var aBootTime = Math.min(a.AutoBoot._totalMilliseconds, a.VoteToBoot._totalMilliseconds, a.DirectBoot._totalMilliseconds) - a.WaitingFor._totalMilliseconds
var bRealTime = gameB.Game.RealTimeGame
var bPlaying = (gameB.Game.State == 3 || gameB.Game.State == 5) && gameB.UsOpt.State == 2
var bPrio0 = gameB.Game.PrivateMessagesWaiting || gameB.Game.PublicChatWaiting || gameB.Game.TeamChatWaiting
var bPrio1 = gameB.Game.State == 2 && gameB.UsOpt.State == 1
var bPrio4 = gameB.Game.State == 2 && gameB.Game.WaitingForYouToStart
var bPrio3 = bPlaying && !gameB.UsOpt.HasCommittedOrders
var bBootTime = Math.min(b.AutoBoot._totalMilliseconds, b.VoteToBoot._totalMilliseconds, b.DirectBoot._totalMilliseconds) - b.WaitingFor._totalMilliseconds
if(aRealTime && !bRealTime) return -1;
if(bRealTime && !aRealTime) return 1;
if(sortType == 3) {
if(aPrio0 && !bPrio0) return -1;
if(bPrio0 && !aPrio0) return 1;
}
if(aPrio1 && !bPrio1) return -1;
if(bPrio1 && !aPrio1) return 1;
if(aPrio3 && !bPrio3) return -1;
if(bPrio3 && !aPrio3) return 1;
if(aPlaying && !bPlaying) return -1;
if(bPlaying && !aPlaying) return 1;
if(aPrio3 && bPrio3) return aBootTime - bBootTime;
if(aPrio4 && !bPrio4) return -1;
if(bPrio4 && !aPrio4) return 1;
return a.WaitingFor - b.WaitingFor
}
function gameCanBeNextGame(g) {
var game = (new warlight_shared_viewmodels_main_MyGamesGameVM).Init(warlight_shared_viewmodels_ConfigurationVM.Settings, 0, g, warlight_shared_viewmodels_SignIn.get_CurrentPlayer())
var playing = (game.Game.State == 3 || game.Game.State == 5) && game.UsOpt.State == 2
var prio0 = game.Game.PrivateMessagesWaiting || game.Game.PublicChatWaiting || game.Game.TeamChatWaiting
var prio1 = game.Game.State == 2 && game.UsOpt.State == 1 //Waiting to join
var prio3 = playing && !game.UsOpt.HasCommittedOrders //Your turn 3 = turn, 5 = picking
var prio4 = game.Game.State == 2 && game.Game.WaitingForYouToStart //Waiting for you to start
return prio0 || prio1 || prio3 || prio4
}
function refreshOpenGames() {
deletedMD = deletedRT = 0;
openGamesTable.find("tbody").fadeTo('fast', 0.15);
var page = $('').load('https://www.warlight.net/MultiPlayer/ ', function () {
var data = page.find('#AllOpenGamesData').html();
$('#AllOpenGamesData').html(data);
WL_MPDash.OpenGamesCtrl.AllOpenGamesData = data
Database.readIndex(Database.Table.Settings, Database.Row.Settings.Name, "openGamesFilters", function(filters) {
var openGamesFilters;
if(filters) {
openGamesFilters = filters.value;
}
var games;
if (openGamesFilters && openGamesFilters["disableAll"] != true) {
games = filterGames(wljs_Jsutil.GamesFromDump(data), openGamesFilters);
} else {
games = wljs_Jsutil.GamesFromDump(data);
}
$.each(games, function (key, game) {
if ($(game).playerJoined()) {
games[key] = $(game).markJoined();
}
});
wljs_AllOpenGames = WL_MPDash.OpenGamesCtrl.AllOpenGames = games;
var RealTimeLadderTable = page.find("#RealTimeLadderTable tbody tr:first-of-type").outerHTML();
$("#RealTimeLadderTable tbody tr:first-of-type")
$("#RealTimeLadderTable tbody tr:first-of-type").replaceWith(RealTimeLadderTable)
replaceAndFilterForumTable(page.find("#ForumTable").outerHTML());
$("#ClanForumTable").replaceWith(page.find("#ClanForumTable").outerHTML())
setupRightColumn()
updateOpenGamesCounter();
wljs_AllOpenGamesData = wljs_multiplayer_Ctrl_AllOpenGamesData = data;
var player = warlight_shared_viewmodels_SignIn.get_CurrentPlayer();
if ((new js.JQuery(this.BothRadio)).is(":checked")) {
player.OpenGamePreference = 1;
} else if ((new js.JQuery(this.MultiDayRadio)).is(":checked")) {
player.OpenGamePreference = 2;
} else if ((new js.JQuery(this.RealTimeRadio)).is(":checked")) {
player.OpenGamePreference = 3;
}
wljs_Jsutil.Post("/MultiPlayer/", "ChangePace=" + player.OpenGamePreference, function (a) {});
var a = $("#OpenGamesTable").children("tbody");
a.children().remove();
var gamesToShow = warlight_shared_viewmodels_main_MultiPlayerDashboardVM.GamesToShow(wljs_AllOpenGames, player.OpenGamePreference, 0 == this.ShowingAllOpenGames)
for (var b = 0; b < gamesToShow.length;) {
var game = gamesToShow[b];
b++;
game.get_IsLottery() && warlight_shared_viewmodels_main_MultiPlayerDashboardVM.get_HideLotteryGames() ||
(game = (new warlight_shared_viewmodels_main_MyGamesGameVM).Init(warlight_shared_viewmodels_ConfigurationVM.Settings, 2, game, warlight_shared_viewmodels_SignIn.get_CurrentPlayer()), a.append(warlight_shared_viewmodels_main_MultiPlayerDashboardVM.RenderGameHtml(warlight_shared_viewmodels_ConfigurationVM.Settings, game, null)))
}
openGamesTable.find("tbody").fadeTo('fast', 1, function () {
openGamesTable.css('overflow-y', 'scroll');
});
addOpenGamesSuffix();
domRefresh();
})
});
}
var refreshingPromotedGames = false;
function refreshPromotedGames() {
if(!refreshingPromotedGames) {
refreshingPromotedGames = true;
promotedGamesTable.find("tbody").fadeTo('fast', 0.15);
var page = $('').load('https://www.warlight.net/MultiPlayer/ ', function () {
var data = page.find('#MorePromotedGamesData').html();
$('#MorePromotedGamesData').html(data);
wljs_PromotedGames = wljs_Jsutil.GamesFromDump(data);
refreshingPromotedGames = false;
var a = $("#PromotedGamesTable").children("tbody");
a.children().remove();
for (var b = 0; b < wljs_PromotedGames.length;) {
var game = wljs_PromotedGames[b];
b++;
(game = (new warlight_shared_viewmodels_main_MyGamesGameVM).Init(warlight_shared_viewmodels_ConfigurationVM.Settings, 2, game, warlight_shared_viewmodels_SignIn.get_CurrentPlayer()), a.append(warlight_shared_viewmodels_main_MultiPlayerDashboardVM.RenderGameHtml(warlight_shared_viewmodels_ConfigurationVM.Settings, game, null)))
}
domRefresh();
promotedGamesTable.find("tbody").fadeTo('fast', 1, function () {
promotedGamesTable.css('overflow-y', 'scroll');
});
});
} else {
log("refreshing promoted blocked")
}
}
/**
* Setups the refresh functionality
*/
function setupRefreshFunction() {
lastRefresh = new Date();
var oldRefreshBtn = $("#RefreshBtn");
var oldRefreshBtn2 = $("#RefreshBtn2");
if (oldRefreshBtn.length) {
var newRefreshBtn = $("#refreshAll");
oldRefreshBtn.replaceWith(oldRefreshBtn.clone().removeAttr("id").attr("id", "refreshAll").attr("value", "Refresh (R)"));
newRefreshBtn.appendTo("body");
$("#refreshAll").on("click", function () {
if (new Date() - lastRefresh > 3000) {
lastRefresh = new Date();
log("Refresh by click")
refreshAllGames();
}
});
} else if (oldRefreshBtn2.length) {
var newRefreshBtn = $("#refreshAll");
oldRefreshBtn2.replaceWith(oldRefreshBtn2.clone().removeAttr("id").attr("id", "refreshAll").attr("value", "Refresh (R)"));
newRefreshBtn.appendTo("body");
$("#refreshAll").on("click", function () {
if (new Date() - lastRefresh > 3000) {
lastRefresh = new Date();
log("Refresh by click")
refreshAllGames();
}
});
}
$(".MainColumn").prepend($('#refreshAll'))
ifSettingIsEnabled('autoRefreshOnFocus', function() {
$(window).on('focus', function () {
if (new Date() - lastRefresh > 30000) {
lastRefresh = new Date();
log("Refresh by focus")
refreshAllGames();
}
});
})
$("body").keyup(function (event) {
// "R" is pressed
if (event.which == 82) {
if (new Date() - lastRefresh > 3000) {
lastRefresh = new Date();
log("Refresh by key r")
refreshAllGames();
}
}
});
}
function getDate(text) {
var date;
if (text.match(/[0-9]+ second/)) {
date = new Date() - 1000;
} else if (text.match(/[0-9]+ seconds/)) {
date = new Date() - text.match(/[0-9]+/) * 1000;
} else if (text.match(/[0-9]+ minute/)) {
date = new Date() - text.match(/[0-9]+/) * 1000 * 60;
} else if (text.match(/[0-9]+ minutes/)) {
date = new Date() - text.match(/[0-9]+/) * 1000 * 60;
} else if (text.match(/[0-9]+ hour/)) {
date = new Date() - text.match(/[0-9]+/) * 1000 * 60 * 59;
} else if (text.match(/[0-9]+ hours/)) {
date = new Date() - text.match(/[0-9]+/) * 1000 * 60 * 60;
} else if (text.match(/[0-9]+ day/)) {
date = new Date() - text.match(/[0-9]+/) * 1000 * 60 * 60 * 36;
} else if (text.match(/[0-9]+ days/)) {
date = new Date() - text.match(/[0-9]+/) * 1000 * 60 * 60 * 24;
} else if (text.match(/[0-9]+[\/][0-9]+[\/][0-9]+/)) {
var split = text.split('/');
date = new Date(split[2], split[0] - 1, split[1]);
date.setHours(0, 0, 0, 0);
}
return date;
}
function setGlobalStyles() {
$("[src='https://d2wcw7vp66n8b3.cloudfront.net/Images/MembershipGiftIcon.gif']").closest(".dataTable").attr("id", "ShopTable");
createSelector('.help-icon', 'display:inline-block;position:absolute; margin-left:10px;margin-top: 2px;cursor:pointer; height: 15px; width: 15px;')
var winHeight = $(window).height();
createSelector(".userscript-menu", "display: block;color: #555;text-decoration: none;line-height: 18px;padding: 3px 15px;margin: 0;white-space: nowrap;");
createSelector(".userscript-menu:hover", "cursor:pointer;background-color: #08C;color: #FFF;cursor: pointer;");
createSelector(".popup", "position: fixed;;left: 50%;background: #171717;top: 100px;z-index: 99; color:white;padding:60px 30px 30px 30px;border: 2px solid gray;border-radius:8px;max-height:" + (winHeight - 200) + "px;overflow-y:auto");
createSelector(".close-userscript", "margin: 40px 0;width: 100%;text-align: center;font-size: 15px;cursor: pointer;background: gray;line-height: 30px;border-radius: 8px;clear: both");
createSelector(".close-popup-img", "float:right;margin:5px;cursor:pointer;margin-right: 20px");
createSelector(".popup label", "width: 80%;display: inline-block;font-size: 15px;margin: 5px;");
createSelector(".popup .title", "color: gray;font-size: 15px;margin-top: 10px;display: inline-block;width: 95%;border-bottom: 1px gray solid;padding-bottom: 3px;");
createSelector(".popup input[type='checkbox']", "width: 20px;height: 20px;margin-left:30px;margin: 5px;-moz-appearance:none;");
createSelector(".overlay", "position: absolute;background: white;top: 0;left: 0;right: 0;bottom: 0;z-index: 98;opacity: 0.5;width: 100%;height: 100%;position: fixed;");
createSelector(".popup .head", "position: fixed;height: 40px;background: #330000;width: 660px;left: 0;right: 0;top: 100px;color: white;font-size: 15px;text-align: center;line-height: 40px;border-top-left-radius:8px;border-top-right-radius:8px;margin:auto;z-index:10000;");
createSelector(".userscript-show", "display:none");
createSelector("#MorePromotedGamesHorizontalRow", "display:none");
createSelector(".newSetting", "color: gold;font-weight: bold;");
createSelector(".userscript-menu img", "height: 18px;display: inline-block;position: relative;margin-bottom: -5px;margin-right: 7px;");
createSelector(".custom-menu", "display: none;z-index: 98;position: absolute;overflow: hidden;border: 1px solid #CCC;white-space: nowrap;font-family: sans-serif;background: #FFF;color: #333;border-radius:5px;padding: 10px;z-index:100000000; cursor:pointer");
createSelector(".custom-menu .content", "width: 300px;white-space: pre-wrap;");
createSelector('.popup input[type="text"]', 'display: inline-block;background: none;border-top: none;border-left: none;border-right: none;color: green;font-size: 15px;border-bottom: 1px white dashed;font-family: Verdana;padding: 0 5px 0 5px;text-align: center;margin-right: 5px');
createSelector(".popup840", "width: 840px;margin-left: -452px");
createSelector(".popup600", "width: 600px;margin-left: -332px");
createSelector(".popup840 .head", "width: 900px");
createSelector(".popup600 .head", "width: 660px");
createSelector(".context-menu", "display: none;z-index: 100;position: absolute;overflow: hidden;border: 1px solid #CCC;white-space: nowrap;font-family: sans-serif;background: #FFF;color: #333;border-radius: 5px;padding: 0;");
createSelector(".context-menu li", "padding: 8px 12px;cursor: pointer;list-style-type: none;");
createSelector(".context-menu li:hover", "background-color: #DEF;");
createSelector("#MyGamesTable select","margin: 0 10px 0 5px; width: 125px")
createSelector("#MyGamesFilter", "float:right")
createSelector("#MyGamesTable thead tr", "text-align: right")
$("body").on("click", function (e) {
if ($(".custom-menu").is(':visible')) {
$(".custom-menu").hide(100);
}
});
}
window.deletedRT = 0;
window.deletedMD = 0;
function filterGames(games, openGamesFilters) {
var filteredGames = [];
var deletedGames = [];
$.each(games, function (key, game) {
if (!$(game).getsFiltered(openGamesFilters)) {
filteredGames.push(game);
} else {
if (game.RealTimeGame) {
deletedRT++;
} else {
deletedMD++;
}
}
});
return filteredGames;
}
function storeFilterVariables() {
openGamesFilters = {};
$.each(filters, function (key, filter) {
if (filter.type == "checkbox") {
openGamesFilters[filter.id] = $("#" + filter.id).prop("checked");
}
});
openGamesFilters["hideKeyword"] = $("#hideKeyword").val()
openGamesFilters["hideRealTimeBootTime"] = $("#hideRealTimeBootTime").val()
openGamesFilters["hideMultiDayBootTimeDays"] = $("#hideMultiDayBootTimeDays").val()
openGamesFilters["hideMultiDayBootTimeHours"] = $("#hideMultiDayBootTimeHours").val()
var luck = $("#hideLuck").val();
openGamesFilters["hideLuck"] = ($.isNumeric(luck) && luck <= 100 && luck >= 0) ? luck : 100;
var minPlayers = $("#hideMinPlayers").val();
openGamesFilters["hideMinPlayers"] = ($.isNumeric(minPlayers) && minPlayers <= 100 && minPlayers >= 2) ? minPlayers : 2;
var maxPlayers = $("#hideMaxPlayers").val();
openGamesFilters["hideMaxPlayers"] = ($.isNumeric(maxPlayers) && maxPlayers <= 100 && maxPlayers >= 2) ? maxPlayers : 100;
if (parseFloat(openGamesFilters["hideMinPlayers"]) > parseFloat(openGamesFilters["hideMaxPlayers"])) {
openGamesFilters["hideMaxPlayers"] = openGamesFilters["hideMinPlayers"]
}
var rtBoot = $("#hideRealTimeBootTime").val();
openGamesFilters["hideRealTimeBootTime"] = $.isNumeric(rtBoot) ? rtBoot * 60 * 1000 : 0;
var mdBoot = calculateMDBoot($("#hideMultiDayBootTimeHours").val(), $("#hideMultiDayBootTimeDays").val());
openGamesFilters["hideMultiDayBootTimeDays"] = mdBoot.days;
openGamesFilters["hideMultiDayBootTimeHours"] = mdBoot.hours;
openGamesFilters["hideMultiDayBootTimeInMs"] = (parseInt(mdBoot.days) * 24 + parseInt(mdBoot.hours)) * 60 * 60 * 1000;
var gameFilters = {
name: "openGamesFilters",
value: openGamesFilters
}
Database.update(Database.Table.Settings, gameFilters, undefined, function() {
updateFilterSettings()
})
}
function calculateMDBoot(hours, days) {
hours = $.isNumeric(hours) ? hours : 0;
days = $.isNumeric(days) ? days : 0;
if (hours >= 24) {
days = parseFloat(days) + parseInt(hours / 24);
hours -= parseInt(hours / 24) * 24
}
return {
hours: hours,
days: days
}
}
function updateFilterSettings() {
Database.readIndex(Database.Table.Settings, Database.Row.Settings.Name, "openGamesFilters", function(gameFilters) {
if(!gameFilters || !gameFilters.value) {
return;
}
var openGamesFilters = gameFilters.value;
$.each(filters, function (key, filter) {
if (filter.type == "checkbox") {
$("#" + filter.id).prop("checked", openGamesFilters[filter.id]);
}
});
$("#hideLuck").val(openGamesFilters["hideLuck"] || 100);
$("#hideMinPlayers").val(openGamesFilters["hideMinPlayers"] || 0);
$("#hideMaxPlayers").val(openGamesFilters["hideMaxPlayers"] || 100);
$("#hideKeyword").val(openGamesFilters["hideKeyword"] || "");
$("#hideRealTimeBootTime").val(openGamesFilters["hideRealTimeBootTime"] / 1000 / 60 || 0);
$("#hideMultiDayBootTimeDays").val(openGamesFilters["hideMultiDayBootTimeDays"] || 0);
$("#hideMultiDayBootTimeHours").val(openGamesFilters["hideMultiDayBootTimeHours"] || 0);
})
}
function ifSettingIsEnabled(setting, positive, negative, cb) {
Database.readIndex(Database.Table.Settings, Database.Row.Settings.Name, setting, function(setting) {
if(setting && setting.value) {
positive();
if(typeof cb == "function") {
cb();
}
} else {
if(typeof negative == 'function') {
negative();
}
if(typeof cb == 'function') {
cb();
}
}
})
}
function ifSettingIsNotEnabled(setting, callback) {
Database.readIndex(Database.Table.Settings, Database.Row.Settings.Name, setting, function(setting) {
if(!setting.value) {
callback();
}
})
}
function ifAllAreEnabled(settings, positive, negative) {
var promises = [];
var allAreEnabled = true;
$.each(settings, function (key, setting) {
promises[key] = $.Deferred();
Database.readIndex(Database.Table.Settings, Database.Row.Settings.Name, setting, function(set) {
if(!set || !set.value) {
allAreEnabled = false;
}
promises[key].resolve();
})
})
$.when.apply($, promises).done(function () {
if(allAreEnabled){
positive()
} else {
if(typeof negative == "function") {
negative();
}
}
})
}
function ifOneOrMoreIsEnabled(settings, positive, negative) {
var promises = [];
var isEnabled = false;
$.each(settings, function (key, setting) {
promises[key] = $.Deferred();
Database.readIndex(Database.Table.Settings, Database.Row.Settings.Name, setting, function(set) {
if(set && set.value) {
isEnabled = true;
}
promises[key].resolve();
})
})
$.when.apply($, promises).done(function () {
if(isEnabled){
positive()
} else {
if(typeof negative == "function") {
negative();
}
}
})
}
function pageIsMultiplayer() {
return location.href.match(/.*warlight[.]net\/MultiPlayer.*/i);
}
function pageIsPointsPage() {
return location.href.match(/.*warlight[.]net\/Points.*/i);
}
function pageIsDashboard() {
return location.href.match(/.*warlight[.]net\/MultiPlayer\/(?:#|\?|$).*$/i);
}
function pageIsRealTimeLadder() {
return location.href.match(/.*warlight[.]net\/LadderSeason\?ID=3.*$/i);
}
function pageIsProfile() {
return location.href.match(/.*warlight[.]net\/profile\?p=[0-9]+$/i);
}
function pageIsLevelOverview() {
return location.href.match(/.*warlight[.]net\/SinglePlayer\/Level\?ID=[0-9]+$/i);
}
function pageIsLevelPlayLog() {
return location.href.match(/.*warlight[.]net\/SinglePlayer\/PlayLog\?ID=[0-9]+$/i);
}
function pageIsMapsPage() {
return location.href.match(/.*warlight[.]net\/maps/i);
}
function pageIsClanThread() {
return location.href.match(/.*warlight[.]net\/Discussion/i);
}
function pageIsNewThread() {
return location.href.match(/.*warlight[.]net\/Forum\/NewThread.*/i);
}
function pageIsForumThread() {
return location.href.match(/.*warlight[.]net\/Forum\/[0-9]+.*/i);
}
function pageIsForumOverview() {
return location.href.match(/.*warlight[.]net\/Forum\/Forum.*/i);
}
function pageIsThread() {
return location.href.match(/.*warlight[.]net\/(Forum|Discussion|Clans\/CreateThread).*/i);
}
function pageIsSubForum() {
return location.href.match(/.*warlight[.]net\/Forum\/[A-Z]+.*/i);
}
function pageIsForum() {
return location.href.match(/.*warlight[.]net\/Forum\/.*/);
}
function pageIsLadderOverview() {
return location.href.match(/.*warlight[.]net\/Ladders/);
}
function pageIsLogin() {
return location.href.match(/.*warlight[.]net\/LogIn.*/);
}
function pageIsClanForumThread() {
return location.href.match(/.*warlight[.]net\/Discussion\/\?ID=[0-9]+.*/);
}
function pageIsTournament() {
return location.href.match(/.*warlight[.]net\/MultiPlayer\/Tournament\?ID=[0-9]+/i);
}
function pageIsTournamentOverview() {
return location.href.match(/.*warlight[.]net\/MultiPlayer\/Tournaments\/$/i);
}
function pageIsGame() {
return location.href.match(/.*warlight[.]net\/MultiPlayer\?GameID=[0-9]+/i);
}
function pageIsCommonGames() {
return location.href.match(/.*warlight[.]net\/CommonGames\?p=[0-9]+$/i);
}
function pageIsCommunityLevels() {
return location.href.match(/.*warlight[.]net\/SinglePlayer\/CommunityLevels/i);
}
function pageIsBlacklistPage() {
return location.href.match(/.*warlight[.]net\/ManageBlackList.*/i);
}
function pageIsMapPage() {
return location.href.match(/.*warlight[.]net\/Map.*/i);
}
function showOpenGamesLink() {
$("#SubTabRow td:nth-child(8)").after('
");
}
}
function getNumHiddenLabelText(num) {
return num == 1 ? "1 Game is hidden" : (num + " Games are hidden");
}
function loadPrivateNotes() {
log("Loading private notes")
$("#FeedbackMsg").after('
Private Notes
Loading Privates Notes..
');
var url = $("img[alt='Private Notes']").parent()[0].href;
var page = $('').load(url, function () {
var notes = page.find('#PostForDisplay_0').html().trim();
if (notes) {
$('#privateNotes .content').html(notes);
} else {
$('#privateNotes .content').html('You don\'t have any Private Notes.');
}
});
}
window.showFilterOptions = function () {
showPopup(".filters-show")
}
function domRefresh() {
$("body").hide(0).show(0);
$(window).trigger('resize')
}
window.showFilterHelp = function (text, obj) {
window.setTimeout(function () {
if (!$(".custom-menu").is(':visible')) {
$(".custom-menu .content").html(text);
$(".custom-menu").finish().toggle(100).
// In the right position (the mouse)
css({
top: $(obj).offset().top + "px",
left: $(obj).offset().left + "px"
});
}
}, 10);
}
function setupBookmarkMenu() {
bookmarkBody = "
' + nameLink + member + "(Level " + player.Level + ", " + player.TimesPlayedWithYou + " common games)
";
$("#foundPlayers").append('
' + clan + description + '
')
}
}
function parseFoundClans(clans) {
clans.sort(function (c1, c2) {
return (c2.TotalPointsInThousands - c1.TotalPointsInThousands)
});
var clanTableHTML = '
#
Name
Created By
Total Points
Created On
'
for (var i = 0; i < clans.length; i++) {
var clan = clans[i];
var name = clan.Name;
var id = clan.ID;
var createdBy = clan.CreatedBy;
var iconId = clan.IconIncre;
var imgTag = iconId == 0 ? "" : ``;
var totalpoints = (clan.TotalPointsInThousands * 1000).toLocaleString("en")
var createdDate = moment(clan.CreatedDate.date).format('MM/DD/YYYY')
var nameHTML = `${imgTag}${name}`;
clanTableHTML += `