Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ext.add("option-migrator", function () {
- function getOpt(info) {
- let _prefix = null;
- function quote(str) {
- return '"' + str.replace(/"/g, '\\"') + '"';
- }
- function descToM(descriptions) {
- return "M({\n" + [desc for each (desc in descriptions)].map(function (desc) {
- return " " +
- (desc.@lang.toString() || "en") + ": " + quote(L(desc.text()));
- }).join(",\n") + "})";
- }
- let bodyText = [option for each (option in info.options.option)].map(function (option) {
- let fullName = option.name.text();
- let [prefix, optionName] = fullName.split(".");
- if (!_prefix)
- _prefix = prefix;
- return util.format(<><![CDATA[
- %s : {
- preset: '',
- description: %s,
- type: %s
- }]]></>.toString(),
- optionName.quote(),
- descToM(option.description),
- option.type.quote());
- }).join(",\n");
- return 'const pOptions = plugins.setupOptions("' + _prefix + '", {' +
- bodyText +
- "}, PLUGIN_INFO);";
- }
- prompt.selector({
- message : "select plugin: ",
- flags : [IGNORE | HIDDEN, 0],
- collection : [[path, util.getLeafNameFromURL(util.pathToURL(path))]
- for ([path] in Iterator(plugins.context))],
- callback : function (i, collections) {
- if (i < 0)
- return;
- let path = collections[i][0];
- let info = plugins.context[path].PLUGIN_INFO;
- let optText = getOpt(info);
- util.message(optText);
- command.setClipboardText(optText);
- alert(optText);
- }
- });
- }, "Option migrator");
Add Comment
Please, Sign In to add comment