楼中楼翻页

This commit is contained in:
xing 2020-07-11 23:20:35 +08:00
parent 67dc71da23
commit ee38a89b09

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name tieba page // @name tieba page
// @namespace https://github.com/fthvgb1/tampermonkey-script // @namespace https://github.com/fthvgb1/tampermonkey-script
// @version 1.006 // @version 1.007
// @author fthvgb1 // @author fthvgb1
// @match https://tieba.baidu.com/* // @match https://tieba.baidu.com/*
// @match https://tiebac.baidu.com/* // @match https://tiebac.baidu.com/*
@ -266,6 +266,66 @@
}) })
} }
function gmPage(url, el, page, call) {
GM_xmlhttpRequest({
method: 'GET',
url: url,
headers: {
"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'
},
onload: function (res) {
let lis = (new DOMParser()).parseFromString(res.responseText, 'text/html');
let tmp = lis.querySelectorAll('li');
let arr = [...tmp];
arr.splice(tmp.length - 1, 1);
if (page === 1 && el.length > 0) {
arr.splice(0, 2);
}
arr.forEach(li => {
let o = JSON.parse(li.getAttribute('data-field'));
let n = {
pid: o.spid,
un: o.user_name
}
let ell = document.createElement('li');
ell.className = 'list_item_floor j_list_item_floor';
ell.setAttribute('data-info', JSON.stringify(n))
ell.setAttribute('pid', o.spid);
let time = li.querySelector('.lzl_time').innerHTML;
let h = li.querySelector('a[class="at j_user_card "]');
let he = `<a href="${h.href}" target="_blank" class="user_name">${h.getAttribute('username') + (h.innerText !== h.getAttribute('username') ? '(' + h.innerText + ')' : '')}</a>`;
let re = li.querySelector('.lzl_content_main');
let rrr = re.querySelector('.at');
let rrrxx = '';
if (rrr) {
rrrxx += `回复 <a href="${rrr.href}">${rrr.innerText}</a> : `
re.removeChild(rrr)
}
rrrxx += re.innerHTML
ell.innerHTML = `
<div class="fmain j_floor_main">
<div class="floor_footer_item">
${he}: <span style="color: #8fa391">${time}</span>
<span class="floor_content">
${rrrxx}
</span>
</div>
</div>
`;
el.append(ell)
})
if (call) {
call()
}
}
});
}
function t() { function t() {
lz(); lz();
@ -309,52 +369,108 @@
let tot = Math.ceil(orgnum / 10); let tot = Math.ceil(orgnum / 10);
let el = a.previousElementSibling; let el = a.previousElementSibling;
a.addEventListener('click', function () { a.addEventListener('click', function () {
let that = this; let that = this;
if (num === orgnum) { if (num === orgnum) {
let url = this.getAttribute('data-url'); let url = this.getAttribute('data-url');
$.get(url, function (rst) { if (num <= 8) {
replayPage({data: {floor_html: rst}}, el, ls => { $.get(url, function (rst) {
ls.splice(0, 2) replayPage({data: {floor_html: rst}}, el, ls => {
ls.splice(0, 2)
that.parentNode.removeChild(that);
});
}); });
if (num <= 8) { return
that.parentNode.removeChild(that); }
} else { if (GM_xmlhttpRequest) {
const tt = Math.ceil((new Date()).getTime());
url = `/p/comment?tid=${kz}&pid=${tid}&pn=1&t=${tt}`;
gmPage(url, el, 1, () => {
num -= 8; num -= 8;
that.innerText = `还有${num}条回复`; that.innerText = `还有${num}条回复`;
if (orgnum > 18) { if (orgnum > 10) {
a.style.display = 'none'; a.style.display = 'none';
tpage(tot, el, (page) => { tpage(tot, el, (page) => {
if (a.style.display !== 'none') { if (a.style.display !== 'none') {
a.style.display = 'none'; a.style.display = 'none';
} }
let url = `/mo/q//flr?fpn=${page}&kz=${kz}&pid=${tid}&is_ajax=1&has_url_param=0&template=lzl`; let tt = Math.ceil((new Date()).getTime());
$.get(url, res => { let url = `/p/comment?tid=${kz}&pid=${tid}&pn=${page}&t=${tt}`;
replayPage(res, el); gmPage(url, el, page, function () {
let l = lo(document, el); let l = lo(document, el);
window.scrollTo({top: l.top - 20, left: 0, behavior: "smooth"}); window.scrollTo({top: l.top - 20, left: 0, behavior: "smooth"});
}) });
}); });
} }
} })
}); } else {
$.get(url, function (rst) {
replayPage({data: {floor_html: rst}}, el, ls => {
ls.splice(0, 2)
});
if (num <= 8) {
that.parentNode.removeChild(that);
} else {
num -= 8;
that.innerText = `还有${num}条回复`;
if (orgnum > 18) {
a.style.display = 'none';
tpage(tot, el, (page) => {
if (a.style.display !== 'none') {
a.style.display = 'none';
}
let url = `/mo/q//flr?fpn=${page}&kz=${kz}&pid=${tid}&is_ajax=1&has_url_param=0&template=lzl`;
$.get(url, res => {
replayPage(res, el);
let l = lo(document, el);
window.scrollTo({top: l.top - 20, left: 0, behavior: "smooth"});
})
});
}
}
});
}
} else { } else {
let url = `/mo/q//flr?fpn=${page}&kz=${kz}&pid=${tid}&is_ajax=1&has_url_param=0&template=lzl`; if (GM_xmlhttpRequest) {
$.get(url, function (res) { const tt = Math.ceil((new Date()).getTime());
replayPage(res, el); url = `/p/comment?tid=${kz}&pid=${tid}&pn=${page}&t=${tt}`;
let i = el.parentNode.querySelector('.pagexx input'); gmPage(url, el, page, () => {
if (i) { let i = el.parentNode.querySelector('.pagexx input');
i.dataset.r = `${page}`; if (i) {
i.type = 'text'; i.dataset.r = `${page}`;
i.value = page + '/' + tot; i.type = 'text';
} i.value = page + '/' + tot;
++page; }
if (num > 10) { ++page;
num -= 10; if (num > 10) {
that.innerText = `还有${num}条回复`; num -= 10;
} else { that.innerText = `还有${num}条回复`;
that.parentNode.removeChild(that); } else {
} that.parentNode.removeChild(that);
}) }
})
} else {
let url = `/mo/q//flr?fpn=${page}&kz=${kz}&pid=${tid}&is_ajax=1&has_url_param=0&template=lzl`;
$.get(url, function (res) {
replayPage(res, el);
let i = el.parentNode.querySelector('.pagexx input');
if (i) {
i.dataset.r = `${page}`;
i.type = 'text';
i.value = page + '/' + tot;
}
++page;
if (num > 10) {
num -= 10;
that.innerText = `还有${num}条回复`;
} else {
that.parentNode.removeChild(that);
}
})
}
} }
}); });
} }