[方法分享]一种将网页微博固定为分组浏览(按时间线排序)的方法

众所周知,微博默认的信息流会推送但不限于"你可能感兴趣”、营销广告等信息,并且不是按照时间线排序的。

但是分组浏览的时候就没有任何不是你关注的博主产生的信息,并且是按照时间先后顺序的时间线排列。非常的古典、干净。

确实通过固定的URL就可以进入分组浏览,我的脚本自动将https://weibo.com转跳到分组https://weibo.com/mygroups?gid=[your gid],并且将页面首页按钮事件清除以便在点击的时候转跳到"最新微博"(其指定分组)的浏览页面。

以下是脚本,将其中的gid换成你的gid即可。weibo首页点击’最新微博’观察URL即可获取你的gid

// ==UserScript==
// @name        时间轴微博 
// @namespace   Violentmonkey Scripts
// @match       https://weibo.com/*
// @grant       none
// @version     1.0
// @author      -
// @description -
// ==/UserScript==
(function() {
    'use strict';

    // 定义目标路径
    const TARGET_PATH = '/mygroups?gid=[替换成你的 gid]';

    // 获取当前路径
    const currentPath = window.location.pathname;

    // 判断是否需要跳转(当访问根路径时)
    if (currentPath === '/' || currentPath === '') {
        // 构建新URL
        const newUrl = window.location.origin + TARGET_PATH;

        // 使用replace方法避免产生浏览器历史记录
        window.location.replace(newUrl);
    }

    // 修改首页按钮的点击事件
    // 获取目标元素
    const target = document.querySelector('a.Ctrls_alink_1L3hP');

    if(target) {
      // 克隆节点(cloneNode(true) 会保留子节点)
      const cloned = target.cloneNode(true);

      // 用克隆副本替换原始节点(自动解除所有事件绑定)
      target.parentNode.replaceChild(cloned, target);
}
})();
1 Like