jcunews

ViolentmonkeyToTampermonkey.hta

Jun 13th, 2020
702
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <!--
  5. ViolentmonkeyToTampermonkey.hta v1.0.1.
  6.  
  7. Requirement: Internet Explorer 8
  8. Note: Save as "ViolentmonkeyToTampermonkey.hta". Not "ViolentmonkeyToTampermonkey.html".
  9.  
  10. Both Tampermonkey and Violentmonkey can import each other's backup data. But Violentmonkey's exported data use different structure where if imported to Tampermonkey, scripts' enabled state, position, storage data, and settings, are lost.
  11.  
  12. This tool converts Violentmonkey backup data folder to Tampermonkey backup data folder so that Violentmonkey backup data can be used by Tampermonkey while preserving script data as much as possible. Full data preserving is not possible due to design difference between the two addons. The backup data folder in this context is the folder which contains the extracted files of the ZIP-ed backup data.
  13.  
  14. Before using this tool, extract the contents of a Violentmonkey ZIP file, then run this tool. The tool will ask for a folder. Select the folder where the extracted files are contained, then press OK. The converted backup data will be placed in a folder named "tampermonkey_from_violentmonkey". Once the conversion process is done, ZIP the contents of that folder (excluding the folder itself), and use that ZIP file as the source data to import from Tampermonkey.
  15.  
  16. Note: the tool may show warning messages stating that it can not find a script storage data. Due to uncommon algorithm used by Violentmonkey, script storage detection is not yet perfect. The script storage data may actually exist but isn't detected by this tool. But most of them should be detectable for now.
  17. -->
  18. <meta charset=utf-8 />
  19. <meta http-equiv="x-ua-compatible" content="IE=8" />
  20. </head>
  21. <body>
  22. <script>
  23. fs = new ActiveXObject("scripting.filesystemobject");
  24. sa = new ActiveXObject("shell.application");
  25. sp = null;
  26. while (true) {
  27.   sp = sa.browseForFolder(0,
  28.     "Select extracted Violentmonkey backup data folder.", 0x8075, sp);
  29.   if (sp === null) close();
  30.   if (fs.fileExists((sp = sp.self.path) + "\\violentmonkey")) break;
  31.   alert("Selected folder is not a valid Violentmonkey backup data folder.");
  32. }
  33. op = "tampermonkey_from_violentmonkey";
  34. if (fs.folderExists(op)) fs.deleteFolder(op);
  35. fs.createFolder(op);
  36. f = fs.openTextFile(sp + "\\violentmonkey");
  37. vm = JSON.parse(f.readall());
  38. f.close();
  39. for (key in vm.scripts) {
  40.   scr = vm.scripts[key];
  41.   f = fs.createTextFile(op + "\\" + key + ".options.json", true);
  42.   f.write(JSON.stringify({
  43.     meta: {modified: scr.lastModified},
  44.     options: {
  45.       check_for_updates: !!scr.config.shouldUpdate,
  46.       override: {
  47.         use_excludes: scr.custom.exclude,
  48.         use_includes: scr.custom.include,
  49.         use_matches: scr.custom.match
  50.       }
  51.     },
  52.     settings: {enabled: !!scr.config.enabled, position: scr.position}
  53.   }));
  54.   f.close();
  55.   n = new RegExp("-0a" + encodeURIComponent(key).replace(/%26/g, "&")
  56.    .replace(/-/g, "-2[dfa]").replace(/\./g, "\\.")
  57.    .replace(/%[0-9A-F]{2}/g, function(s) {
  58.      return "-" + s.substr(1).toLowerCase();
  59.     }) + "-0a$");
  60.   k = "";
  61.   for (val in vm.values) {
  62.     if (n.test(val)) {
  63.       k = val;
  64.       break;
  65.     }
  66.   }
  67.   if (k) {
  68.     f = fs.createTextFile(op + "\\" + key + ".storage.json", true);
  69.     f.write(JSON.stringify({data: vm.values[k]}));
  70.     f.close();
  71.   } else {
  72.     alert("Warning:\n'" + key + "' storage is not found.");
  73.   }
  74.   fs.copyFile(sp + "\\" + key + ".user.js", op + "\\" + key + ".user.js", true);
  75. }
  76. alert("Done");
  77. close();
  78. </script>
  79. </body>
  80. </html>
RAW Paste Data