yaohuo

妖火评论全显示

当前为 2021-07-16 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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)
})();