百度网盘回到旧版

检测到ai助手,自动跳转回旧版网页

< 脚本百度网盘回到旧版的反馈

评价:好评 - 脚本运行良好

§
发表于:2025-04-11

由于百度网盘倍速播放脚本暂不支持旧版播放页面,所以我对你的代码进行了少量修改,使播放页面自动跳转到新版,修改后的代码如下

// ==UserScript==
// @name        百度网盘回到旧版
// @namespace   https://github.com/jqtmviyu/UserScripts
// @match       https://pan.baidu.com/disk/main*
// @match       https://pan.baidu.com/play/video*
// @version     0.3
// @author      jqtmviyu
// @description 检测到ai助手,自动跳转回旧版网页,回收站/分享/视频页面除外,旧版网页的回收站/分享用不了,旧版视频不能使用倍速播放插件,倍速播放插件下载地址:https://greasyfork.org/scripts/517564
// @downloadURL https://update.greasyfork.org/scripts/504409/%E7%99%BE%E5%BA%A6%E7%BD%91%E7%9B%98%E5%9B%9E%E5%88%B0%E6%97%A7%E7%89%88.user.js
// @updateURL https://update.greasyfork.org/scripts/504409/%E7%99%BE%E5%BA%A6%E7%BD%91%E7%9B%98%E5%9B%9E%E5%88%B0%E6%97%A7%E7%89%88.meta.js
// ==/UserScript==
function redirectToHomeWithPath() {
    // 旧版网页的回收站/分享/视频用不了,排除掉
    const urlhash = window.location.hash;
    if (/^#\/(recyclebin|share|pfile)/.test(urlhash)) {
        return; // 如果匹配任一前缀,则退出脚本
    }

    // 获取当前页面的 URL
    const currentUrl = window.location.href
    // 使用 URL 构造函数解析当前 URL
    const url = new URL(currentUrl)
    var pathParam = url.searchParams.get('path');
    if(pathParam==null){
        // 1. 提取哈希部分(去掉开头的 #)
        const hash = url.hash.substring(1); // "/video?path=...&t=-1"
        // 3. 分割并解析参数
        const [path, query] = hash.split("?");
        const hashParams = new URLSearchParams(query);
        // 获取 path 参数
        pathParam = hashParams.get("path")
    }
    // 跳转到新的 URL
    window.location.href = (/^#\/(video)/.test(urlhash)) ?
        `https://pan.baidu.com/pfile/video?path=${encodeURIComponent(pathParam)}&theme=light&view_from=personal_file&from=home`
    :`https://pan.baidu.com/disk/home?from=newversion&stayAtHome=true#/all?path=${encodeURIComponent(pathParam)}&vmode=list`;
}

// 调用
redirectToHomeWithPath()

发表回复

登录以发表回复。