mirror of
https://github.com/SoPat712/videospeed.git
synced 2026-04-21 04:42:35 -04:00
fix: remember playback speed site switching behavior
This commit is contained in:
@@ -627,7 +627,26 @@ function sanitizeSpeed(speed, fallback) {
|
||||
}
|
||||
|
||||
function getVideoSourceKey(video) {
|
||||
return (video && (video.currentSrc || video.src)) || "unknown_src";
|
||||
if (!video) return "unknown_src";
|
||||
|
||||
var docLocation =
|
||||
video.ownerDocument &&
|
||||
video.ownerDocument.location &&
|
||||
video.ownerDocument.location.href
|
||||
? video.ownerDocument.location
|
||||
: location;
|
||||
|
||||
var hostname = (docLocation && docLocation.hostname) || "";
|
||||
if (
|
||||
hostname.includes("youtube.com") ||
|
||||
hostname.includes("youtube-nocookie.com")
|
||||
) {
|
||||
// YouTube frequently reuses the same <video> element and may expose
|
||||
// transient blob/currentSrc values. URL keying makes navigation distinct.
|
||||
return "yt:" + docLocation.pathname + docLocation.search;
|
||||
}
|
||||
|
||||
return (video.currentSrc || video.src) || "unknown_src";
|
||||
}
|
||||
|
||||
function getControllerTargetSpeed(video) {
|
||||
@@ -842,6 +861,14 @@ function resolveTargetSpeed(video) {
|
||||
return getDesiredSpeed(video);
|
||||
}
|
||||
|
||||
function clearControllerTargetSpeedsOnNavigation() {
|
||||
tc.mediaElements.forEach(function (video) {
|
||||
if (!video || !video.vsc) return;
|
||||
video.vsc.targetSpeed = null;
|
||||
video.vsc.targetSpeedSourceKey = null;
|
||||
});
|
||||
}
|
||||
|
||||
function extendSpeedRestoreWindow(video, duration) {
|
||||
if (!video || !video.vsc) return;
|
||||
|
||||
@@ -2329,6 +2356,7 @@ function attachNavigationListeners() {
|
||||
if (window.vscNavigationListenersAttached) return;
|
||||
|
||||
var scheduleRescan = function () {
|
||||
clearControllerTargetSpeedsOnNavigation();
|
||||
clearTimeout(window.vscNavigationRescanTimer);
|
||||
window.vscNavigationRescanTimer = setTimeout(function () {
|
||||
initializeWhenReady(document, true);
|
||||
@@ -2347,6 +2375,9 @@ function attachNavigationListeners() {
|
||||
|
||||
window.addEventListener("popstate", scheduleRescan);
|
||||
window.addEventListener("hashchange", scheduleRescan);
|
||||
// YouTube SPA navigation often emits these before/after URL/view swaps.
|
||||
window.addEventListener("yt-navigate-start", scheduleRescan);
|
||||
window.addEventListener("yt-navigate-finish", scheduleRescan);
|
||||
window.vscNavigationListenersAttached = true;
|
||||
}
|
||||
|
||||
|
||||
+9
-23
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "Speeder",
|
||||
"short_name": "Speeder",
|
||||
"version": "5.0.0",
|
||||
"version": "5.0.1",
|
||||
"manifest_version": 2,
|
||||
"description": "Speed up, slow down, advance and rewind HTML5 audio/video with shortcuts (New and improved version of \"Video Speed Controller\")",
|
||||
"homepage_url": "https://github.com/SoPat712/speeder",
|
||||
@@ -9,9 +9,7 @@
|
||||
"gecko": {
|
||||
"id": "{ed860648-f54f-4dc9-9a0d-501aec4313f5}",
|
||||
"data_collection_permissions": {
|
||||
"required": [
|
||||
"none"
|
||||
]
|
||||
"required": ["none"]
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -23,9 +21,7 @@
|
||||
"background": {
|
||||
"scripts": ["background.js"]
|
||||
},
|
||||
"permissions": [
|
||||
"storage"
|
||||
],
|
||||
"permissions": ["storage"],
|
||||
"options_ui": {
|
||||
"page": "options.html",
|
||||
"open_in_tab": false
|
||||
@@ -41,27 +37,17 @@
|
||||
"content_scripts": [
|
||||
{
|
||||
"all_frames": true,
|
||||
"matches": [
|
||||
"http://*/*",
|
||||
"https://*/*",
|
||||
"file:///*"
|
||||
],
|
||||
"matches": ["http://*/*", "https://*/*", "file:///*"],
|
||||
"match_about_blank": true,
|
||||
"exclude_matches": [
|
||||
"https://plus.google.com/hangouts/*",
|
||||
"https://hangouts.google.com/*",
|
||||
"https://meet.google.com/*"
|
||||
],
|
||||
"css": [
|
||||
"inject.css"
|
||||
],
|
||||
"js": [
|
||||
"inject.js"
|
||||
]
|
||||
"css": ["inject.css"],
|
||||
"js": ["inject.js"]
|
||||
}
|
||||
],
|
||||
"web_accessible_resources": [
|
||||
"inject.css",
|
||||
"shadow.css"
|
||||
]
|
||||
}
|
||||
"web_accessible_resources": ["inject.css", "shadow.css"]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user