try to take over the world!
当前为
// ==UserScript==
// @name Better Games Done Quick Schedule
// @namespace http://tampermonkey.net/
// @version 2.0
// @description try to take over the world!
// @author Ruben
// @match https://gamesdonequick.com/schedule
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
(function() {
'use strict';
console.log("Better AGDQ Shedule loading...");
var tableRows = $("#runTable tbody tr").not(".day-split");
var tableRowsDays = $("#runTable tbody tr");
var time = "";
var day = 0;
var currentDate = new Date($.now());
var rowOfCurrentRun = 0;
var refreshInSeconds = 0;
var refreshInTime = "";
var newDate;
var countdown;
var days = {};
var amountOfDays = 0;
var counter = 0;
console.log("Collecting and formatting dates and times...");
for(var j = 0; j < tableRowsDays.length; j = j + 2)
{
if(tableRowsDays.eq(j).hasClass("day-split"))
{
day = tableRowsDays.eq(j).text().match(/\d+/)[0];
//console.log(day);
j--;
continue;
}
//console.log(tableRowsDays.eq(j));
days.length = amountOfDays+1;
days[amountOfDays] = day;
//console.log(days);
amountOfDays++;
}
for(var i = 0; i < tableRows.length; i = i + 2)
{
time = timeFormatting(tableRows.eq(i).children().eq(0).text());
//console.log(days[counter]);
var date="2017/01/" + days[counter] +" " + time;
newDate = new Date(Date.parse(date));
//newDate = newDate -(-6000000);
if(currentDate < newDate)
{
console.log("Highlighting current runs...");
//console.log(newDate);
//console.log(currentDate);
//console.log(tableRows.eq(i-2));
//console.log(tableRows.eq(i-1));
//Ändere Background vom vorheriger Run
tableRows.eq(i-4).css("background-color", "#f2dede");
tableRows.eq(i-4).css("color", "black");
tableRows.eq(i-3).css("background-color", "#f2dede");
tableRows.eq(i-3).css("color", "black");
$(tableRows.eq(i-4)).attr('id', 'currentRun');
//Ändere Background vom aktuellem Run
tableRows.eq(i-2).css("background-color", "#a00303");
tableRows.eq(i-2).css("color", "white");
tableRows.eq(i-1).css("background-color", "#a00303");
tableRows.eq(i-1).css("color", "white");
//Ändere Background vom nächsten Run
tableRows.eq(i).css("background-color", "#f2dede");
tableRows.eq(i).css("color", "black");
tableRows.eq(i+1).css("background-color", "#f2dede");
tableRows.eq(i+1).css("color", "black");
rowOfCurrentRun = i;
i = tableRows.length;
}
counter++;
}
console.log("Adding current run to the top of the page...");
//Den aktuellen RUN an den Anfang der Seite einfügen
var top = $(tableRows.eq(rowOfCurrentRun-2)).children();
var bottom = $(tableRows.eq(rowOfCurrentRun-1)).children();
refreshInSeconds = Math.ceil(((newDate - currentDate)/1000));
refreshInTime = secondsToTime(refreshInSeconds);
var countdown = "<div id='countdown' style='display: inline-block; text-align: center; padding: 5px 20px; line-height: 25px; background-color: #a00303; color: white; width: 150px; height: 100%'>Next Run in: " + refreshInTime + "</div>";
var goToCurrentRun = "<a href='#currentRun' id='goToCurrentRun' style='display: inline-block; text-align: center; padding: 5px 20px; color: white; line-height: 25px; padding-left: 15px; height: 100%; width: 150px; text-decoration: none; background-color: #8c1616;'>Go to Current Run <img style='filter: invert(); width: 20px; height: 22px' src='https://cdn0.iconfinder.com/data/icons/navigation-set-arrows-part-one/32/DoubleChevronDown-128.png'/></a>";
var currentRun = "<div style='overflow-x: auto; display: inline-block; max-width: 100%; vertical-align: top;'><nobr><div style='background-color: #a00303; color: white; padding: 5px 20px; line-height: 25px; display: inline-block;'>Current Run: <b>" + top.eq(1).text() + " (" + bottom.eq(1).text() + ")</b> From <b>" + top.eq(2).text() + "</b><br/>Start: <b>" + timeFormatting(top.eq(0).text()) + " </b> Duration: <b>" + timeFormatting(bottom.eq(0).text()) + " </b> Setup Length: <b>" + timeFormatting(top.eq(3).text()) + "</b></div></nobr></div>" + goToCurrentRun + countdown;
$("#top").after(currentRun);
//console.log($("#white-bg").eq(2));
$("#goToCurrentRun").mouseenter(function() {
$(this).css("background-color", "#c32323");
}).mouseleave(function() {
$(this).css("background-color", "#8c1616");
});
countdown = setInterval(function() {
refreshInSeconds--;
if(refreshInSeconds < 0) {
//Refresh
clearInterval(countdown);
} else {
$("#countdown").text("Next Run in: "+secondsToTime(refreshInSeconds));
}
}, 1000);
console.log("Better AGDQ Shedule done");
})();
function timeFormatting(time)
{
//console.log("TimeFormatting:" + time);
//console.log("Länge: " + time.length);
//console.log(time);
if(time.length == 7)
{
time = "0" + time;
}
else if(time.length == 10)
{
time = time.replace(/ /g, "0");
}
else
{
time = time;
}
return time;
}
function secondsToTime(seconds)
{
var hours = Math.floor((seconds/60/60));
seconds = seconds - hours*60*60;
var minutes = Math.floor((seconds/60));
seconds = seconds - minutes*60;
return(addZero(hours) + ":" + addZero(minutes) + ":" + addZero(seconds));
}
function addZero(time)
{
if(time.toString().length == 1)
{
return ("0" + time);
}
else return ("" + time);
}