diff --git a/RestoolsBBWatchReloaded.js b/RestoolsBBWatchReloaded.js index aa19bbc..f6e125a 100644 --- a/RestoolsBBWatchReloaded.js +++ b/RestoolsBBWatchReloaded.js @@ -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 = `
+ Settings + @@ -318,8 +329,8 @@ function wrapper(plugin_info) let htmlEnd = `
` + bestScore + bestScoreVolatiles + ` - Reset local storage (refresh window after) - Refresh this window + Reset local storage (fully refresh window after) + Refresh this dialog
`; let html = htmlBegin + htmlBody + htmlEnd; @@ -333,6 +344,41 @@ function wrapper(plugin_info) }); } + window.plugin.restoolsBBWatchReloaded.openPreferences = function() { + var html = + '
' + + ''; + + html += + '' + + '' + + '' + + '' ; + + html += + '
' + + 'Your timezone shift against local anomaly time: ' + + '' + + '' + + '
' + + '
' + + '
' + + '' + + '
'; + 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");