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

Function getUserScriptRegister

src/app/service/service_worker/utils.ts:202–235  ·  view source on GitHub ↗
(scriptMatchInfo: ScriptMatchInfo)

Source from the content-addressed store, hash-verified

200
201// 构建userScript注册信息(忽略代码部份)
202export function getUserScriptRegister(scriptMatchInfo: ScriptMatchInfo) {
203 const { matches, includeGlobs } = getApiMatchesAndGlobs(scriptMatchInfo.scriptUrlPatterns);
204
205 const excludeMatches = toUniquePatternStrings(
206 scriptMatchInfo.scriptUrlPatterns.filter((e) => e.ruleType === RuleType.MATCH_EXCLUDE)
207 );
208 const excludeGlobs = toUniquePatternStrings(
209 scriptMatchInfo.scriptUrlPatterns.filter((e) => e.ruleType === RuleType.GLOB_EXCLUDE)
210 );
211
212 const registerScript: chrome.userScripts.RegisteredUserScript = {
213 id: scriptMatchInfo.uuid,
214 js: [{ code: "" }],
215 matches: matches, // primary
216 includeGlobs: includeGlobs, // includeGlobs applied after matches
217 excludeMatches: excludeMatches,
218 excludeGlobs: excludeGlobs,
219 allFrames: !scriptMatchInfo.metadata["noframes"],
220 world: "MAIN",
221 };
222
223 if (isInjectIntoContent(scriptMatchInfo.metadata)) {
224 // 需要注入到content script的脚本
225 registerScript.world = "USER_SCRIPT";
226 }
227
228 if (scriptMatchInfo.metadata["run-at"]) {
229 registerScript.runAt = getRunAt(scriptMatchInfo.metadata["run-at"]);
230 }
231
232 return {
233 registerScript,
234 };
235}
236
237export function buildScriptRunResourceBasic(script: Script): ScriptRunResource {
238 const ret: ScriptRunResource = { ...script } as ScriptRunResource;

Callers 2

utils.test.tsFile · 0.90

Calls 4

getApiMatchesAndGlobsFunction · 0.90
toUniquePatternStringsFunction · 0.90
isInjectIntoContentFunction · 0.90
getRunAtFunction · 0.85

Tested by

no test coverage detected