// ==UserScript== // @id iitc-plugin-update-check@jonatkins // @name IITC plugin: Check for updates // @category Misc // @version 0.1.1.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @updateURL @@UPDATEURL@@ // @downloadURL @@DOWNLOADURL@@ // @description [@@BUILDNAME@@-@@BUILDDATE@@] **WORK IN PROGRESS** Check for updates for IITC and plugins against http://iitc.jonatkins.com/. Can also report status messages for known IITC issues. // @include https://*.ingress.com/intel* // @include http://*.ingress.com/intel* // @match https://*.ingress.com/intel* // @match http://*.ingress.com/intel* // @include https://*.ingress.com/mission/* // @include http://*.ingress.com/mission/* // @match https://*.ingress.com/mission/* // @match http://*.ingress.com/mission/* // @grant none // ==/UserScript== @@PLUGINSTART@@ // PLUGIN START //////////////////////////////////////////////////////// // use own namespace for plugin window.plugin.updateCheck = function() {}; window.plugin.updateCheck.versionDataLoading = false; window.plugin.updateCheck.getUrl = function(callback) { var base = window.location.protocol == 'https:' ? 'https://secure.jonatkins.com/iitc' : 'http://iitc.jonatkins.com'; var url = base+'/versioncheck.php' + '?build=@@BUILDNAME@@' + '&mobile='+((typeof android !== 'undefined' && android)?'1':'0') + '&ts='+Date.now(); // append timestamp - ensures no caching of old data, even on mobile with the aggressive cache code if (callback) { url = url + '&callback='+callback } return url; } 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; i'+match[2]+''; } else { return ver; } } window.plugin.updateCheck.compareDetails = function(web_version, script_version) { // compare the local script version data with the website version data // and return an object with the results var result = {}; result.webUrl = web_version.pageUrl; result.downloadUrl = web_version.downloadUrl; result.webVersion = web_version.version; result.localVersion = script_version.script && script_version.script.version; if (result.localVersion && result.webVersion) { result.comp = window.plugin.updateCheck.versionCompare (result.localVersion, result.webVersion); result.outOfDate = result.comp>0; result.upToDate = result.comp==0; result.localNewer = result.comp<0; } var webVerHTML = result.webVersion && window.plugin.updateCheck.versionHTML(result.webVersion); var localVerHTML = result.localVersion && window.plugin.updateCheck.versionHTML(result.localVersion); // var webLinkInstallHTML = ''; // if (result.downloadUrl && result.webUrl) { // webLinkInstallHTML = 'web ' // + 'install'; // } if (!result.localVersion) { result.html = 'version check failed'; } else if (!result.webVersion) { result.html = 'version check failed'; } else if (result.upToDate) { result.html = 'up to date'; } else if (result.outOfDate) { result.html = 'out of date'; } else if (result.localNewer) { result.html = localVerHTML+' is newer than '+webVerHTML+'(?!)'; } else { console.warn ('Unknown case of version combinations!'); result.html = 'version check failed(!?)'; } return result; } window.plugin.updateCheck.showReport = function(data) { var result = 'WORK IN PROGRESS'; if (data.error) { result += '
Error checking for updates
'+data.error+'
'; } else { if (data.name) { result += '
IITC update check: '+data.name+'
'; } if (typeof android !== 'undefined' && android) { // mobile app version check var ourVerCode = android.getVersionCode && android.getVersionCode() || 0; var ourVerName = android.getVersionName && android.getVersionName() || '(unknown)'; if (data.mobile) { var latestVerCode = parseInt(data.mobile.versioncode); var latestVerName = data.mobile.versionstr; var webLink = ''; if (data.mobile.pageurl) webLink = 'web'; var downloadLink = ''; if (data.mobile.downloadurl) downloadLink = 'download'; if (data.mobile.downloadurl && android.updateIitc) downloadLink = 'install'; if (ourVerCode == latestVerCode) { // up to date result += '
IITC Mobile is up to date - version '+ourVerName+' '+webLink+'
'; } else if (ourVerCode < latestVerCode) { // out of date result += '
IITC Mobile is out of date. Current version '+ourVerName+', ' + 'Available version '+latestVerName+'. '+webLink+' '+downloadLink+'
'; } else { // local version newer?! result += '
IITC Mobile version newer than latest on server?! Current version '+ourVerName+', ' + 'Available version '+latestVerName+'.
'; } } else { result += '
Warning: no version data for mobile app found in response
'; } } else { // desktop userscript version check if (data.iitc && window.script_info) { var compare = window.plugin.updateCheck.compareDetails(data.iitc, window.script_info); result += '
IITC Main script: '+compare.html+'
'; } 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
'; } } } if (data.plugins && window.bootPlugins) { var plugins = { upToDate: [], outOfDate: [], other: [] }; if (window.bootPlugins.length == 0) { result += '
  • No plugins installed
  • '; } else { for (var i=0; iweb'); if (downloadlink && p.compare && p.compare.downloadUrl) links.push('download'); //now convert to text links = links && links.join(' ') || '-'; return ''+name+''+statustext+''+links+''; } result += 'Out of date'; for (var i in plugins.outOfDate) { result += formatRow (plugins.outOfDate[i],true,true); } if (plugins.outOfDate.length==0) { result += 'no plugins'; } result += 'Up To Date'; for (var i in plugins.upToDate) { result += formatRow (plugins.upToDate[i],true,false); } if (plugins.upToDate.length==0) { result += 'no plugins'; } result += 'Other'; for (var i in plugins.other) { result += formatRow (plugins.other[i],true,false); } if (plugins.other.length==0) { result += 'no plugins'; } result += ''; } } dialog({ width: 700, 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@@