// ==UserScript== // @name 百度网盘在线视频播放器 // @namespace https://example.com/ // @version 2.5 // @description 百度网盘视频在线播放,支持倍速调节(0.25x-4x)、画质切换(360P-1080P)、画中画、记忆播放进度、默认最高画质。 // @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'; function formatDuration(seconds) { if (!seconds || seconds <= 0) return ''; var s = Math.floor(seconds); var h = Math.floor(s / 3600); var m = Math.floor((s % 3600) / 60); var sec = s % 60; return h > 0 ? h + ':' + String(m).padStart(2, '0') + ':' + String(sec).padStart(2, '0') : m + ':' + String(sec).padStart(2, '0'); } 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) {} try { if (unsafeWindow.__LIST__ && unsafeWindow.__LIST__.length) { sessionStorage.setItem(getSurId(), JSON.stringify(unsafeWindow.__LIST__)); return unsafeWindow.__LIST__; } } catch (e) {} var scripts = document.querySelectorAll('script'); for (var i = 0; i < scripts.length; i++) { var text = scripts[i].textContent; if (text && text.indexOf('"list":[') !== -1 && text.indexOf('"category"') !== -1) { try { var match = text.match(/"list":(\[.*?\]),/) || text.match(/"list":(\[.*?\])/); if (match) { var list = JSON.parse(match[1]); 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 filterVideos(list) { if (!list || !list.length) return []; return list.filter(function(i) { if (i.hasOwnProperty('category')) return i.category === 1; var name = getFileName(i).toLowerCase(); return /\.(mp4|mkv|webm|avi|mov|flv|wmv|ts|m3u8)$/i.test(name); }); } function getCachedVideoList(surId) { var key = 'bd_video_cache_' + surId; var cached = localStorage.getItem(key); if (cached) { try { return JSON.parse(cached); } catch (e) {} } return null; } function safeJsonStringify(obj) { return JSON.stringify(obj).replace(/<\/script>/gi, '<\\/script>'); } function generateSidebarListHTML(enhancedVideos) { if (!enhancedVideos || enhancedVideos.length === 0) { return '
当前文件夹没有视频文件,请返回选择包含视频的目录。