extract script version and other data from the tampermonkey/greasemonkey GM_info and pass it through the wrapper function

modify the plugin template code to do the same for plugins - also include the plugin base filename

this is the required data to allow version checks to be performed. it will also allow IITC to know which plugins are installed and active
This commit is contained in:
Jon Atkins
2013-10-28 21:56:36 +00:00
parent 3e272a645c
commit b6eebccca9
2 changed files with 27 additions and 17 deletions

10
main.js
View File

@ -107,7 +107,11 @@ document.getElementsByTagName('body')[0].innerHTML = ''
// putting everything in a wrapper function that in turn is placed in a
// script tag on the website allows us to execute in the sites context
// instead of in the Greasemonkey/Extension/etc. context.
function wrapper() {
function wrapper(info) {
// a cut-down version of GM_info is passed as a parameter to the script
// (not the full GM_info - it contains the ENTIRE script source!)
window.script_info = info;
// LEAFLET PREFER CANVAS ///////////////////////////////////////////////
// Set to true if Leaflet should draw things using Canvas instead of SVG
@ -240,5 +244,7 @@ if(typeof window.plugin !== 'function') window.plugin = function() {};
// inject code into site context
var script = document.createElement('script');
script.appendChild(document.createTextNode('('+ wrapper +')();'));
var info = { buildName: '@@BUILDNAME@@', dateTimeVersion: '@@DATETIMEVERSION@@' };
if (this.GM_info && this.GM_info.script) info.script = { version: GM_info.script.version, name: GM_info.script.name, description: GM_info.script.description };
script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));
(document.body || document.head || document.documentElement).appendChild(script);