// ==UserScript==
// @name MouseHunt - Tournament Time Helper
// @author Jia Hao (Limerence#0448 @Discord)
// @namespace https://greasyfork.org/en/users/165918-jia-hao
// @version 1.7
// @description Automatically converts "Begins in:" to your local time as well as adding the end time for tournaments.
// @include http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
// @include https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/locale/en-ie.js
// @include http://www.mousehuntgame.com/*
// @include https://www.mousehuntgame.com/*
// @downloadURL none
// ==/UserScript==
function saveTimeFormat() {
var tournaments = document.getElementsByClassName("tournamentPage-tournamentRow tournamentPage-tournamentData basic pending");
var timeFormatCheckbox = document.getElementById('timeformat');
var startTime, endTime, day, date, time;
if (timeFormatCheckbox.checked) {
window.localStorage.setItem('timeformat', '24-hour'); //save settings
for (i = 0; i < tournaments.length; i++) {
startTime = tournaments[i].children[3].innerHTML.split("
");
endTime = tournaments[i].children[4].innerHTML.split("
");
day = startTime[0];
date = startTime[1];
time = startTime[2];
tournaments[i].children[3].innerHTML = moment(day + " " + date + " " + time, "dddd D MMM YYYY h:mm A").format("dddd
D MMM YYYY
HH:mm").concat(" hrs");
day = endTime[0];
date = endTime[1];
time = endTime[2];
tournaments[i].children[4].innerHTML = moment(day + " " + date + " " + time, "dddd D MMM YYYY h:mm A").format("dddd
D MMM YYYY
HH:mm").concat(" hrs");
}
} else {
window.localStorage.setItem('timeformat', '12-hour'); //save settings
for (i = 0; i < tournaments.length; i++) {
startTime = tournaments[i].children[3].innerHTML.split("
");
endTime = tournaments[i].children[4].innerHTML.split("
");
day = startTime[0];
date = startTime[1];
time = startTime[2];
tournaments[i].children[3].innerHTML = moment(day + " " + date + " " + time + " hrs", "dddd D MMM YYYY HH:mm").format("dddd
D MMM YYYY
h:mm A");
day = endTime[0];
date = endTime[1];
time = endTime[2];
tournaments[i].children[4].innerHTML = moment(day + " " + date + " " + time + " hrs", "dddd D MMM YYYY HH:mm").format("dddd
D MMM YYYY
h:mm A");
}
}
}
function load() {
//Get local time and time format preference
var now = moment(new Date());
if (Math.abs(moment(now).zone()) % 60 > 0) {
now.add('minutes', 30);
}
var timeFormat = "12-hour";
try {
timeFormat = window.localStorage.getItem('timeformat');
if (timeFormat === null) { //Default time format is 12-hour.
window.localStorage.setItem('timeformat', '12-hour');
}
} catch (e) {
console.log('Browser does not support localStorage');
}
try {
//Checkbox for user time format preference
if (!document.getElementById('timeformat')) {
var tournamentHeading = document.getElementsByClassName("tournamentPage-tournamentHeading")[0];
tournamentHeading.innerHTML += " ";
tournamentHeading.innerHTML += "Display timings in 24-hour format";
}
if (timeFormat === "24-hour") {
document.getElementById('timeformat').checked = true;
}
$('#timeformat').click(function() {saveTimeFormat();});
//Editing the Table
//Shrinking tournament description to fit a new column
var tournamentNames = document.getElementsByClassName("tournamentPage-tournament-column name");
for (var i = 0; i < tournamentNames.length; i++) {
tournamentNames[i].style.width = "35.5%";
}
//Changing the header "Begins in:" to "Begins at:"
//Adding the header "Ends at:"
//Looping since there are potentially special tournament tabs
var beginsHeader = document.getElementsByClassName("tournamentPage-tournament-column label");
for (i = 0; i < beginsHeader.length; i++) {
if (beginsHeader[i].innerHTML === "Begins in:") {
beginsHeader[i].style.marginRight = "0.15%";
beginsHeader[i].insertAdjacentHTML('afterend', "