yaohuo

妖火评论全显示

目前為 2021-07-16 提交的版本,檢視 最新版本

// ==UserScript==
// @name         yaohuo
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  妖火评论全显示
// @author       Polygon
// @match        https://yaohuo.me/bbs-*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function () {
    'use strict';
    let nextPageURL = document.querySelector('.more a').getAttribute('href')
    console.log(nextPageURL)
    console.log(nextPageURL.match(/Total=(\d+)/g)[0].split('=')[1])
    if (parseInt(nextPageURL.match(/Total=(\d+)/g)[0].split('=')[1]) <= 15) {
        return
    }
    // 获取更多评论地址
    let commentURL = location.protocol + '//' + location.host + nextPageURL.replace('page=2', 'page=1')
    // 移除简短评论url 第一个是正文,第二个是评论
    let commentDiv = document.querySelectorAll('.content')[1]
    commentDiv.removeChild(commentDiv.querySelector('.recontent'))
    commentDiv.removeChild(commentDiv.querySelector('.more'))
    let iframe = document.createElement('iframe')
    iframe.id = 'full-comment'
    iframe.src = commentURL
    iframe.width = '100%'
    iframe.setAttribute('frameborder', 'no')
    iframe.setAttribute('scrolling', 'no')
    iframe.setAttribute('border', '0')
    iframe.style = `
        transition: height 0.3s linear;
    `
    commentDiv.appendChild(iframe)
    setInterval(() => {
        try {
            let iframeDocument = document.getElementById('full-comment').contentWindow.document
            let body = iframeDocument.querySelector('body')
            while (true) {
                if (body.firstElementChild.className.search('line') == -1) {
                    body.removeChild(body.firstElementChild)
                } else if (body.lastElementChild.className.search('showpage') == -1) {
                    body.removeChild(body.lastElementChild)
                } else {
                    iframe.height = iframeDocument.body.scrollHeight
                    break
                }
            }
        } catch (error) {
            console.log(error)
        }
    }, 1200)
})();