From 0401d5dcc8957cb6680696a2cc209af134e64a2b Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Wed, 30 Oct 2013 06:43:12 +0000 Subject: [PATCH] work in progress - update-check plugin data retrieved - work on comparing with local version info started --- plugins/update-check.user.js | 167 +++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 plugins/update-check.user.js diff --git a/plugins/update-check.user.js b/plugins/update-check.user.js new file mode 100644 index 00000000..29ea1a3a --- /dev/null +++ b/plugins/update-check.user.js @@ -0,0 +1,167 @@ +// ==UserScript== +// @id iitc-plugin-update-check@jonatkins +// @name IITC plugin: Check for updates +// @category Tweaks +// @version 0.1.0.@@DATETIMEVERSION@@ +// @namespace https://github.com/jonatkins/ingress-intel-total-conversion +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ +// @description [@@BUILDNAME@@-@@BUILDDATE@@] Check for updates for IITC and plugins against http://iitc.jonatkins.com/. Can also report status messages for known IITC issues. +// @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.updateCheck = function() {}; + +window.plugin.updateCheck.url = 'http://iitc.jonatkins.com/versioncheck.php?build=@@BUILDNAME@@'; +window.plugin.updateCheck.versionDataLoading = false; + + +window.plugin.updateCheck.versionCompare = function(a,b) { + a = a.split('.'); + b = b.split('.'); + + // adding dummy -1 entries to both split arrays simplifies comparisons + a.push(-1); + b.push(-1); + + var minlen = Math.min(a.length, b.length); + + for (var i=0; i0; + result.upToDate = result.comp==0; + result.localNewer = result.comp<0; + + + } + + if (!result.localVersion) { + + } else if (!result.webVersion) { + } + + return result; +} + + +window.plugin.updateCheck.showReport = function(data) { + var result = 'WORK IN PROGRESS - NOT YET FUNCTIONAL'; + + if (data.error) { + result += '
Error checking for updates
'+data.error+'
'; + } else { + if (data.name) { + result += '
IITC update check: '+data.name+'
'; + } + + if (data.iitc && window.script_info) { + + var compare = window.plugin.updateCheck.compareDetails(data.iitc, window.script_info); + + result += '
IITC Main script: '+JSON.stringify(compare)+'
'; + + } else { + if (!data.iitc) { + result += '
Warning: no version information for main IITC script found in response
'; + } + if (!window.script_info) { + result += '
Warning: your IITC script does not contain version data
'; + } + } + + + } + + dialog({ + width: 500, + title: 'Update check', + html: result + }); +} + + +window.plugin.updateCheck.open = function() { + + // TODO? open a dialog/show a message indicating that the update check is in progress, before the data is loaded? + // TODO? prevent loading the version data every time - cache it, with a user option to force fresh data + + window.plugin.updateCheck.loadVersionData(); +} + + + +window.plugin.updateCheck.setup = function() { + $('#toolbox').append(' Update check'); +}; + +var setup = window.plugin.updateCheck.setup; + +// PLUGIN END ////////////////////////////////////////////////////////// + +@@PLUGINEND@@