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

Function showPager

52pojie-Enhanced.user.js:269–346  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

267
268 // 修改自 https://greasyfork.org/scripts/14178 , https://github.com/machsix/Super-preloader
269 function showPager() {
270 ShowPager = {
271 getFullHref: function (e) {
272 if (e != null && e.nodeType === 1 && e.href && e.href.slice(0,4) === 'http') return e.href;
273 return '';
274 },
275 createDocumentByString: function (e) {
276 if (e) {
277 if ('HTML' !== document.documentElement.nodeName) return (new DOMParser).parseFromString(e, 'application/xhtml+xml');
278 var t;
279 try { t = (new DOMParser).parseFromString(e, 'text/html');} catch (e) {}
280 if (t) return t;
281 if (document.implementation.createHTMLDocument) {
282 t = document.implementation.createHTMLDocument('ADocument');
283 } else {
284 try {((t = document.cloneNode(!1)).appendChild(t.importNode(document.documentElement, !1)), t.documentElement.appendChild(t.createElement('head')), t.documentElement.appendChild(t.createElement('body')));} catch (e) {}
285 }
286 if (t) {
287 var r = document.createRange(),
288 n = r.createContextualFragment(e);
289 r.selectNodeContents(document.body);
290 t.body.appendChild(n);
291 for (var a, o = { TITLE: !0, META: !0, LINK: !0, STYLE: !0, BASE: !0}, i = t.body, s = i.childNodes, c = s.length - 1; c >= 0; c--) o[(a = s[c]).nodeName] && i.removeChild(a);
292 return t;
293 }
294 } else console.error('没有找到要转成 DOM 的字符串');
295 },
296 loadMorePage: function () {
297 if (curSite.pager) {
298 let curPageEle = getElementByXpath(curSite.pager.nextLink);
299 var url = this.getFullHref(curPageEle);
300 //console.log(`${url} ${curPageEle} ${curSite.pageUrl}`);
301 if(url === '') return;
302 if(curSite.pageUrl === url) return;// 不会重复加载相同的页面
303 curSite.pageUrl = url;
304 // 读取下一页的数据
305 curSite.pager.startFilter && curSite.pager.startFilter();
306 GM_xmlhttpRequest({
307 url: url,
308 method: "GET",
309 overrideMimeType: 'text/html; charset=' + (document.characterSet||document.charset||document.inputEncoding),
310 timeout: 5000,
311 onload: function (response) {
312 try {
313 var newBody = ShowPager.createDocumentByString(response.responseText);
314 let pageElems = getAllElements(curSite.pager.pageElement, newBody, newBody);
315 let toElement = getAllElements(curSite.pager.HT_insert[0])[0];
316 if (pageElems.length >= 0) {
317 let addTo = "beforeend";
318 if (curSite.pager.HT_insert[1] == 1) addTo = "beforebegin";
319 // 插入新页面元素
320 pageElems.forEach(function (one) {
321 toElement.insertAdjacentElement(addTo, one);
322 });
323 //删除悬赏贴
324 delateReward();
325 // 替换待替换元素
326 try {

Callers 1

Calls 3

delateRewardFunction · 0.85
getElementByXpathFunction · 0.70
getAllElementsFunction · 0.70

Tested by

no test coverage detected