| 358 | |
| 359 | // 新标签页打开链接 |
| 360 | function linksBlank() { |
| 361 | if (location.pathname.indexOf('/settings') > -1) return |
| 362 | document.head.appendChild(document.createElement('base')).target = '_blank'; // 让所有链接默认以新标签页打开 |
| 363 | Array.from(document.links).forEach(function (_this) { |
| 364 | if (_this.onclick || _this.href.slice(0,4) != 'http' || _this.href.indexOf('#;') > -1 || _this.href.indexOf('night/toggle') > -1 || _this.href.indexOf('/favorite') > -1 || _this.href.indexOf('/?tab=') > -1) { |
| 365 | _this.target = '_self' |
| 366 | } |
| 367 | }) |
| 368 | document.querySelectorAll('form').forEach(function (_this) { |
| 369 | if (!_this.target) {_this.target = '_self'} |
| 370 | }); |
| 371 | |
| 372 | const callback = (mutationsList, observer) => { |
| 373 | for (const mutation of mutationsList) { |
| 374 | for (const target of mutation.addedNodes) { |
| 375 | if (target.nodeType != 1) return |
| 376 | if (target.tagName === 'A') { |
| 377 | if (target.onclick || target.href.slice(0,4) != 'http' || target.href.indexOf('#;') > -1 || target.href.indexOf('night/toggle') > -1 || target.href.indexOf('/favorite') > -1) { |
| 378 | target.target = '_self' |
| 379 | } |
| 380 | } else { |
| 381 | document.querySelectorAll('a').forEach(function (_this) { |
| 382 | if (_this.onclick || _this.href.slice(0,4) != 'http' || _this.href.indexOf('#;') > -1 || _this.href.indexOf('night/toggle') > -1 || _this.href.indexOf('/favorite') > -1) { |
| 383 | _this.target = '_self' |
| 384 | } |
| 385 | }); |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | }; |
| 390 | const observer = new MutationObserver(callback); |
| 391 | observer.observe(document, { childList: true, subtree: true }); |
| 392 | } |
| 393 | |
| 394 | |
| 395 | // 添加全站最近更新主题链接 |