Skip to content

Commit 5b9e9c9

Browse files
committed
新增 [fun.cleanuEvent()] 内置函数(用于清理目标元素绑定的事件)
1 parent 72d643c commit 5b9e9c9

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

Autopage.user.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @name:zh-CN 自动无缝翻页
44
// @name:zh-TW 自動無縫翻頁
55
// @name:en AutoPager
6-
// @version 6.5.12
6+
// @version 6.5.13
77
// @author X.I.U
88
// @description ⭐无缝加载 下一页内容 至网页底部(类似瀑布流)⭐,目前支持:【所有「Discuz!、Flarum、phpBB、Xiuno、XenForo、NexusPHP...」论坛】【百度、谷歌(Google)、必应(Bing)、搜狗、微信、360、Yahoo、Yandex 等搜索引擎...】、贴吧、豆瓣、知乎、B 站(bilibili)、NGA、V2EX、煎蛋网、龙的天空、起点中文、千图网、千库网、Pixabay、Pixiv、3DM、游侠网、游民星空、NexusMods、Steam 创意工坊、CS.RIN.RU、RuTracker、BT之家、萌番组、动漫花园、樱花动漫、爱恋动漫、AGE 动漫、Nyaa、SrkBT、RARBG、SubHD、423Down、不死鸟、扩展迷、小众软件、【动漫狂、动漫屋、漫画猫、漫画屋、漫画 DB、动漫之家、HiComic、Mangabz、Xmanhua 等漫画网站...】、PubMed、Z-Library、GreasyFork、Github、StackOverflow(以上仅一小部分,更多的写不下了...
99
// @description:zh-TW ⭐無縫加載 下一頁內容 至網頁底部(類似瀑布流)⭐,支持各論壇、社交、遊戲、漫畫、小說、學術、搜索引擎(Google、Bing、Yahoo...) 等網站~
@@ -126,7 +126,7 @@
126126
loadMoreExclude1 = ['.smzdm.com','stackoverflow.com'],
127127
loadMoreExclude2 = ['.steampowered.com','.zcool.com.cn'],
128128
menuId = [], webType = 0, curSite = {SiteTypeID: 0}, DBSite, DBSite2, pausePage = true, pageNum = {now: 1, _now: 1}, urlC = false, nowLocation = '', lp = location.pathname, scriptHandler;
129-
window.autoPage = {lp: ()=>location.pathname, indexOF: indexOF, isMobile: isMobile, isUrlC: isUrlC, blank: forceTarget, getAll: getAll, getOne: getOne, getAllXpath: getAllXpath, getXpath: getXpath, getAllCSS: getAllCSS, getCSS: getCSS, getNextE: getNextE, getNextEP: getNextEP, getNextSP: getNextSP, getNextEPN: getNextEPN, getNextUPN: getNextUPN, getNextUP: getNextUP, getNextF: getNextF, getSearch: getSearch, getCookie: getCookie, insStyle: insStyle, insScript: insScript, src_bF: src_bF, xs_bF: xs_bF}
129+
window.autoPage = {lp: ()=>location.pathname, indexOF: indexOF, isMobile: isMobile, isUrlC: isUrlC, blank: forceTarget, getAll: getAll, getOne: getOne, getAllXpath: getAllXpath, getXpath: getXpath, getAllCSS: getAllCSS, getCSS: getCSS, getNextE: getNextE, getNextEP: getNextEP, getNextSP: getNextSP, getNextEPN: getNextEPN, getNextUPN: getNextUPN, getNextUP: getNextUP, getNextF: getNextF, getSearch: getSearch, getCookie: getCookie, insStyle: insStyle, insScript: insScript, cleanuEvent: cleanuEvent, src_bF: src_bF, xs_bF: xs_bF}
130130
if (typeof GM_info != 'undefined') {scriptHandler = GM_info.scriptHandler;} else if (typeof GM != 'undefined' && typeof GM.info != 'undefined') {scriptHandler = GM.info.scriptHandler;} else {scriptHandler = '';}
131131
for (let i=0;i<menuAll.length;i++){ // 如果读取到的值为 null 就写入默认值
132132
if (GM_getValue(menuAll[i][0]) == null){GM_setValue(menuAll[i][0], menuAll[i][3])};
@@ -2641,6 +2641,22 @@ function: {
26412641
});
26422642
}
26432643
}
2644+
2645+
// 清理元素上绑定的事件(不包括父元素上监听的事件委托)
2646+
// css 为元素选择器(也支持 Xpath)
2647+
// delay 为延迟时间,确保其放在 url 规则中执行时网页已经加载完成
2648+
// mode 为 0 时清理全部,为 1 时额外清理 onclick 属性,为 2 时添加空点击事件并阻止冒泡
2649+
function cleanuEvent(css, delay = 0, mode = -1) {
2650+
setTimeout(()=>{
2651+
getAll(css).forEach(function (a) {
2652+
const clonedLink = a.cloneNode(true); // 克隆原元素
2653+
if (mode == 0 || mode == 1) {if (clonedLink.getAttribute('onclick') != undefined) {clonedLink.removeAttribute('onclick')}} // 清理 onclick 属性
2654+
if (mode == 0 || mode == 2) clonedLink.addEventListener('click', function(e) {e.stopPropagation();}); // 添加空点击事件并阻止冒泡(避免父元素事件委托捕获该元素的点击事件)
2655+
a.insertAdjacentElement('afterend', clonedLink); // 把克隆的元素插入原元素后面
2656+
a.remove(); // 删除原元素
2657+
}, delay);
2658+
})
2659+
}
26442660
// 初始化事件
26452661
/*function initEvent() {
26462662
if (curSite.initE[1] == undefined) curSite.initE[1] = 500;

0 commit comments

Comments
 (0)