Skip to content

[v1.4] feat: 支持 @unwrap#1213

Merged
CodFrm merged 17 commits into
scriptscat:release/v1.4from
cyfung1031:pr-unwrap-001
Mar 17, 2026
Merged

[v1.4] feat: 支持 @unwrap#1213
CodFrm merged 17 commits into
scriptscat:release/v1.4from
cyfung1031:pr-unwrap-001

Conversation

@cyfung1031

@cyfung1031 cyfung1031 commented Feb 7, 2026

Copy link
Copy Markdown
Collaborator

文档说明

VM

https://violentmonkey.github.io/api/metadata-block/#unwrap

TM

https://www.tampermonkey.net/documentation.php?locale=en#meta:unwrap

相关历史

简单说明

直接注入,不封装。不使用沙盒。不使用 GM 和 GM API
单纯是利用 脚本管理器 把一些JS代码注入到页面
(注:不跑脚本管理器流程。直接注入即执行。在 @run-at document-start 的设定下会比 @early-start 更优先。这也是其中一个 @unwrap 的价值)

Monaco Editor hint

Screenshot 2026-02-07 at 14 53 50

测试用代码

// ==UserScript==
// @name         A Scriptlet for @unwrap test
// @namespace    none
// @version      2026-02-07
// @description  try to take over the world!
// @author       You
// @match        https://*/*?test_unwrap
// @grant        GM_setValue
// @require      https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js#sha384-vtXRMe3mGCbOeY7l30aIg8H9p3GdeSe4IFlP6G8JMa7o7lXvnz3GFKzPxzJdPfGK
// @unwrap
// ==/UserScript==

var test_global_injection = "success"; 
// User can access the variable "test_global_injection" directly in DevTools

(function () {
    const results = {
        GM: {
            expected: "undefined",
            actual: typeof GM,
        },
        GM_setValue: {
            expected: "undefined",
            actual: typeof GM_setValue,
        },
        jQuery: {
            expected: "function",
            actual: typeof jQuery,
        },
    };

    console.group(
        "%c@unwrap Test",
        "color:#0aa;font-weight:bold"
    );

    const table = {};
    let allPass = true;

    for (const key in results) {
        const { expected, actual } = results[key];
        const pass = expected === actual;
        allPass &&= pass;

        table[key] = {
            Expected: expected,
            Actual: actual,
            Result: pass ? "✅ PASS" : "❌ FAIL",
        };
    }

    console.table(table);

    console.log(
        allPass
            ? "%cAll tests passed ✔"
            : "%cSome tests failed ✘",
        `font-weight:bold;color:${allPass ? "green" : "red"}`
    );

    console.groupEnd();
})();

Screenshot 2026-02-07 at 15 16 26

@CodFrm CodFrm changed the title [v1.3] feat: 支持 @unwrap [v1.4] feat: 支持 @unwrap Feb 12, 2026
@cyfung1031 cyfung1031 changed the base branch from release/v1.3 to release/v1.4 March 15, 2026 04:56
@CodFrm CodFrm requested a review from Copilot March 17, 2026 02:49

This comment was marked as outdated.

cyfung1031 and others added 6 commits March 17, 2026 13:01
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- isScriptletUnwrap / compileScriptletCode 单元测试
- embeddedPatternChecker / embeddedPatternCheckerString 单元测试
- compileInjectionCode unwrap 分支单元测试
- unwrap E2E 测试(GM API 为 undefined、全局变量可访问)
@CodFrm CodFrm merged commit 202b693 into scriptscat:release/v1.4 Mar 17, 2026
3 checks passed
@cyfung1031 cyfung1031 deleted the pr-unwrap-001 branch March 22, 2026 15:50
@cyfung1031

Copy link
Copy Markdown
Collaborator Author

补 PR comments 说明一下

https://sourceforge.net/p/greasemonkey/wiki/Metadata_Block/#unwrap

Screenshot 2026-06-15 at 13 03 36

本 PR 设计完全符合 greasemonkey 说明

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants