// ==UserScript== // @name 百度网盘在线视频播放器 // @namespace https://example.com/ // @version 1.7 // @description 自动识别当前文件夹视频,一键弹窗播放。支持倍速、清晰度切换。 // @match https://pan.baidu.com/s/* // @grant unsafeWindow // @run-at document-end // @icon https://nd-static.bdstatic.com/m-static/wp-brand/favicon.ico // @license MIT // ==/UserScript== (function() { 'use strict'; console.log('=== 百度网盘在线视频播放器 v1.7 ==='); function formatSize(bytes) { if (!bytes) return ''; var u = ['B','KB','MB','GB'], s = bytes, i = 0; while (s >= 1024 && i < u.length-1) { s /= 1024; i++; } return s.toFixed(1) + ' ' + u[i]; } function getFileName(file) { return file.server_filename || file.filename || file.name || file.title || '未知文件'; } function getFolderName() { var hash = location.hash; var match = hash.match(/path=([^&]+)/); if (match) { var path = decodeURIComponent(match[1]); var idx = path.indexOf('sharelink'); if (idx >= 0) { var sub = path.substring(idx); var parts = sub.split('/'); if (parts.length > 1) parts.shift(); return parts.join('/') || '根目录'; } return path || '根目录'; } return '根目录'; } function getSurId() { return (location.pathname.match(/\/s\/(\w+)/) || [])[1] || ''; } function getCurrentList() { try { var ctx = unsafeWindow.require('system-core:context/context.js'); var list = ctx.instanceForSystem.list.getCurrentList(); if (list && list.length) { sessionStorage.setItem(getSurId(), JSON.stringify(list)); return list; } } catch(e) {} var cached = sessionStorage.getItem(getSurId()); if (cached) { try { return JSON.parse(cached); } catch(e) {} } return []; } function buildPlayerPage(videos, shareInfo, folderName) { var enhancedVideos = videos.map(function(v, idx) { return { id: idx, name: getFileName(v), fid: v.fs_id || v.fid, size: v.size || 0 }; }); enhancedVideos.sort(function(a, b) { return a.name.localeCompare(b.name, 'zh-CN', {numeric:true}); }); enhancedVideos.forEach(function(v, i) { v.id = i; }); var videoDataJson = JSON.stringify(enhancedVideos); var shareDataJson = JSON.stringify(shareInfo); return '百度网盘视频播放器'+ '