diff --git a/plugins/score-cycle-times.user.js b/plugins/score-cycle-times.user.js new file mode 100644 index 00000000..60749ea2 --- /dev/null +++ b/plugins/score-cycle-times.user.js @@ -0,0 +1,85 @@ +// ==UserScript== +// @id iitc-plugin-score-cycle-times@jonatkins +// @name IITC plugin: Show scoreboard cycle/checkpoint times +// @category Info +// @version 0.1.0.@@DATETIMEVERSION@@ +// @namespace https://github.com/jonatkins/ingress-intel-total-conversion +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ +// @description [@@BUILDNAME@@-@@BUILDDATE@@] Show the times used for the septicycle and checkpoints for regional scoreboards. +// @include https://www.ingress.com/intel* +// @include http://www.ingress.com/intel* +// @match https://www.ingress.com/intel* +// @match http://www.ingress.com/intel* +// @grant none +// ==/UserScript== + +@@PLUGINSTART@@ + +// PLUGIN START //////////////////////////////////////////////////////// + + +// use own namespace for plugin +window.plugin.scoreCycleTimes = function() {}; + +window.plugin.scoreCycleTimes.CHECKPOINT = 5*60*60; //5 hours per checkpoint +window.plugin.scoreCycleTimes.CYCLE = 7*25*60*60; //7 25 hour 'days' per cycle + + +window.plugin.scoreCycleTimes.setup = function() { + + // add a div to the sidebar, and basic style + $('#sidebar').append('
'); + $('#score_cycle_times_display').css({'color':'#ffce00'}); + + + window.plugin.scoreCycleTimes.update(); +}; + + + +window.plugin.scoreCycleTimes.update = function() { + + // checkpoint and cycle start times are based on a simple modulus of the timestamp + // no special epoch (other than the unix timestamp/javascript's 1970-01-01 00:00 UTC) is required + + // when regional scoreboards were introduced, the first cycle would have started at 2014-01-15 10:00 UTC - but it was + // a few checkpoints in when scores were first added + + var now = new Date().getTime(); + + var cycleStart = Math.floor(now / (window.plugin.scoreCycleTimes.CYCLE*1000)) * (window.plugin.scoreCycleTimes.CYCLE*1000); + var cycleEnd = cycleStart + window.plugin.scoreCycleTimes.CYCLE*1000; + + var checkpointStart = Math.floor(now / (window.plugin.scoreCycleTimes.CHECKPOINT*1000)) * (window.plugin.scoreCycleTimes.CHECKPOINT*1000); + var checkpointEnd = checkpointStart + window.plugin.scoreCycleTimes.CHECKPOINT*1000; + + + var formatRow = function(label,time) { + var timeStr = unixTimeToDateTimeString(time,true); + timeStr = timeStr.replace(/:00.000$/,''); + + return '