mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 03:41:46 +00:00
Add option in skip-silences plugin to only skip at the beginning
This commit is contained in:
@ -91,6 +91,9 @@ const defaultConfig = {
|
|||||||
"saveSize": false,
|
"saveSize": false,
|
||||||
"hotkey": "P"
|
"hotkey": "P"
|
||||||
},
|
},
|
||||||
|
"skip-silences": {
|
||||||
|
onlySkipBeginning: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
const hark = require("hark/hark.bundle.js");
|
const hark = require("hark/hark.bundle.js");
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = (options) => {
|
||||||
let isSilent = false;
|
let isSilent = false;
|
||||||
|
let hasAudioStarted = false;
|
||||||
|
|
||||||
document.addEventListener("apiLoaded", () => {
|
document.addEventListener("apiLoaded", () => {
|
||||||
const video = document.querySelector("video");
|
const video = document.querySelector("video");
|
||||||
@ -10,6 +11,10 @@ module.exports = () => {
|
|||||||
interval: 2, // ms
|
interval: 2, // ms
|
||||||
});
|
});
|
||||||
const skipSilence = () => {
|
const skipSilence = () => {
|
||||||
|
if (options.onlySkipBeginning && hasAudioStarted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isSilent && !video.paused) {
|
if (isSilent && !video.paused) {
|
||||||
video.currentTime += 0.2; // in s
|
video.currentTime += 0.2; // in s
|
||||||
}
|
}
|
||||||
@ -17,6 +22,7 @@ module.exports = () => {
|
|||||||
|
|
||||||
speechEvents.on("speaking", function () {
|
speechEvents.on("speaking", function () {
|
||||||
isSilent = false;
|
isSilent = false;
|
||||||
|
hasAudioStarted = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
speechEvents.on("stopped_speaking", function () {
|
speechEvents.on("stopped_speaking", function () {
|
||||||
@ -35,10 +41,12 @@ module.exports = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
video.addEventListener("play", function () {
|
video.addEventListener("play", function () {
|
||||||
|
hasAudioStarted = false;
|
||||||
skipSilence();
|
skipSilence();
|
||||||
});
|
});
|
||||||
|
|
||||||
video.addEventListener("seeked", function () {
|
video.addEventListener("seeked", function () {
|
||||||
|
hasAudioStarted = false;
|
||||||
skipSilence();
|
skipSilence();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user