MCPcopy Index your code
hub / github.com/XIU2/UserScript / cleanuEvent

Function cleanuEvent

Autopage.user.js:2492–2502  ·  view source on GitHub ↗
(css, delay = 0, mode = -1)

Source from the content-addressed store, hash-verified

2490 // delay 为延迟时间,确保其放在 url 规则中执行时网页已经加载完成
2491 // mode 为 0 时清理全部,为 1 时额外清理 onclick 属性,为 2 时添加空点击事件并阻止冒泡
2492 function cleanuEvent(css, delay = 0, mode = -1) {
2493 setTimeout(()=>{
2494 getAll(css).forEach(function (a) {
2495 const clonedLink = a.cloneNode(true); // 克隆原元素
2496 if (mode == 0 || mode == 1) {if (clonedLink.getAttribute('onclick') != undefined) {clonedLink.removeAttribute('onclick')}} // 清理 onclick 属性
2497 if (mode == 0 || mode == 2) clonedLink.addEventListener('click', function(e) {e.stopPropagation();}); // 添加空点击事件并阻止冒泡(避免父元素事件委托捕获该元素的点击事件)
2498 a.insertAdjacentElement('afterend', clonedLink); // 把克隆的元素插入原元素后面
2499 a.remove(); // 删除原元素
2500 }, delay);
2501 })
2502 }
2503 // 初始化事件
2504 /*function initEvent() {
2505 if (curSite.initE[1] == undefined) curSite.initE[1] = 500;

Callers

nothing calls this directly

Calls 1

getAllFunction · 0.85

Tested by

no test coverage detected