MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / blackListSelfCheck

Function blackListSelfCheck

src/pkg/utils/match.ts:141–168  ·  view source on GitHub ↗
(blacklist: string[] | null | undefined)

Source from the content-addressed store, hash-verified

139}
140
141export const blackListSelfCheck = (blacklist: string[] | null | undefined) => {
142 blacklist = blacklist || [];
143
144 const scriptUrlPatterns = extractUrlPatterns([...blacklist.map((e) => `@include ${e}`)]);
145 const blackMatch = new UrlMatch<string>();
146 blackMatch.addRules("BK", scriptUrlPatterns);
147
148 for (const line of blacklist) {
149 const templateLine = line.replace(/[*?]/g, (a) => {
150 // ?: 置换成1个英文字母
151 if (a === "?") return String.fromCharCode(randNum(97, 122));
152 // *: 置换成3~5个英文字母
153 const s = [];
154 for (let i = randNum(3, 5); i > 0; i--) {
155 s.push(randNum(97, 122));
156 }
157 return String.fromCharCode(...s);
158 });
159 if (blackMatch.urlMatch(templateLine)[0] !== "BK") {
160 // 无效的复合规则
161 // 生成的字串不能被匹对、例如正则表达式
162 return { ok: false, line };
163 }
164 }
165 // 有效的复合规则
166 // 只包含 match pattern 及 glob pattern
167 return { ok: true };
168};

Callers 1

SettingFunction · 0.90

Calls 5

addRulesMethod · 0.95
urlMatchMethod · 0.95
extractUrlPatternsFunction · 0.90
randNumFunction · 0.90
pushMethod · 0.80

Tested by

no test coverage detected