Skip to content

支持 GM_info.scriptHandler #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bobz25 opened this issue Dec 14, 2022 · 5 comments
Closed

支持 GM_info.scriptHandler #126

bobz25 opened this issue Dec 14, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@bobz25
Copy link

bobz25 commented Dec 14, 2022

希望能够支持 GM_info.scriptHandler,用来处理可能存在的兼容性问题。

其他脚本管理器的结果是返回

Greasemonkey Tampermonkey Violentmonkey

或许本管理器可以返回 Scriptcat

@CodFrm
Copy link
Member

CodFrm commented Dec 15, 2022

支持的呀

// ==UserScript==
// @name         New Userscript
// @namespace    https://bbs.tampermonkey.net.cn/
// @version      0.1.0
// @description  try to take over the world!
// @author       You
// @match        https://bbs.tampermonkey.net.cn/
// ==/UserScript==

console.log(GM_info)

image

@bobz25
Copy link
Author

bobz25 commented Dec 15, 2022

测试了下,总算知道为啥了。
vite-plugin-monkey build 完以后会成为这种格式

// ==UserScript==
// @name               ChatGPT Search
// @namespace          https://greasyfork.org/scripts/456077
// @version            0.7.0
// @author             Zheng Bang-Bo(https://github.com/zhengbangbo)
// @description        ChatGPT answers displayed in sidebar after search (Google, Bing, Baidu, DuckDuckGo and DeepL)
// @match              https://*.google.com/search*
// ==/UserScript==

(function() {
  "use strict";
  var monkeyWindow = window;
  var GM_info = /* @__PURE__ */ (() => monkeyWindow.GM_info)();
  document.createElement("div");
  async function main() {
    console.log(GM_info);
  }
  main().catch((e) => {
    console.log(e);
  });
})();

在 ScriptCat 中会打印 undefined

@CodFrm
Copy link
Member

CodFrm commented Dec 15, 2022

那这应该算是一个bug,我调试一下

@CodFrm CodFrm added the bug Something isn't working label Dec 15, 2022
@CodFrm
Copy link
Member

CodFrm commented Dec 15, 2022

@zhengbangbo
其他脚本管理器在这种情况(grant none 非沙盒模式)也会输出undefined,一时间不知道如何判断,GM_info信息最好不从window上取

// ==UserScript==
// @name               ChatGPT Search
// @namespace          https://greasyfork.org/scripts/456077
// @version            0.7.0
// @author             Zheng Bang-Bo(https://github.com/zhengbangbo)
// @description        ChatGPT answers displayed in sidebar after search (Google, Bing, Baidu, DuckDuckGo and DeepL)
// @match              https://bbs.tampermonkey.net.cn/
// @grant              none
// ==/UserScript==

console.log('ok');
console.log(GM_info);
(function() {
  "use strict";
  var monkeyWindow = window;
  var GM_info = /* @__PURE__ */ (() => monkeyWindow.GM_info)();
  document.createElement("div");
  async function main() {
    console.log(GM_info);
  }
  main().catch((e) => {
    console.log(e);
  });
})();

@CodFrm
Copy link
Member

CodFrm commented Dec 15, 2022

@CodFrm CodFrm closed this as completed Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants