Alook浏览器的via插件助手(GreasyFork、openuserjs)

a script help alook(ios) install script from greasyfork and openuserjs

  1. // ==UserScript==
  2. // @name Alook浏览器的via插件助手(GreasyFork、openuserjs)
  3. // @namespace http://tampermonkey.net/*
  4. // @version 0.1
  5. // @description a script help alook(ios) install script from greasyfork and openuserjs
  6. // @author Number17831
  7. // @match https://gf.qytechs.cn/*/scripts/*
  8. // @match https://openuserjs.org/scripts/*
  9. // @icon https://www.google.com/s2/favicons?domain=gf.qytechs.cn
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. let isVia = window.via && typeof window.via.addon === "function";
  16. let Base64 = {encode: s=>btoa(unescape(encodeURIComponent(s))), decode: s=>decodeURIComponent(escape(window.atob(s)))};
  17. let zhBase64 = {
  18. encode: function (input) {
  19. let _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  20. let output = "";
  21. let chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  22. let i = 0;
  23. input = this.utf8_encode(input);
  24. while (i < input.length) {
  25. chr1 = input.charCodeAt(i++);
  26. chr2 = input.charCodeAt(i++);
  27. chr3 = input.charCodeAt(i++);
  28. enc1 = chr1 >> 2;
  29. enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
  30. enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
  31. enc4 = chr3 & 63;
  32. if (isNaN(chr2)) { enc3 = enc4 = 64;
  33. } else if (isNaN(chr3)) { enc4 = 64; }
  34. output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
  35. }
  36. return output;
  37. },
  38. utf8_encode: function(_string) {
  39. return _string.replace(/([\u2E80-\u2EFF\u2F00-\u2FDF\u3000-\u303F\u31C0-\u31EF\u3200-\u32FF\u3300-\u33FF\u3400-\u4DBF\u4DC0-\u4DFF\u4E00-\u9FBF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF])/g, str => {
  40. return '\\u' + str.charCodeAt(0).toString(16)
  41. })
  42. }
  43. };
  44.  
  45. function tryGetExec(result, idx, fallback) { if (result.length < idx + 1) return fallback; else return result[idx]; }
  46.  
  47. async function addonApp(scriptUrl) {
  48. let scriptContent = await (await (fetch(scriptUrl))).text();
  49. let version = tryGetExec(/\/\/\s*@version\s*([0-9\.]*)/.exec(scriptContent), 1, "unknown");
  50. let author = tryGetExec(/\/\/\s*@author\s*([^\s]*)/.exec(scriptContent), 1, "unknown");
  51. let name = tryGetExec(/\/\/\s*@name\s*([^\s]*)/.exec(scriptContent), 1, "unknown");
  52. // alook javascript 扩展 匹配类型建议采用链接网址,比域名更精确,但是alook匹配采用正则表达式,普通油猴脚本采用*作为通配符匹配,
  53. // 因此这里做一个简单的转换,把match匹配地址中的 “*” 全部改成标准正则表达式 “.*”
  54. // let match = /\/\/ @match\s*([^\s]*)/.exec(scriptContent)[1];
  55. let match = scriptContent.match(/\/\/\s*@(match|include)\s*([^\s\n]*)/g)
  56. .map(s=>tryGetExec(/\/\/\s*@(match|include)\s*([^\s]*)/.exec(s), 2, "unknown"))
  57. .map(s=>s.replaceAll("*", ".*"))
  58. .join("@@");
  59. let codeStr = Base64.encode(
  60. `
  61. (function (){
  62. ${scriptContent}
  63. })();
  64. `
  65. );
  66. // let codeStr = scriptContent;
  67. var appJson = {
  68. author: name,
  69. id: "1",
  70. runat : 1,
  71. version : version,
  72. name: name,
  73. url: match,
  74. code: codeStr,
  75. };
  76. var appStr = JSON.stringify(appJson);
  77. var addon_result = zhBase64.encode(appStr);
  78. try {
  79. // alert(appStr);
  80. window.via.addon(addon_result);
  81. } catch (error) {
  82. alert(error);
  83. console.log(error);
  84. }
  85. }
  86.  
  87. function FindInstallBtn(selectStr) {
  88.  
  89. // 查找标题元素用到的querySelector字符串
  90. let installBtn = document.querySelector(selectStr);
  91. if (!installBtn) return false;
  92.  
  93. var button = document.createElement("a");
  94. button.append(isVia ? "通过via安装插件" : "当前浏览器不支持via插件安装");
  95. button.className = installBtn.className;
  96. button.style.color = "black";
  97. button.style.background = "lightgreen";
  98. //storyDiv.append(button)
  99. button.onclick = async () => {
  100. // alert("install via plugin by script url: " + installBtn.href);
  101. let url = installBtn.href;
  102. url = prompt("是否安装当前链接所对应的脚本?(注:如果脚本比较大,可能会花一点时间,长时间没有反馈就是安装失败)", url);
  103. if (url) addonApp(url);
  104. };
  105. installBtn.parentNode.insertBefore(button, installBtn.nextSibling);
  106. return true;
  107. };
  108.  
  109. let targets = [
  110. "a.install-link", // Greasy Fork镜像
  111. "a.btn.btn-info[type='text/javascript']", // openuserjs
  112. ];
  113. for (let i = 0; i < targets.length; ++i) {
  114. if (FindInstallBtn(targets[i])) break;
  115. }
  116.  
  117. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址