mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-15 04:11:47 +00:00
Add SponsorBlock plugin
This commit is contained in:
27
plugins/sponsorblock/front.js
Normal file
27
plugins/sponsorblock/front.js
Normal file
@ -0,0 +1,27 @@
|
||||
const { ipcRenderer } = require("electron");
|
||||
|
||||
const is = require("electron-is");
|
||||
|
||||
const { ontimeupdate } = require("../../providers/video-element");
|
||||
|
||||
let currentSegments = [];
|
||||
|
||||
module.exports = () => {
|
||||
ipcRenderer.on("sponsorblock-skip", (_, segments) => {
|
||||
currentSegments = segments;
|
||||
});
|
||||
|
||||
ontimeupdate((videoElement) => {
|
||||
if (
|
||||
currentSegments.length > 0 &&
|
||||
videoElement.currentTime >= currentSegments[0][0] &&
|
||||
videoElement.currentTime <= currentSegments[0][1]
|
||||
) {
|
||||
videoElement.currentTime = currentSegments[0][1];
|
||||
const skipped = currentSegments.shift();
|
||||
if (is.dev()) {
|
||||
console.log("SponsorBlock: skipping segment", skipped);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user