Added settings of timeshift, fixed undefined behavior after anomaly times
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name IITC plugin: ResTools BB Watch Reloaded
|
||||
// @namespace https://git.martinvylet.cz/vykend/ResTools-BB-Watch-Reloaded
|
||||
// @version 0.4
|
||||
// @version 0.5
|
||||
// @description Scan window for BBs on ornamented portals, then check results
|
||||
// @author vikend
|
||||
// @icon
|
||||
@@ -28,6 +28,7 @@ function wrapper(plugin_info)
|
||||
window.plugin.restoolsBBWatchReloaded.LAYERGROUP = null;
|
||||
window.plugin.restoolsBBWatchReloaded.BB_STORAGE = 'plugin-restools-bbwatch-reloaded';
|
||||
window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS = [[[],[]],[[],[]],[[],[]],[[],[]],[[],[]],[[],[]],[[],[]]];
|
||||
window.plugin.restoolsBBWatchReloaded.timezone = 0;
|
||||
//struct of WAVE_PORTALS: [ wave: [ ornamented[], results[] ] ]
|
||||
|
||||
//edit this with start times according to YOUR local times (ie. as seen in COMM)
|
||||
@@ -79,9 +80,13 @@ function wrapper(plugin_info)
|
||||
|
||||
// --- HELPER
|
||||
window.plugin.restoolsBBWatchReloaded.getCurrentWaveNo = function() {
|
||||
|
||||
const currentTime = new Date();
|
||||
const currentTimeString = currentTime.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
const currentTimePlus5Minutes = (new Date(currentTime.getTime() + 5 * 60000)).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });// Adding 20 minutes in milliseconds
|
||||
const timezoneOffsetHours = window.plugin.restoolsBBWatchReloaded.timezone; // Assuming the offset is stored in hours
|
||||
const offsetMilliseconds = timezoneOffsetHours * 60 * 60 * 1000; // Convert offset to milliseconds
|
||||
const currentTimeWithOffset = new Date(currentTime.getTime() + offsetMilliseconds);
|
||||
const currentTimeString = currentTimeWithOffset.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
const currentTimePlus5Minutes = (new Date(currentTimeWithOffset.getTime() + 5 * 60000)).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
|
||||
let currentWave = 0;
|
||||
let battleOver = false;
|
||||
@@ -149,6 +154,10 @@ function wrapper(plugin_info)
|
||||
console.log("BBWatchReloaded: According to timetable anomaly haven't started yet, skipping");
|
||||
return;
|
||||
}
|
||||
if (waveNo > 7) {
|
||||
console.log("BBWatchReloaded: According to timetable anomaly already ended, skipping");
|
||||
return;
|
||||
}
|
||||
let portalsToBeAdded = [];
|
||||
for (let i in wavePortals)
|
||||
{
|
||||
@@ -250,7 +259,7 @@ function wrapper(plugin_info)
|
||||
}
|
||||
|
||||
window.plugin.restoolsBBWatchReloaded.loadStorage = function() {
|
||||
if (JSON.parse(localStorage[window.plugin.restoolsBBWatchReloaded.BB_STORAGE]) != null) {
|
||||
if (localStorage[window.plugin.restoolsBBWatchReloaded.BB_STORAGE] != undefined) {
|
||||
return JSON.parse(localStorage[window.plugin.restoolsBBWatchReloaded.BB_STORAGE]);
|
||||
}
|
||||
else {
|
||||
@@ -272,6 +281,8 @@ function wrapper(plugin_info)
|
||||
|
||||
let htmlBegin = `
|
||||
<div class="restoolsBBWatchReloadedDialog">
|
||||
<a onclick="window.plugin.restoolsBBWatchReloaded.openPreferences()" title="Settings">Settings</a>
|
||||
|
||||
<table class="styled-table">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -318,8 +329,8 @@ function wrapper(plugin_info)
|
||||
let htmlEnd = `
|
||||
</tbody>
|
||||
</table>` + bestScore + bestScoreVolatiles + `
|
||||
<a onclick="window.plugin.restoolsBBWatchReloaded.resetStorage()" title="Reset local storage (deletes data saved in your browser, do this prior to anomaly, refresh windown for it to take effect)">Reset local storage (refresh window after)</a>
|
||||
<a style="float: right;" onclick="window.plugin.restoolsBBWatchReloaded.getCurrentState()" title="Refresh this dialog window">Refresh this window</a>
|
||||
<a onclick="window.plugin.restoolsBBWatchReloaded.resetStorage()" title="Reset local storage (deletes data saved in your browser, do this prior to anomaly, fully refresh window for it to take effect)">Reset local storage (fully refresh window after)</a>
|
||||
<a style="float: right;" onclick="window.plugin.restoolsBBWatchReloaded.getCurrentState()" title="Refresh this dialog window">Refresh this dialog</a>
|
||||
</div>
|
||||
`;
|
||||
let html = htmlBegin + htmlBody + htmlEnd;
|
||||
@@ -333,6 +344,41 @@ function wrapper(plugin_info)
|
||||
});
|
||||
}
|
||||
|
||||
window.plugin.restoolsBBWatchReloaded.openPreferences = function() {
|
||||
var html =
|
||||
'<div>' +
|
||||
'<table>';
|
||||
|
||||
html +=
|
||||
'<tr>' +
|
||||
'<td>' +
|
||||
'Your timezone shift against local anomaly time: ' +
|
||||
'</td>' +
|
||||
'<td>' +
|
||||
'<input id="timezone_input" size="10" type="number" value="'+ window.plugin.restoolsBBWatchReloaded.timezone + '"/>' +
|
||||
'</td>' +
|
||||
'</tr>' ;
|
||||
|
||||
html +=
|
||||
'</table>' +
|
||||
'</div>' +
|
||||
'<div style="text-align:center">' +
|
||||
'<button type="button" onclick="window.plugin.restoolsBBWatchReloaded.saveTimezone()">Save</button>' +
|
||||
'</div>';
|
||||
dialog({
|
||||
html: html,
|
||||
id: 'plugin_restoolsBBWatchReloaded',
|
||||
title: 'ResTools BB Watch Reloaded - Settings',
|
||||
width: 'auto'
|
||||
});
|
||||
};
|
||||
|
||||
window.plugin.restoolsBBWatchReloaded.saveTimezone = function() {
|
||||
window.plugin.restoolsBBWatchReloaded.timezone = $('#timezone_input').val();
|
||||
localStorage['window.plugin.restoolsBBWatchReloaded.timezone'] = JSON.stringify(window.plugin.restoolsBBWatchReloaded.timezone);
|
||||
};
|
||||
|
||||
|
||||
|
||||
// --- SETUP ---
|
||||
var setup = function()
|
||||
@@ -342,6 +388,9 @@ function wrapper(plugin_info)
|
||||
// Automatic update
|
||||
setTimeout(window.plugin.restoolsBBWatchReloaded.updateCurrentState, 10 * 1000);
|
||||
window.plugin.restoolsBBWatchReloaded.WAVE_PORTALS = window.plugin.restoolsBBWatchReloaded.loadStorage();
|
||||
if (localStorage['window.plugin.restoolsBBWatchReloaded.timezone'] != undefined) {
|
||||
window.plugin.restoolsBBWatchReloaded.timezone = JSON.parse(localStorage['window.plugin.restoolsBBWatchReloaded.timezone']);
|
||||
}
|
||||
console.log("BBWatchReloaded: Loaded previous state");
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user