| 49 | |
| 50 | // 针对动态加载内容中的 a 标签 |
| 51 | function aObserver() { |
| 52 | const callback = (mutationsList, observer) => { |
| 53 | for (const mutation of mutationsList) { |
| 54 | for (const target of mutation.addedNodes) { |
| 55 | if (target.nodeType != 1) return |
| 56 | if (target.tagName === 'A') { |
| 57 | if (target.onclick || target.href.slice(0,4) != 'http' || target.getAttribute('href').slice(0,1) === '#') { |
| 58 | target.target = '_self' |
| 59 | } |
| 60 | } else { |
| 61 | document.querySelectorAll('a').forEach(function (_this) { |
| 62 | if (_this.onclick || _this.href.slice(0,4) != 'http' || _this.getAttribute('href').slice(0,1) === '#') { |
| 63 | _this.target = '_self' |
| 64 | } |
| 65 | }); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | }; |
| 70 | const observer = new MutationObserver(callback); |
| 71 | observer.observe(document, { childList: true, subtree: true }); |
| 72 | } |
| 73 | })(); |