墨燝 发表于 2024-11-4 20:22:15

【梅克军团】bilibili视频跳过片头片尾

本帖最后由 墨燝 于 2024-11-14 15:52 编辑

因为有看切片剧的需求(没版权所以一集切分了很多p,每p最后还有别的内容),所以用chatgpt改了别人的代码,添加了几个按钮就不会绑定奇怪的键盘按键还忘了功能是啥了。不过目前没有做本地的跳过时长存储,应该也不需要吧(大概

大致在右下角放了三个按钮,一个用于手动输入,另外两个自动获取当前时间,改一下match网页和播放器的选取条件应该也能用到其他平台吧



论坛格式有点抽风,下面这个@Name @match自己改改就行

// ==UserScript==
// @name         BiliBili跳过片头片尾
// @namespace    http://tampermonkey.net/
// @version      2024-11-04
// @description添加控制按钮用于跳过片头片尾设置
// @match      *://www.bilibili.com/*
// @icon         data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNDEuMDY1IiBoZWlnaHQ9IjEyNy43NDciIHZpZXdCb3g9IjAgMCAzNy4zMjQgMzMuOCI+PHBhdGggZmlsbD0iIzIwYjBlMyIgZD0iTTg2Ljk2MiAxMTIuMzMyYTIuNjYxIDIuNjYxIDAgMCAxIDIuMjYyIDAgNS41MzYgNS41MzYgMCAwIDEgMS4zODQgMS4wMTFsNS4zMjMgNC42NThoMy44MDVsNS4zMjMtNC42NThhNS41ODkgNS41ODkgMCAwIDEgMS4zODQtMS4wMTEgMi42NjEgMi42NjEgMCAwIDEgMy41NCAyLjIwOSAyLjY2MSAyLjY2MSAwIDAgMS0uNTg2IDEuNzgzIDE0Ljg3NyAxNC44NzcgMCAwIDEtMS4xNzEgMS4wNjUgNy42OTEgNy42OTEgMCAwIDEtLjc0NS42MTJoMy4zMjZhNS42NDIgNS42NDIgMCAwIDEgMy45MTIgMS43NTYgNS42NjkgNS42NjkgMCAwIDEgMS43ODQgMy45MTJ2MTUuMzAzYTEwLjc3OCAxMC43NzggMCAwIDEtLjEzNCAyLjMxNSA1LjkwOCA1LjkwOCAwIDAgMS0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EuMTE3IDEuMzA0LTEuMTk4LjA3NC0xLjc1Ny0uNDA4LjQxNy0uOTQxLjg4NC0xLjM2IDEuMjIzLS4zOTIuMzE2LS44NjMuNjctMS4yMzUuOTUyLTEuOTA3IDEuNDQzLjIyNiA0LjA1MyAyLjEzIDIuNjA3IDAgMCAyLTEuNTM1IDIuODA3LTIuMzAxLjQ0LS40MTcuNjgtLjk1Ni43Mi0xLjU5Mi4wNC0uNjU0LS41MzUtMS4yNC0uNzk0LTEuNDk4LS45Mi0uOTE0LTEuNzQzLTEuOTY4LTIuNTUtMi44MTItMS41NzUtMS44LTQuMTIuNDI4LTIuNTQ2IDIuMjI3ek0xMDYuOTc5IDEyOC42MzZjLS4zNjMuMzc3LS43NDUuNzQ3LTEuMDg4IDEuMTQyLS41OTcuNjg3LTEuMTE4IDEuMTk3LTEuNjY2IDEuODA5LjEyOS0xLjExNy0xLjMwNC0xLjE5OC0uMDc0LTEuNzU3LjQwOC40MTcuOTQxLjg4NCAxLjM2IDEuMjIzLjM5Mi4zMTYuODYzLjY3IDEuMjM1Ljk1MiAxLjkwNyAxLjQ0My0uMjI2IDQuMDUzLTIuMTMgMi42MDcgMCAwLTItMS41MzUtMi44MDctMi4zMDEtLjQ0LS40MTctLjY4LS45NTYtLjcyLTEuNTkyLS4wNC0uNjU0LjUzNS0xLjI0Ljc5NC0xLjQ5OC45Mi0uOTE0IDEuNzQzLTEuOTY4IDIuNTUtMi44MTIgMS41NzUtMS44IDQuMTIuNDI4IDIuNTQ2IDIuMjI3eiIgc3R5bGU9ImZpbGw6IzIwYjBlMztmaWxsLW9wYWNpdHk6MTtzdHJva2Utd2lkdGg6LjUyNDE1OTtzdHJva2UtZGFzaGFycmF5Om5vbmUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC03OS4xOTMgLTExMi4wOCkiLz48L3N2Zz4NCg==
// @grant      none
// ==/UserScript==

let skip_IntroLength = 0;
let skip_OutroLength = 0;

(function() {
    'use strict';

    // 创建按钮容器
    const buttonContainer = document.createElement("div");
    buttonContainer.style.position = "fixed";
    buttonContainer.style.bottom = "20px";
    buttonContainer.style.right = "20px";
    buttonContainer.style.display = "flex";
    buttonContainer.style.flexDirection = "column";
    buttonContainer.style.gap = "10px";
    buttonContainer.style.zIndex = "9999";
    document.body.appendChild(buttonContainer);

    // 创建手动设置按钮
    const manualButton = document.createElement("button");
    manualButton.textContent = "手动设置时长";
    manualButton.style.padding = "10px";
    manualButton.style.backgroundColor = "#6DD3CE";
    manualButton.style.color = "#fff";
    manualButton.style.border = "none";
    manualButton.style.borderRadius = "5px";
    manualButton.style.cursor = "pointer";
    buttonContainer.appendChild(manualButton);

    // 创建设定片头按钮
    const setIntroButton = document.createElement("button");
    setIntroButton.textContent = "设为片头时间";
    setIntroButton.style.padding = "10px";
    setIntroButton.style.backgroundColor = "#C8E9A0";
    setIntroButton.style.color = "#fff";
    setIntroButton.style.border = "none";
    setIntroButton.style.borderRadius = "5px";
    setIntroButton.style.cursor = "pointer";
    buttonContainer.appendChild(setIntroButton);

    // 创建设定片尾按钮
    const setOutroButton = document.createElement("button");
    setOutroButton.textContent = "设为片尾时间";
    setOutroButton.style.padding = "10px";
    setOutroButton.style.backgroundColor = "#F7A278";
    setOutroButton.style.color = "#fff";
    setOutroButton.style.border = "none";
    setOutroButton.style.borderRadius = "5px";
    setOutroButton.style.cursor = "pointer";
    buttonContainer.appendChild(setOutroButton);

    // 手动设置跳过时长
    manualButton.addEventListener("click", () => {
      const newIntroLength = prompt("请输入片头跳过时间(秒):", skip_IntroLength);
      const newOutroLength = prompt("请输入片尾跳过时间(秒):", skip_OutroLength);

      if (!isNaN(parseFloat(newIntroLength))) {
            skip_IntroLength = parseFloat(newIntroLength);
      }
      if (!isNaN(parseFloat(newOutroLength))) {
            skip_OutroLength = parseFloat(newOutroLength);
      }
    });

    // 设置当前播放时间为片头时长
    setIntroButton.addEventListener("click", () => {
      const video = document.querySelector("#bilibili-player video");
      if (video) {
            skip_IntroLength = video.currentTime;
            alert(`片头时长已设置为:${skip_IntroLength.toFixed(2)} 秒`);
      } else {
            alert("未找到视频元素!");
      }
    });

    // 设置当前播放时间为片尾时长
    setOutroButton.addEventListener("click", () => {
      const video = document.querySelector("#bilibili-player video");
      if (video) {
            skip_OutroLength = video.duration - video.currentTime;
            alert(`片尾时长已设置为:${skip_OutroLength.toFixed(2)} 秒`);
      } else {
            alert("未找到视频元素!");
      }
    });

    // 定时跳过片头和片尾
    setInterval(() => {
      const video = document.querySelector("#bilibili-player video");
      if (video && !isNaN(video.duration)) {
            const currentTime = video.currentTime;
            if (currentTime < skip_IntroLength) {
                video.currentTime = skip_IntroLength;
            } else if (currentTime > (video.duration - skip_OutroLength) && currentTime < (video.duration - 2)) {
                video.currentTime = video.duration;
            }
      }
    }, 2000);
})();


泥潭療養院

折木 发表于 2024-11-4 20:25:15

对于多P资源很有帮助惹

Nittbone 发表于 2024-11-4 20:26:06

code又被识别抽风了

凯诺斯 发表于 2024-11-4 20:27:38

能够自动跳过片头片尾确实很方便实用惹{:6_169:}

2337891498 发表于 2024-11-4 20:33:17

配合b站的自动播放下集一起很好用惹

凄怆流年 发表于 2024-11-4 20:33:33

跳片头,这个功能实用啊

佐均夏 发表于 2024-11-4 20:36:07

双手解放了,可以动都不动了

boshen 发表于 2024-11-4 20:38:47

好哎好哎,非常需要用来刷些老剧,解放双手,科技改变生活

Brine 发表于 2024-11-4 20:42:31

对于不想反复看oped但又懒得手动跳过的用户很实用呀

zzy159 发表于 2024-11-4 20:43:05

哇哦,看上去很好用哎,感谢大佬捏;P

ONOTOU 发表于 2024-11-4 20:48:43

好唉好唉,解放双手,很实用惹{:6_200:}

枫糖 发表于 2024-11-4 20:54:12

b站其实更需要跳过up主恰饭内容的插件;P;P

Makima 发表于 2024-11-4 20:58:42

牛蛙
不过b站不开会员太糊了,我现在尽量下载看了

不是卖萌的基佬 发表于 2024-11-4 20:59:08

我记得B站以前有这个功能 现在不知道怎么就消失了

娱乐法师火布偶 发表于 2024-11-4 21:00:23

对于在B站追番或者看电视剧来说可以提高体验了

mengdi 发表于 2024-11-4 21:13:23

确实是很方便的代码,这下追剧轻松不少,以前手动快进很少有能跳的特别准的{:6_169:}

sinhotiger 发表于 2024-11-4 21:22:16

感谢大佬给出的代码,很好用

黑夜下的灯光 发表于 2024-11-4 21:27:39

相当不错的功能呢,很多东西可以省略了呢

2297988 发表于 2024-11-4 22:04:14

当初看情深深雨蒙蒙哭得老惨了
长大后看感觉有不同的味道呢{:6_169:}

1017186309 发表于 2024-11-4 22:08:17

看着挺不错的东西惹,专注看剧看番挺好用
页: [1] 2 3
查看完整版本: 【梅克军团】bilibili视频跳过片头片尾