MCPcopy Create free account
hub / github.com/XIU2/UserScript / aObserver

Function aObserver

TargetBlank.user.js:51–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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})();

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected