// ==UserScript==
// @name Tidy up your Dashboard
// @namespace https://greasyfork.org/users/10154
// @grant none
// @run-at document-start
// @match https://www.warlight.net/*
// @description Tidy Up Your Dashboard is a Userscript which brings along a lot of features for improving the user experience on Warlight.
// @version 1.99.99
// @icon http://i.imgur.com/XzA5qMO.png
// @require https://code.jquery.com/jquery-1.11.2.min.js
// ==/UserScript==
window.MULIS_USERSCRIPT = true;
var version = GM_info.script.version;
this.$$$ = jQuery.noConflict(true);
this.$ = $$$;
setupImages();
console.log(123)
function setupImages() {
window.IMAGES = {
EYE: 'https://i.imgur.com/kekYrsO.png',
CROSS: 'https://i.imgur.com/RItbpDS.png',
QUESTION: 'https://i.imgur.com/TUyoZOP.png',
PLUS: 'https://i.imgur.com/lT6SvSY.png',
SAVE: 'https://i.imgur.com/Ze4h3NQ.png',
BOOKMARK: 'https://i.imgur.com/c6IxAql.png'
}
}
$$$(document).ready(function() {
if(location.href.match(/.*temp\?Muli.*/i)) {
console.log("active")
$$$("body").html("<h1>Export Muli's userscript Settings</h1>")
$$$("body").append("Copy or download this text and save it somewhere on your computer!<br><br><textarea style='display:block;width:100%; height: 500px' id='exportSettingsBox'></textarea><a id='downloadExportSettingsFile' href='' download='tuyd_settings.txt'>Download Text-File</a></div>")
}
})
setupDatabase()
if (document.readyState == 'complete' || document.readyState == 'interactive') {
DOM_ContentReady();
} else {
window.document.addEventListener("DOMContentLoaded", DOM_ContentReady);
}
function DOM_ContentReady() {
Database.init(function() {
exportSettings();
})
}
function setupDatabase() {
window.Database = {
db: null,
Table: {
Bookmarks: "Bookmarks",
Settings: "Settings",
BlacklistedForumThreads: "BlacklistedForumThreads",
TournamentData: "TournamentData"
},
Exports: {
Bookmarks: "Bookmarks",
Settings: "Settings",
BlacklistedForumThreads: "BlacklistedForumThreads"
},
Row: {
BlacklistedForumThreads: {
ThreadId: "threadId",
Date: "date"
},
Bookmarks: {
Order: "order"
},
Settings: {
Name: "name"
},
TournamentData: {
Id: "tournamentId",
}
},
init: function(callback) {
if(!"indexedDB" in window) {
return;
}
var openRequest = indexedDB.open("TidyUpYourDashboard_v3", 3);
openRequest.onupgradeneeded = function(e) {
var thisDB = e.target.result;
if(!thisDB.objectStoreNames.contains("Bookmarks")) {
var objectStore = thisDB.createObjectStore("Bookmarks", {autoIncrement:true});
objectStore.createIndex("order", "order", {unique:true});
}
if(!thisDB.objectStoreNames.contains("Settings")) {
var objectStore = thisDB.createObjectStore("Settings", { keyPath: "name" });
objectStore.createIndex("name", "name", {unique: true});
objectStore.createIndex("value", "value", {unique: false});
}
if(!thisDB.objectStoreNames.contains("BlacklistedForumThreads")) {
var objectStore = thisDB.createObjectStore("BlacklistedForumThreads", {autoIncrement:true});
objectStore.createIndex("threadId", "threadId", {unique:true});
objectStore.createIndex("date", "date", {unique:false});
}
if(!thisDB.objectStoreNames.contains("TournamentData")) {
var objectStore = thisDB.createObjectStore("TournamentData",{ keyPath: "tournamentId" });
objectStore.createIndex("tournamentId", "tournamentId", {unique:true});
objectStore.createIndex("value", "value", {unique: false});
}
}
openRequest.onsuccess = function(e) {
db = e.target.result;
callback()
}
openRequest.onerror = function(e) {
// alert("Sorry, Tidy Up Your Dashboard is not supported")
$$$("<div>Sorry,<br> Tidy Up Your Dashboard is not supported.</div>").dialog();
}
},
update: function(table, value, key, callback) {
var transaction = db.transaction([table],"readwrite");
var store = transaction.objectStore(table);
//Perform the add
try {
var request = store.put(value, key != undefined ? Number(key) : undefined);
request.onerror = function(e) {
log(JSON.stringify(e));
}
request.onsuccess = function(e) {
callback()
}
} catch(e) {
}
},
read: function(table, key, callback) {
var transaction = db.transaction([table], "readonly");
var objectStore = transaction.objectStore(table);
var ob = objectStore.get(Number(key));
ob.onsuccess = function(e) {
var result = e.target.result;
callback(result)
}
},
readIndex: function(table, row, value, callback) {
var transaction = db.transaction([table], "readonly");
var objectStore = transaction.objectStore(table);
var index = objectStore.index(row);
//name is some value
var ob = index.get(value);
ob.onsuccess = function(e) {
var result = e.target.result;
callback(result)
}
},
readAll: function(table, callback) {
var transaction = db.transaction([table], "readonly");
var objectStore = transaction.objectStore(table);
var items = []
var ob = objectStore.openCursor()
ob.onsuccess = function(e) {
var cursor = e.target.result;
if (cursor) {
var item = cursor.value;
item.id = cursor.primaryKey;
items.push(item);
cursor.continue();
} else {
callback(items)
}
}
},
add: function(table, value, callback) {
var transaction = db.transaction([table],"readwrite");
var store = transaction.objectStore(table);
try {
var request = store.add(value);
request.onerror = function(e) {
log(`Error saving ${JSON.stringify(value)} in ${table}`)
log(JSON.stringify(e));
}
request.onsuccess = function(e) {
log(`Saved ${JSON.stringify(value)} in ${table}`)
callback()
}
} catch(e) {
log(`Error saving ${JSON.stringify(value)} in ${table}`)
log(JSON.stringify(e));
}
request.onerror = function(e) {
log(`Error saving ${JSON.stringify(value)} in ${table}`)
log(JSON.stringify(e));
}
request.onsuccess = function(e) {
log(`Saved ${JSON.stringify(value)} in ${table}`)
callback()
}
},
delete: function(table, key, callback) {
var transaction = db.transaction([table],"readwrite");
var store = transaction.objectStore(table);
//Perform the add
var request = store.delete(key)
request.onerror = function(e) {
//some type of error handler
}
request.onsuccess = function(e) {
callback()
}
},
clear: function(table, callback) {
var transaction = db.transaction([table],"readwrite");
var store = transaction.objectStore(table);
//Perform the add
var request = store.clear();
request.onerror = function(e) {
//some type of error handler
}
request.onsuccess = function(e) {
callback()
}
},
}
}
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 a lot 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 ( <img src="https://d2wcw7vp66n8b3.cloudfront.net/Images/GameInfoIcons/Teams.png">,<img src="https://d2wcw7vp66n8b3.cloudfront.net/Images/GameInfoIcons/ManualDistribution.png"> , 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 (coin) 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: 'nonUnityDashboard',
text: 'Display HTML Dashboard when Unity is enabled',
selected: false,
title: '',
addBreak: false,
help: 'This options makes sure that you will see the HTML dashboard instead of the unity dashboard if unity is enabled.'
},
{
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 to right-click forum thread on the dashboard and use the default browser 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.'
}
];
function exportSettings() {
var settings = [];
var deferredCount = 0;
var resolvedCount = 0;
var promises = [];
$$$.each(Database.Exports, function (key, table) {
promises[deferredCount++] = $$$.Deferred();
Database.readAll(table, function(data) {
settings.push({table: table, data: data})
promises[resolvedCount++].resolve();
})
})
$$$.when.apply($$$, promises).done(function () {
var settingsString = btoa(JSON.stringify(settings))
$$$("#exportSettingsBox").html(settingsString)
$$$("#exportSettingsBox").focus();
$$$("#exportSettingsBox").select();
$$$("#downloadExportSettingsFile").click(function(){
this.href = "data:text/plain;charset=UTF-8," + settingsString;
});
});
}