MCPcopy
hub / github.com/zxlie/FeHelper / isValidUrl

Function isValidUrl

apps/screenshot/content-script.js:29–52  ·  view source on GitHub ↗

* URL合法性校验 * @param {string} url - 要检查的URL * @returns {boolean} - URL是否合法

(url)

Source from the content-addressed store, hash-verified

27 * @returns {boolean} - URL是否合法
28 */
29 function isValidUrl(url) {
30 // 允许的URL模式
31 const matches = ['http://*/*', 'https://*/*', 'ftp://*/*', 'file://*/*'];
32 // 不允许的URL模式
33 const noMatches = [/^https?:\/\/chrome\.google\.com\/.*$/];
34
35 // 先检查不允许的URL
36 for (let i = 0; i < noMatches.length; i++) {
37 if (noMatches[i].test(url)) {
38 return false;
39 }
40 }
41
42 // 再检查允许的URL
43 for (let i = 0; i < matches.length; i++) {
44 const pattern = matches[i].replace(/\*/g, '.*');
45 const regex = new RegExp('^' + pattern + '$');
46 if (regex.test(url)) {
47 return true;
48 }
49 }
50
51 return false;
52 }
53
54 /**
55 * 释放canvas资源

Callers 1

goCaptureFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected