()
| 189 | |
| 190 | // 判断是支持 |
| 191 | function doesItSupport() { |
| 192 | setDBSite(); // 配置 DBSite 变量对象 |
| 193 | |
| 194 | // 遍历判断是否是某个已支持的网站,顺便直接赋值 |
| 195 | let support = false; |
| 196 | end: |
| 197 | for (let now in DBSite) { // 遍历 对象 |
| 198 | if (DBSite[now].ignore) continue; // 如果是特殊的内置规则(如通用规则)则跳过直接继续下一个循环 |
| 199 | |
| 200 | // 供其他函数在 域名/URL 判断阶段使用 |
| 201 | if (typeof DBSite[now].url == 'function'){ |
| 202 | DBSiteNow = DBSite[now] // 如果是脚本内置规则就没必要深度克隆了(用不上 rule 对象变量,毕竟是可以直接操作自身的) |
| 203 | } else { |
| 204 | DBSiteNow = structuredClone(DBSite[now]) //深度克隆是为了在后续 url 规则中通过操作 rule 对象变量来修改当前网页规则时,不会间接影响到 DBSite[now] 本身 |
| 205 | } |
| 206 | |
| 207 | // 如果是 数组 |
| 208 | if (Array.isArray(DBSite[now].host)) { |
| 209 | |
| 210 | for (let i of DBSite[now].host) { // 遍历 数组 |
| 211 | |
| 212 | // 针对自定义翻页规则中的正则 |
| 213 | if (typeof i === 'string' && i.slice(0,1) === '/') i = new RegExp(i.slice(1,i.length-1)) |
| 214 | if ((i instanceof RegExp && i.test(location.hostname)) || (typeof i === 'string' && i === location.hostname)) { |
| 215 | |
| 216 | if (self != top) {if (!DBSite[now].iframe) continue end;} // 如果当前位于 iframe 框架下,就需要判断是否需要继续执行 |
| 217 | if (DBSite[now].url) { |
| 218 | if (typeof DBSite[now].url == 'function') { |
| 219 | DBSite[now].url(); |
| 220 | } else { // 自定义翻页规则时,因为同域名不同页面 url 分开写,所以如果没找到就需要跳出当前数组循环,继续规则循环 |
| 221 | try { |
| 222 | if (DBSite[now].url.slice(0,1) === '/') { // 如果是正则,则对 URL 路径进行匹配 |
| 223 | if (new RegExp(DBSite[now].url.slice(1,DBSite[now].url.length-1), 'i').test(location.pathname + location.search) === true) {curSite = DBSite[now];} else {if (urlC === true) {support = true;}; break;} |
| 224 | } else { // 如果是函数,那就执行代码(url 规则中可通过操作 rule 这个对象变量来修改当前网页实际应用的规则) |
| 225 | if (new Function('fun','rule', DBSite[now].url)(window.autoPage,DBSiteNow)) {curSite = DBSiteNow;} else {if (urlC === true) {support = true;}; break;} |
| 226 | } |
| 227 | } catch (e) { |
| 228 | console.error('[自动无缝翻页] - 当前网页规则 "url" 匹配出错,请检查:\n', DBSite[now].url + '\n\n', e); |
| 229 | } |
| 230 | } |
| 231 | } else { |
| 232 | curSite = DBSite[now]; |
| 233 | } |
| 234 | support = true; break end; // 如果找到了就退出所有循环 |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // 如果是 正则/字符串 |
| 239 | } else { |
| 240 | // 针对自定义翻页规则中的正则 |
| 241 | if (typeof DBSite[now].host === 'string' && DBSite[now].host.slice(0,1) === '/') DBSite[now].host = new RegExp(DBSite[now].host.slice(1,DBSite[now].host.length-1)) |
| 242 | if ((DBSite[now].host === undefined) || (DBSite[now].host instanceof RegExp && DBSite[now].host.test(location.hostname)) || (typeof DBSite[now].host === 'string' && DBSite[now].host === location.hostname)) { |
| 243 | // 如果没有指定 host 规则,那么默认匹配所有域名(会对所有域名匹配 url 规则判断),可以当成一个简单的外置(自定义)通用规则方案 |
| 244 | |
| 245 | if (self != top) {if (!DBSite[now].iframe) continue;} // 如果当前位于 iframe 框架下,就需要判断是否需要继续执行 |
| 246 | if (DBSite[now].url) { |
| 247 | if (typeof DBSite[now].url == 'function') { |
| 248 | DBSite[now].url(); |
no test coverage detected