本帖最后由 zoenbo 于 2023-6-7 17:46 编辑
我想让所有加载出来的DOM元素节点不要因为向下滚动而被删除,
当翻到8页的时候第一个.page下的.canvasWrapper和.textLayer会被删除,
.page的行内属性data-loaded="true"也会跟着删除掉,
被
这个所代替了~
下边的脚本只能保持.canvasWrapper和.textLayer不被删除,
但不是我要的最终效果,
我想让所有已加载的.page和节点原封不动的保留(不要loadingIcon notVisible出现,也不要让data-loaded="true"消失),
总之要的结果就是不管下翻多少页,往上翻时不用重新加载~
大佬帮帮忙,帮我修改下,我实在是解决不了了~
(改JS的方法会,想用脚本来实现)
@李恒道
页面:http://biaozhun.osta.org.cn/pdfview.html?code=597
// ==UserScript==
// @name Block Node Operations
// @namespace YOU
// @version 1
// @description Block operations on specific nodes in a web page
// @match http://biaozhun.osta.org.cn/pdfview.html?code=*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const observer = new MutationObserver(mutations => {
for (const mutation of mutations) {
if (mutation.type === 'attributes' && mutation.attributeName === 'data-loaded') {
const page = mutation.target.closest('.page');
if (page && !page.getAttribute('data-loaded')) {
console.log("Setting data-loaded attribute to true for .page element");
page.setAttribute('data-loaded', 'true');
}
}
}
});
observer.observe(document.body, { childList: true, subtree: true });
const originRemove = HTMLDivElement.prototype.remove;
const originRemoveChild = HTMLDivElement.prototype.removeChild;
Object.defineProperty(HTMLDivElement.prototype, 'remove', {
value: function () {
if ((this.classList.contains("canvasWrapper") || this.classList.contains("textLayer")) && !this.closest('.page')) {
console.log("Rejected remove", this);
return;
} else {
originRemove.apply(this, arguments);
}
},
configurable: true,
enumerable: true,
writable: true,
});
Object.defineProperty(HTMLDivElement.prototype, 'removeChild', {
value: function (element) {
if ((element.classList.contains("canvasWrapper") || element.classList.contains("textLayer")) && !element.closest('.page')) {
console.log("Rejected removeChild", element);
return;
} else {
originRemoveChild.apply(this, arguments);
}
},
configurable: true,
enumerable: true,
writable: true,
});
})();