mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 14:37:23 +03:00
add mediaSession, remove bindMediaKey
This commit is contained in:
13
package-lock.json
generated
13
package-lock.json
generated
@@ -25,6 +25,7 @@
|
|||||||
"@types/firefox-webext-browser": "70.0.1",
|
"@types/firefox-webext-browser": "70.0.1",
|
||||||
"@types/jest": "^24.0.23",
|
"@types/jest": "^24.0.23",
|
||||||
"@types/jquery": "^3.3.31",
|
"@types/jquery": "^3.3.31",
|
||||||
|
"@types/wicg-mediasession": "^1.1.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.9.1",
|
"@typescript-eslint/eslint-plugin": "^4.9.1",
|
||||||
"@typescript-eslint/parser": "^4.9.1",
|
"@typescript-eslint/parser": "^4.9.1",
|
||||||
"chromedriver": "^92.0.0",
|
"chromedriver": "^92.0.0",
|
||||||
@@ -2044,6 +2045,12 @@
|
|||||||
"integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==",
|
"integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/wicg-mediasession": {
|
||||||
|
"version": "1.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/wicg-mediasession/-/wicg-mediasession-1.1.3.tgz",
|
||||||
|
"integrity": "sha512-lzoszzJJfW9vcaIxf6tDx3lCJq/4oaD+mplA7sCV7W21PGdR6yUPwErN047ziIcwFx61w8WMURIwUyj1V7KJIQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/@types/yargs": {
|
"node_modules/@types/yargs": {
|
||||||
"version": "13.0.7",
|
"version": "13.0.7",
|
||||||
"integrity": "sha512-Sg9kNeJz+V+W+0fugcVhHC+mNHnydDR1RJrW5Qn2jVrDQARF8wfPVqIqwEzZp+bneuEBIm2ClsJ1/je42ZBzSg==",
|
"integrity": "sha512-Sg9kNeJz+V+W+0fugcVhHC+mNHnydDR1RJrW5Qn2jVrDQARF8wfPVqIqwEzZp+bneuEBIm2ClsJ1/je42ZBzSg==",
|
||||||
@@ -20547,6 +20554,12 @@
|
|||||||
"integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==",
|
"integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@types/wicg-mediasession": {
|
||||||
|
"version": "1.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/wicg-mediasession/-/wicg-mediasession-1.1.3.tgz",
|
||||||
|
"integrity": "sha512-lzoszzJJfW9vcaIxf6tDx3lCJq/4oaD+mplA7sCV7W21PGdR6yUPwErN047ziIcwFx61w8WMURIwUyj1V7KJIQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"@types/yargs": {
|
"@types/yargs": {
|
||||||
"version": "13.0.7",
|
"version": "13.0.7",
|
||||||
"integrity": "sha512-Sg9kNeJz+V+W+0fugcVhHC+mNHnydDR1RJrW5Qn2jVrDQARF8wfPVqIqwEzZp+bneuEBIm2ClsJ1/je42ZBzSg==",
|
"integrity": "sha512-Sg9kNeJz+V+W+0fugcVhHC+mNHnydDR1RJrW5Qn2jVrDQARF8wfPVqIqwEzZp+bneuEBIm2ClsJ1/je42ZBzSg==",
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
"@types/firefox-webext-browser": "70.0.1",
|
"@types/firefox-webext-browser": "70.0.1",
|
||||||
"@types/jest": "^24.0.23",
|
"@types/jest": "^24.0.23",
|
||||||
"@types/jquery": "^3.3.31",
|
"@types/jquery": "^3.3.31",
|
||||||
|
"@types/wicg-mediasession": "^1.1.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.9.1",
|
"@typescript-eslint/eslint-plugin": "^4.9.1",
|
||||||
"@typescript-eslint/parser": "^4.9.1",
|
"@typescript-eslint/parser": "^4.9.1",
|
||||||
"chromedriver": "^92.0.0",
|
"chromedriver": "^92.0.0",
|
||||||
|
|||||||
@@ -918,11 +918,5 @@
|
|||||||
},
|
},
|
||||||
"youtubeKeybindWarning": {
|
"youtubeKeybindWarning": {
|
||||||
"message": "This is a built-in YouTube shortcut. Are you sure you want to use it?"
|
"message": "This is a built-in YouTube shortcut. Are you sure you want to use it?"
|
||||||
},
|
|
||||||
"bindMediaKey": {
|
|
||||||
"message": "Play/Pause Current Video with Media Keys"
|
|
||||||
},
|
|
||||||
"bindMediaKeyDescription": {
|
|
||||||
"message": "Enable this if your media keys stop working after the audio notification is played."
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -264,20 +264,6 @@
|
|||||||
<div class="small-description">__MSG_audioNotificationDescription__</div>
|
<div class="small-description">__MSG_audioNotificationDescription__</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div data-type="toggle" data-sync="bindMediaKey" data-dependent-on="audioNotificationOnSkip">
|
|
||||||
<div class="switch-container">
|
|
||||||
<label class="switch">
|
|
||||||
<input id="bindMediaKey" type="checkbox" checked>
|
|
||||||
<span class="slider round"></span>
|
|
||||||
</label>
|
|
||||||
<label class="switch-label" for="bindMediaKey">
|
|
||||||
__MSG_bindMediaKey__
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="small-description">__MSG_bindMediaKeyDescription__</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div data-type="toggle" data-sync="showTimeWithSkips">
|
<div data-type="toggle" data-sync="showTimeWithSkips">
|
||||||
<div class="switch-container">
|
<div class="switch-container">
|
||||||
<label class="switch">
|
<label class="switch">
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ interface SBConfig {
|
|||||||
minDuration: number,
|
minDuration: number,
|
||||||
skipNoticeDuration: number,
|
skipNoticeDuration: number,
|
||||||
audioNotificationOnSkip: boolean,
|
audioNotificationOnSkip: boolean,
|
||||||
bindMediaKey: boolean,
|
|
||||||
checkForUnlistedVideos: boolean,
|
checkForUnlistedVideos: boolean,
|
||||||
testingServer: boolean,
|
testingServer: boolean,
|
||||||
refetchWhenNotFound: boolean,
|
refetchWhenNotFound: boolean,
|
||||||
@@ -199,7 +198,6 @@ const Config: SBObject = {
|
|||||||
minDuration: 0,
|
minDuration: 0,
|
||||||
skipNoticeDuration: 4,
|
skipNoticeDuration: 4,
|
||||||
audioNotificationOnSkip: false,
|
audioNotificationOnSkip: false,
|
||||||
bindMediaKey: false,
|
|
||||||
checkForUnlistedVideos: false,
|
checkForUnlistedVideos: false,
|
||||||
testingServer: false,
|
testingServer: false,
|
||||||
refetchWhenNotFound: true,
|
refetchWhenNotFound: true,
|
||||||
|
|||||||
@@ -967,7 +967,8 @@ function getYouTubeVideoIDFromURL(url: string): string | boolean {
|
|||||||
return id.length == 11 ? id : false;
|
return id.length == 11 ? id : false;
|
||||||
} else if (urlObject.pathname.startsWith("/embed/") || urlObject.pathname.startsWith("/shorts/")) {
|
} else if (urlObject.pathname.startsWith("/embed/") || urlObject.pathname.startsWith("/shorts/")) {
|
||||||
try {
|
try {
|
||||||
return urlObject.pathname.split("/")[2].slice(0, 11);
|
const id = urlObject.pathname.split("/")[2]
|
||||||
|
if (id?.length >=11 ) return id.slice(0, 11);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("[SB] Video ID not valid for " + url);
|
console.error("[SB] Video ID not valid for " + url);
|
||||||
return false;
|
return false;
|
||||||
@@ -1272,9 +1273,14 @@ function skipToTime({v, skipTime, skippingSegments, openNotice, forceAutoSkip, u
|
|||||||
if (autoSkip && Config.config.audioNotificationOnSkip) {
|
if (autoSkip && Config.config.audioNotificationOnSkip) {
|
||||||
const beep = new Audio(chrome.runtime.getURL("icons/beep.ogg"));
|
const beep = new Audio(chrome.runtime.getURL("icons/beep.ogg"));
|
||||||
beep.volume = video.volume * 0.1;
|
beep.volume = video.volume * 0.1;
|
||||||
|
const oldMetadata = navigator.mediaSession.metadata
|
||||||
beep.play();
|
beep.play();
|
||||||
if (Config.config.audioNotificationOnSkip && Config.config.bindMediaKey)
|
beep.addEventListener("ended", () => {
|
||||||
window.addEventListener("keydown", mediaPauseListener);
|
navigator.mediaSession.metadata = null
|
||||||
|
setTimeout(() =>
|
||||||
|
navigator.mediaSession.metadata = oldMetadata
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!autoSkip
|
if (!autoSkip
|
||||||
@@ -1985,7 +1991,6 @@ function sendRequestToCustomServer(type, fullAddress, callback) {
|
|||||||
function updateAdFlag(): void {
|
function updateAdFlag(): void {
|
||||||
const wasAdPlaying = isAdPlaying;
|
const wasAdPlaying = isAdPlaying;
|
||||||
isAdPlaying = document.getElementsByClassName('ad-showing').length > 0;
|
isAdPlaying = document.getElementsByClassName('ad-showing').length > 0;
|
||||||
|
|
||||||
if(wasAdPlaying != isAdPlaying) {
|
if(wasAdPlaying != isAdPlaying) {
|
||||||
updatePreviewBar();
|
updatePreviewBar();
|
||||||
updateVisibilityOfPlayerControlsButton();
|
updateVisibilityOfPlayerControlsButton();
|
||||||
@@ -2039,9 +2044,4 @@ function checkForPreloadedSegment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function mediaPauseListener(e: KeyboardEvent) {
|
|
||||||
if (e.key === "MediaPlayPause")
|
|
||||||
video?.paused ? video.play() : video.pause();
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user