MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / __methodInject__

Function __methodInject__

src/app/service/content/create_context.ts:69–85  ·  view source on GitHub ↗
(grant: string)

Source from the content-addressed store, hash-verified

67 });
68 const grantedAPIs: { [key: string]: any } = Object.create(null);
69 const __methodInject__ = (grant: string): boolean => {
70 const grantSet: Set<string> = context.grantSet;
71 const s = GMContextApiGet(grant);
72 if (!s) return false; // @grant 的定义未实现,略过 (返回 false 表示 @grant 不存在)
73 if (grantSet.has(grant)) return true; // 重复的@grant,略过 (返回 true 表示 @grant 存在)
74 grantSet.add(grant);
75 for (const { fnKey, api, param } of s) {
76 grantedAPIs[fnKey] = api.bind(context);
77 const depend = param?.depend;
78 if (depend) {
79 for (const grant of depend) {
80 __methodInject__(grant);
81 }
82 }
83 }
84 return true;
85 };
86 for (const grant of scriptGrants) {
87 // GM. 与 GM_ 都需要注入
88 __methodInject__(grant);

Callers 1

createContextFunction · 0.85

Calls 3

GMContextApiGetFunction · 0.90
addMethod · 0.80
hasMethod · 0.65

Tested by

no test coverage detected