Greasy Fork

来自缓存

Greasy Fork is available in English.

妖火首页获取热门帖

在妖火论坛首页插入热门帖子列表

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         妖火首页获取热门帖
// @namespace    http://tampermonkey.net/
// @version      1.0.2
// @description  在妖火论坛首页插入热门帖子列表
// @author       SiXi
// @icon         https://yaohuo.me/css/favicon.ico
// @match        *://www.yaohuo.me/
// @match        *://yaohuo.me/
// @match        *://www.yaohuo.me/wapindex.aspx
// @match        *://yaohuo.me/wapindex.aspx
// @grant        GM_xmlhttpRequest
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const hotPostsUrl = 'https://www.yaohuo.me/bbs/book_list_hot.aspx?classid=0&days=1';
    // 发起请求获取热门帖子页面内容
    GM_xmlhttpRequest({
        method: 'GET',
        url: hotPostsUrl,
        onload: function(response) {
            const parser = new DOMParser();
            const doc = parser.parseFromString(response.responseText, 'text/html');
            const posts = doc.querySelectorAll('.listdata.line1, .listdata.line2');

            // 创建一个数组来存储帖子标题和链接
            const postList = [];
            posts.forEach((post, index) => {
                const link = post.querySelector('a.topic-link');
                if (link) {
                    postList.push({
                        title: link.textContent.trim(),
                        href: link.getAttribute('href')
                    });
                }
            });

            // 如果获取到了帖子,则插入到页面中
            if (postList.length > 0) {
                insertHotPosts(postList);
            }
        },
        onerror: function(error) {
            console.error('获取热门帖失败:', error);
        }
    });

    // 插入热门帖子到首页
    function insertHotPosts(postList) {
        const targetScript = document.querySelector('script[src*="/Template/search/index.js"]');
        if (!targetScript) return;

        // 创建热门帖显示位置
        const titleDiv = document.createElement('div');
        titleDiv.className = 'title';
        titleDiv.innerHTML = '【<a class="brackets" href="bbs/book_list_hot.aspx?classid=0&days=1">全站热门</a>】<a href="bbs/book_list_hot.aspx?classid=0&days=3">三天</a><span class="separate"> </span><a href="bbs/book_list_hot.aspx?classid=0&days=7">一周</a>';

        // 创建热门帖列表
        const listDiv = document.createElement('div');
        listDiv.className = 'list';
        postList.forEach((post, index) => {
            const postLink = document.createElement('a');
            postLink.href = post.href;
            postLink.textContent = `${index + 1}.${post.title}`;
            listDiv.appendChild(postLink);
            listDiv.appendChild(document.createElement('br'));
        });

        targetScript.parentNode.insertBefore(titleDiv, targetScript.nextSibling);
        targetScript.parentNode.insertBefore(listDiv, titleDiv.nextSibling);
    }
})();