-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
better plugin wrapper #358
base: master
Are you sure you want to change the base?
Conversation
Use `unsafeWindow`, thus no need to 'inject script in site context' anymore. - wrapper is simpler now - no need to cut it out in mobile app (but we keep that code for all legacy plugins) - whole `scriptMetaStr` is added to plugin_info, to be able to analyse more properties - it's easier to debug plugins now To set breakpoints switch to Web Developer Tools' Debugger/Sources tab and find related script in Tampermonkey's list of `userscript.html?id=<guid>` - it's possible to use GM_* functions directly (not in mobile app, for now) - https://wiki.greasespot.net/Greasemonkey_Manual:API - https://www.tampermonkey.net/documentation.php
} | ||
setup.info = plugin_info; | ||
(window.bootPlugins = window.bootPlugins || []).push(setup); | ||
if (window.iitcLoaded) { setup(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps better expose this:
function safeSetup (setup) { |
Otherwise we would need special handling to see such plugins in About:
window.aboutIITC = 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) | ||
plugin_info.buildName = '@build_name@'; | ||
plugin_info.dateTimeVersion = '@build_date@'; | ||
plugin_info.pluginId = '@plugin_id@'; | ||
//END PLUGIN AUTHORS NOTE | ||
// END PLUGIN AUTHORS NOTE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can avoid this, if we add this info to meta block, see #242.
pluginwrapper.py
Outdated
function wrapper(plugin_info) { | ||
// ensure plugin framework is there, even if iitc is not yet loaded | ||
if(typeof window.plugin !== 'function') window.plugin = function() {}; | ||
var plugin_info = (typeof GM_info === 'undefined') ? {} : (function (s) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we should rely on GM_info
definition, but iOS is not ready: HubertZhang/IITC-Mobile#1
Unfortunately we still cannot avoid script injecting for Greasemonkey (and IITC-Button). window = ... It'd be possible to replace it with local variable, but it's not enough for good compatibility with all existing 3rd-party plugins: we also need to replace global. I do not know it it ever possible. So for Greasemonkey I have to restore previous method involving script injection. |
a34b800
to
7b9edd5
Compare
I tried to use // ...
script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));
if (info.script && info.script.name)
script.appendChild(document.createTextNode(`//# sourceURL=${encodeURIComponent(info.script.name)}`));
(document.body || document.head || document.documentElement).appendChild(script); I guess this is not compatible with IITC Mobile but the inserted script is correctly listed in source (from intel.ingress.com) (firefox: violent/grease monkey) I used Edit: Possible workaround for mobile // if on last IITC mobile, will be replaced by wrapper(info)
var mobile = `script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));
(document.body || document.head || document.documentElement).appendChild(script);`;
if (mobile.startsWith('script')) {
script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));
if (info.script && info.script.name)
script.appendChild(document.createTextNode('//# sourceURL=' + encodeURIComponent(info.script.name)));
(document.body || document.head || document.documentElement).appendChild(script);
} else {
// mobile string
wrapper(info);
} |
Use
unsafeWindow
, thus no need to 'inject script in site context' anymore.wrapper is simpler nowJust modernized a bit.
Main goal: avoid script re-injection if main context is directly accessible (like in Tampermonkey, Violentmonkey, and mobile app).
To set breakpoints switch to Web Developer Tools' Debugger/Sources tab
and find related script in Tampermonkey's list of
userscript.html?id=<guid>
(but we keep that code for all legacy plugins)
it's possible to use GM_* functions directly (can't put code outside of wrapper with new build system #354)still not possible in some environments, so stick to build_plugin.py: some code can be placed outside of wrapper #356
in unsupported environments (Greasemonkey, IITC-Button) nothing changed - previous injection-method is used
whole
scriptMetaStr
is added to plugin_info, to be able to analyse more properties (Scripts metadata processing (proof-of-concept) #242)New wrapper is checked with major usescript managers (Tampermonkey, Greasemonkey, Violentmonkey), and is compatible with plugins embedding old wrapper.
TODO:
More tests needed with misc plugins, testing different apis (such as XHR)https://web.archive.org/web/20141008055234/http://www.oreillynet.com/lpt/a/6257
IITC Button is not ready yet: Expose unsafeWindow to plugins IITC-Button#32That can be used for easy updating of embedded wrapper.
plugin_info
window
.But this also can be done manually, so probably not
setup
arguments.We could pass iitc api as argument. And may be something other, e.g. logger object
This change is