Skip to content

Commit

Permalink
Scripts metadata processing
Browse files Browse the repository at this point in the history
- simplify plugins info processing assuming that GM_info is correctly passed
  by userscript manager (previously iOS app had issues)
- wrapper: remove block with (confusing) message for plugins authors
- put extra data into userscript header, which is available thru in `GM_info.scriptMetaStr`
  (passed to wrapper function as field of `plugin_info` arg)
  Currently that data is used only in About IITC window, to highlight non-standard plugins.
  • Loading branch information
johndoe committed Mar 10, 2020
1 parent 5b2eca4 commit 95c6f4d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 39 deletions.
2 changes: 2 additions & 0 deletions build_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def append_line(key, value):
line = line.replace(value, 'IITC plugin: ' + value)
meta.append(line)

append_line('build', settings.build_name)
append_line('date', settings.build_date)
append_line('id', plugin_name)
append_line('namespace', settings.namespace)

Expand Down
62 changes: 30 additions & 32 deletions core/code/utils_misc.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
// UTILS + MISC ///////////////////////////////////////////////////////

window.aboutIITC = function () {
// Plugins metadata come from 2 sources:
// - buildName, pluginId, dateTimeVersion: inserted in plugin body by build script
// (only standard plugins)
// - script.name/version/description: from GM_info object, passed to wrapper
// `script` may be not available if userscript manager does not provede GM_info
// (atm: IITC-Mobile for iOS)
var pluginsInfo = window.bootPlugins.info;
var iitc = script_info;
var iitcVersion = (iitc.script && iitc.script.version || iitc.dateTimeVersion) + ' [' + iitc.buildName + ']';
// Plugins metadata come from GM_info object, collected in wrapper.
// May not be not available if userscript manager does not provede GM_info
// (atm: IITC-Mobile for iOS)
// - script.name/version/description: avalable directly
// - scriptMetaStr: can be parsed for additional properties (such as @category, @author, etc)
function parseMeta (str) {
var re = /\s*\/\/\s*@(\w+)\s+(.+)$/;
var meta = str.split('\n').map(function (s) {
return s.match(re);
}).filter(function (a) { return a; });
var data = {};
meta.forEach(function (a) { data[a[1]] = a[2].trim(); });
return data;
}

var iitc = L.extend(parseMeta(script_info.scriptMetaStr), script_info.script);
var iitcVersion = (iitc.version) + ' [' + iitc.build + ']';
function prepData (info,idx) { // try to gather plugin metadata from both sources
var data = {
build: info.buildName,
name: info.pluginId,
date: info.dateTimeVersion,
error: info.error
};
var script = info.script;
if (script) {
if (typeof script.name === 'string') { // cut non-informative name part
data.name = script.name.replace(/^IITC plugin: /,'');
}
data.version = script.version;
data.description = script.description;
var data = info.script;
if (info.scriptMetaStr) {
data = L.extend({}, parseMeta(info.scriptMetaStr), data);
}
if (!data.name) {
if (iitc.script) { // check if GM_info is available
data.name = '[unknown plugin: index ' + idx + ']';
data.description = "this plugin does not have proper wrapper; report to it's author";
} else { // userscript manager fault
data.name = '[3rd-party plugin: index ' + idx + ']';
}
data.error = info.error;
if (typeof data.name === 'string') {
// cut non-informative name part
data.name = data.name.replace(/^IITC plugin: /,'');
} else {
data.name = '[unknown plugin: index ' + idx + ']';
data.description = "this plugin does not have proper wrapper; report to it's author";
}
return data;
}
var extra = iitc.script && iitc.script.version.match(/^\d+\.\d+\.\d+(\..+)$/);
var extra = iitc.version.match(/^\d+\.\d+\.\d+(\..+)$/);
extra = extra && extra[1];
function formatVerInfo (p) {
if (p.version && extra) {
Expand All @@ -56,15 +54,15 @@ window.aboutIITC = function () {
});
}
}
var plugins = pluginsInfo.map(prepData)
var plugins = window.bootPlugins.info.map(prepData)
.sort(function (a,b) { return a.name > b.name ? 1 : -1; })
.map(function (p) {
p.style = '';
p.description = p.description || '';
if (p.error) {
p.style += 'text-decoration:line-through;';
p.description = p.error;
} else if (p.build === iitc.buildName && p.date === iitc.dateTimeVersion) { // is standard plugin
} else if (p.build === iitc.build && p.date === iitc.date) { // is standard plugin
p.style += 'color:darkgray;';
}
p.verinfo = formatVerInfo(p) || '';
Expand Down
7 changes: 0 additions & 7 deletions pluginwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
return {scriptMetaStr:GM_info.scriptMetaStr, script:s};
}({}));
// 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
window = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window;
// ensure plugin framework is there, even if iitc is not yet loaded
window.plugin = window.plugin || function () {};
Expand Down

0 comments on commit 95c6f4d

Please sign in to comment.