(scriptMatchInfo: ScriptMatchInfo)
| 200 | |
| 201 | // 构建userScript注册信息(忽略代码部份) |
| 202 | export 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 | |
| 237 | export function buildScriptRunResourceBasic(script: Script): ScriptRunResource { |
| 238 | const ret: ScriptRunResource = { ...script } as ScriptRunResource; |
no test coverage detected