立即注册 登录
GameMale 返回首页

咸鱼鱼的个人空间 https://www.gamemale.com/?723150 [收藏] [复制] [RSS]

日志

GM论坛历史回帖标记

热度 191已有 370 次阅读2025-1-2 18:59 |系统分类:纯水(首页不显示)

// ==UserScript==
// @name         GM论坛历史回帖标记
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  根据 fid 自动跳转到上次访问的 GameMale 论坛页面
// @icon         https://www.gamemale.com/template/mwt2/extend/img/favicon.ico
// @author       Your Name
// @match        https://www.gamemale.com/forum.php*
// @match        https://www.gamemale.com/forum-*-*.html
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // 获取当前页面的 fid
    function getFidFromUrl() {
        const url = window.location.href;
        const match = url.match(/forum-(\d+)-\d+\.html/);
        return match ? match[1] : null;
    }

    // 获取当前页面的 URL 参数
    function getUrlParams() {
        return new URLSearchParams(window.location.search);
    }

    // 存储 fid 和 page 到 localStorage
    function storeFidAndPage(fid, page) {
        if (!fid || !page) return;

        try {
            // 从 localStorage 中获取存储的 fid-page 映射
            const fidPageMap = JSON.parse(localStorage.getItem('fidPageMap')) || {};
            // 更新当前 fid 对应的 page
            fidPageMap[fid] = page;
            // 存储回 localStorage
            localStorage.setItem('fidPageMap', JSON.stringify(fidPageMap));
            console.log(`Stored fid=${fid}, page=${page}`);
        } catch (error) {
            console.error('Failed to store fid and page:', error);
        }
    }

    // 根据 fid 跳转到对应的上次存储的页数
    function redirectToLastPage(fid) {
        if (!fid) return;

        try {
            // 获取上次存储的 fid-page 映射
            const fidPageMap = JSON.parse(localStorage.getItem('fidPageMap')) || {};
            const lastPage = fidPageMap[fid];

            if (lastPage) {
                // 构造跳转 URL
                const redirectUrl = `https://www.gamemale.com/forum.php?mod=forumdisplay&filter=author&orderby=dateline&fid=${fid}&page=${lastPage}`;
                window.location.href = redirectUrl;
                console.log(`Redirecting to fid=${fid}, page=${lastPage}`);
            }
        } catch (error) {
            console.error('Failed to redirect:', error);
        }
    }

    // 主逻辑
    function main() {
        const urlParams = getUrlParams();
        const currentFid = urlParams.get('fid');
        const currentPage = urlParams.get('page');

        // 如果是 forum.php 页面,存储当前的 fid 和 page
        if (window.location.pathname === '/forum.php' && currentFid && currentPage) {
            storeFidAndPage(currentFid, currentPage);
        }

        // 如果是 forum-*-*.html 页面,提取 fid 并跳转到上次访问的页面
        if (window.location.pathname.match(/forum-\d+-\d+\.html/)) {
            const fid = getFidFromUrl();
            redirectToLastPage(fid);
        }
    }

    // 执行主逻辑
    main();
})();
182

震惊
3

感谢

关心
4

加油
2

有爱

刚表态过的朋友 (191 人)

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

关闭

站长公告上一条 /1 下一条

文字版|手机版|小黑屋|GameMale

GMT+8, 2025-12-25 08:14 , Processed in 0.054733 second(s), 12 queries , Redis On.

Copyright © 2013-2025 GameMale

All Rights Reserved.