Guest User

Untitled

a guest
Jul 18th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. ext.add("option-migrator", function () {
  2. function getOpt(info) {
  3. let _prefix = null;
  4.  
  5. function quote(str) {
  6. return '"' + str.replace(/"/g, '\\"') + '"';
  7. }
  8.  
  9. function descToM(descriptions) {
  10. return "M({\n" + [desc for each (desc in descriptions)].map(function (desc) {
  11. return " " +
  12. (desc.@lang.toString() || "en") + ": " + quote(L(desc.text()));
  13. }).join(",\n") + "})";
  14. }
  15.  
  16. let bodyText = [option for each (option in info.options.option)].map(function (option) {
  17. let fullName = option.name.text();
  18. let [prefix, optionName] = fullName.split(".");
  19.  
  20. if (!_prefix)
  21. _prefix = prefix;
  22.  
  23. return util.format(<><![CDATA[
  24. %s : {
  25. preset: '',
  26. description: %s,
  27. type: %s
  28. }]]></>.toString(),
  29. optionName.quote(),
  30. descToM(option.description),
  31. option.type.quote());
  32. }).join(",\n");
  33.  
  34. return 'const pOptions = plugins.setupOptions("' + _prefix + '", {' +
  35. bodyText +
  36. "}, PLUGIN_INFO);";
  37. }
  38.  
  39. prompt.selector({
  40. message : "select plugin: ",
  41. flags : [IGNORE | HIDDEN, 0],
  42. collection : [[path, util.getLeafNameFromURL(util.pathToURL(path))]
  43. for ([path] in Iterator(plugins.context))],
  44. callback : function (i, collections) {
  45. if (i < 0)
  46. return;
  47. let path = collections[i][0];
  48. let info = plugins.context[path].PLUGIN_INFO;
  49. let optText = getOpt(info);
  50. util.message(optText);
  51. command.setClipboardText(optText);
  52. alert(optText);
  53. }
  54. });
  55. }, "Option migrator");
Add Comment
Please, Sign In to add comment