yaohuo

妖火评论全显示

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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)
})();