Skip to content

Commit 8562d06

Browse files
authored
🧪 parseMetadata 增加 "解析非GM标准UserScript元数据" (#1400)
1 parent 074be01 commit 8562d06

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

src/pkg/utils/script.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,44 @@ console.log('Hello World');
3737
expect(result?.grant).toEqual(["none"]);
3838
});
3939

40+
it.concurrent("解析非GM标准UserScript元数据", () => {
41+
// https://github.com/Tampermonkey/tampermonkey/issues/1326
42+
const code = `
43+
// ==UserScript==
44+
// @name 测试脚本 TEST 💁🏼‍♀️
45+
// @namespace admin@scriptcat.org
46+
// @version -
47+
// @description 这是一个 💁🏼‍♀️ 测试脚本
48+
// @author 测试作者
49+
// @match https://example.com/*
50+
//@require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
51+
// @match https://greasyfork.org/*/scripts*
52+
//@exclude https://greasyfork.org/*/scripts/*
53+
// @grant none
54+
//@downloadURL https://github.com/EvilSpark/LazyScroll/blob/master/LazyScroll.js
55+
// ==/UserScript==
56+
57+
// ==UserScript==
58+
// @match https://no-this-domain.com/*
59+
// ==/UserScript==
60+
61+
console.log('Hello World');
62+
`;
63+
64+
const result = parseMetadata(code);
65+
expect(result).not.toBeNull();
66+
expect(result?.name).toEqual(["测试脚本 TEST 💁🏼‍♀️"]);
67+
expect(result?.namespace).toEqual(["admin@scriptcat.org"]);
68+
expect(result?.version).toEqual(["-"]);
69+
expect(result?.description).toEqual(["这是一个 💁🏼‍♀️ 测试脚本"]);
70+
expect(result?.author).toEqual(["测试作者"]);
71+
expect(result?.match).toEqual(["https://example.com/*", "https://greasyfork.org/*/scripts*"]);
72+
expect(result?.require).toEqual(["https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"]);
73+
expect(result?.exclude).toEqual(["https://greasyfork.org/*/scripts/*"]);
74+
expect(result?.grant).toEqual(["none"]);
75+
expect(result?.downloadurl).toEqual(["https://github.com/EvilSpark/LazyScroll/blob/master/LazyScroll.js"]);
76+
});
77+
4078
it.concurrent("解析最少UserScript元数据", () => {
4179
const code = `
4280
// ==UserScript==

0 commit comments

Comments
 (0)