mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
fix sponsorblock plugin
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
module.exports = () => {
|
||||
document.addEventListener('apiLoaded', e => {
|
||||
document.addEventListener('apiLoaded', () => {
|
||||
document.querySelector('video').addEventListener('loadeddata', e => {
|
||||
e.target.pause();
|
||||
})
|
||||
|
||||
@ -1,4 +1,12 @@
|
||||
const fetch = require("node-fetch");
|
||||
const is = require("electron-is");
|
||||
|
||||
// see https://github.com/node-fetch/node-fetch/issues/568#issuecomment-932200523
|
||||
// will not be needed if project's electron version >= v15.1.0 (https://github.com/node-fetch/node-fetch/issues/568#issuecomment-932435180)
|
||||
const https = require("https");
|
||||
const agent = new https.Agent({
|
||||
rejectUnauthorized: false,
|
||||
});
|
||||
|
||||
const defaultConfig = require("../../config/defaults");
|
||||
const registerCallback = require("../../providers/song-info");
|
||||
@ -24,6 +32,7 @@ module.exports = (win, options) => {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const fetchSegments = async (apiURL, categories) => {
|
||||
const sponsorBlockURL = `${apiURL}/api/skipSegments?videoID=${videoID}&categories=${JSON.stringify(
|
||||
categories
|
||||
@ -35,6 +44,7 @@ const fetchSegments = async (apiURL, categories) => {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
redirect: "follow",
|
||||
agent // fixes error: 'CERT_HAS_EXPIRED'
|
||||
});
|
||||
if (resp.status !== 200) {
|
||||
return [];
|
||||
@ -45,7 +55,10 @@ const fetchSegments = async (apiURL, categories) => {
|
||||
);
|
||||
|
||||
return sortedSegments;
|
||||
} catch {
|
||||
} catch (e) {
|
||||
if (is.dev()) {
|
||||
console.log('error on sponsorblock request:', e);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
@ -2,8 +2,6 @@ const { ipcRenderer } = require("electron");
|
||||
|
||||
const is = require("electron-is");
|
||||
|
||||
const { ontimeupdate } = require("../../providers/video-element");
|
||||
|
||||
let currentSegments = [];
|
||||
|
||||
module.exports = () => {
|
||||
@ -11,17 +9,19 @@ module.exports = () => {
|
||||
currentSegments = segments;
|
||||
});
|
||||
|
||||
ontimeupdate((videoElement) => {
|
||||
currentSegments.forEach((segment) => {
|
||||
if (
|
||||
videoElement.currentTime >= segment[0] &&
|
||||
videoElement.currentTime <= segment[1]
|
||||
) {
|
||||
videoElement.currentTime = segment[1];
|
||||
if (is.dev()) {
|
||||
console.log("SponsorBlock: skipping segment", segment);
|
||||
document.addEventListener('apiLoaded', () => {
|
||||
document.querySelector('video').addEventListener('timeupdate', e => {
|
||||
currentSegments.forEach((segment) => {
|
||||
if (
|
||||
e.target.currentTime >= segment[0] &&
|
||||
e.target.currentTime <= segment[1]
|
||||
) {
|
||||
e.target.currentTime = segment[1];
|
||||
if (is.dev()) {
|
||||
console.log("SponsorBlock: skipping segment", segment);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
}, { once: true, passive: true})
|
||||
};
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
let videoElement = null;
|
||||
|
||||
module.exports.ontimeupdate = (cb) => {
|
||||
const observer = new MutationObserver((mutations, observer) => {
|
||||
if (!videoElement) {
|
||||
videoElement = document.querySelector("video");
|
||||
if (videoElement) {
|
||||
observer.disconnect();
|
||||
videoElement.ontimeupdate = () => cb(videoElement);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!videoElement) {
|
||||
observer.observe(document, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
});
|
||||
} else {
|
||||
videoElement.ontimeupdate = () => cb(videoElement);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user