Skip to content

Instantly share code, notes, and snippets.

@xavierskip
Last active April 23, 2025 09:02
Show Gist options
  • Save xavierskip/237cd984d2e2a25adec5f96f872271dd to your computer and use it in GitHub Desktop.
Save xavierskip/237cd984d2e2a25adec5f96f872271dd to your computer and use it in GitHub Desktop.
油猴脚本----微博首页转跳到自定义分组(根据时间排序查看微博)
// ==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=[!!!--CHANGE_YOURS--!!!]'; // /mygroups?gid=1490345443458264442
// 获取当前路径
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);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment