diff --git a/tieba page.js b/tieba page.js index 025f948..2a8ace3 100644 --- a/tieba page.js +++ b/tieba page.js @@ -1,7 +1,7 @@ // ==UserScript== // @name tieba page // @namespace https://github.com/fthvgb1/tampermonkey-script -// @version 1.006 +// @version 1.007 // @author fthvgb1 // @match https://tieba.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 = `${h.getAttribute('username') + (h.innerText !== h.getAttribute('username') ? '(' + h.innerText + ')' : '')}`; + let re = li.querySelector('.lzl_content_main'); + + let rrr = re.querySelector('.at'); + let rrrxx = ''; + if (rrr) { + rrrxx += `回复 ${rrr.innerText} : ` + re.removeChild(rrr) + } + rrrxx += re.innerHTML + ell.innerHTML = ` +
+ +
+ `; + el.append(ell) + + }) + if (call) { + call() + } + } + }); + } + function t() { lz(); @@ -309,52 +369,108 @@ let tot = Math.ceil(orgnum / 10); let el = a.previousElementSibling; a.addEventListener('click', function () { + let that = this; if (num === orgnum) { let url = this.getAttribute('data-url'); - $.get(url, function (rst) { - replayPage({data: {floor_html: rst}}, el, ls => { - ls.splice(0, 2) + if (num <= 8) { + $.get(url, function (rst) { + replayPage({data: {floor_html: rst}}, el, ls => { + ls.splice(0, 2) + that.parentNode.removeChild(that); + }); }); - if (num <= 8) { - that.parentNode.removeChild(that); - } else { + return + } + 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; that.innerText = `还有${num}条回复`; - if (orgnum > 18) { + if (orgnum > 10) { 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 tt = Math.ceil((new Date()).getTime()); + let url = `/p/comment?tid=${kz}&pid=${tid}&pn=${page}&t=${tt}`; + gmPage(url, el, page, function () { let l = lo(document, el); 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 { - 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); - } - }) + if (GM_xmlhttpRequest) { + const tt = Math.ceil((new Date()).getTime()); + url = `/p/comment?tid=${kz}&pid=${tid}&pn=${page}&t=${tt}`; + gmPage(url, el, page, () => { + 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); + } + }) + } 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); + } + }) + } } }); }