diff --git a/build.py b/build.py index 517d945eb..406914b99 100755 --- a/build.py +++ b/build.py @@ -62,12 +62,12 @@ gradleBuildFile = settings.get('gradleBuildFile', 'mobile/build.gradle') # plugin wrapper code snippets. handled as macros, to ensure that -# 1. indentation caused by the "function wrapper()" doesn't apply to the plugin code body -# 2. the wrapper is formatted correctly for removal by the IITC Mobile android app +# indentation caused by the wrapper IIFE doesn't apply to the plugin code body pluginWrapperStart = """ -function wrapper(plugin_info) { +if (typeof window.plugin !== 'function') window.plugin = function() {}; +(function wrapper (plugin_info){ // ensure plugin framework is there, even if iitc is not yet loaded -if(typeof window.plugin !== 'function') window.plugin = function() {}; +if (typeof window.plugin !== 'function') window.plugin = function() {}; //PLUGIN AUTHORS: writing a plugin outside of the IITC build environment? if so, delete these lines!! //(leaving them in place might break the 'About IITC' page or break update checks) @@ -82,17 +82,12 @@ pluginWrapperEnd = """ setup.info = plugin_info; //add the script info data to the function as a property -if(!window.bootPlugins) window.bootPlugins = []; +if (!window.bootPlugins) window.bootPlugins = []; window.bootPlugins.push(setup); -// if IITC has already booted, immediately run the 'setup' function -if(window.iitcLoaded && typeof setup === 'function') setup(); -} // wrapper end -// inject code into site context -var script = document.createElement('script'); -var info = {}; -if (typeof GM_info !== 'undefined' && GM_info && 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); +if (window.iitcLoaded && typeof setup === 'function') setup(); +})({ script: typeof GM_info !== 'undefined' && GM_info.script && { + version: GM_info.script.version, name: GM_info.script.name, description: GM_info.script.description +}})// wrapper end """ diff --git a/main.js b/main.js index 9b11e97f2..67ad2783f 100644 --- a/main.js +++ b/main.js @@ -95,13 +95,9 @@ document.body.innerHTML = '' // avoid error by stock JS + '
'; -// putting everything in a wrapper function that in turn is placed in a -// script tag on the website allows us to execute in the site’s context -// instead of in the Greasemonkey/Extension/etc. context. -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; + +// anonymous function wrapper for the code - any variables/functions not placed into 'window' will be private +(function(info){ @@ -202,17 +198,21 @@ window.overlayStatus = {}; // plugin framework. Plugins may load earlier than iitc, so don’t // overwrite data -if(typeof window.plugin !== 'function') window.plugin = function() {}; +if (typeof window.plugin !== 'function') window.plugin = function() {}; + +// (not saving the full GM_info - it contains the ENTIRE script source!) +window.script_info = info; +if (typeof GM_info !== 'undefined') { + info.script = { + version: GM_info.script.version, + name: GM_info.script.name, + description: GM_info.script.description, + }; +} @@INJECTCODE@@ -} // end of wrapper - -// inject code into site context -var script = document.createElement('script'); -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); +})({ buildName: '@@BUILDNAME@@', dateTimeVersion: '@@DATETIMEVERSION@@' }); +// end of wrapper diff --git a/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_FileManager.java b/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_FileManager.java index 4db767efe..cb3e576f7 100644 --- a/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_FileManager.java +++ b/mobile/app/src/main/java/org/exarhteam/iitc_mobile/IITC_FileManager.java @@ -46,10 +46,6 @@ public class IITC_FileManager { private static final WebResourceResponse EMPTY = new WebResourceResponse("text/plain", "UTF-8", new ByteArrayInputStream("".getBytes())); - private static final String WRAPPER_NEW = "wrapper(info);"; - private static final String WRAPPER_OLD = - "script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));\n" - + "(document.body || document.head || document.documentElement).appendChild(script);"; // update interval is 2 days by default private long mUpdateInterval = 1000 * 60 * 60 * 24 * 7; @@ -213,9 +209,7 @@ private InputStream prepareUserScript(final InputStream stream) { final HashMap