mirror of
https://github.com/SoPat712/videospeed.git
synced 2025-08-21 18:08:46 -04:00
Far better fix now utilizes a short cooldown window after issuing a speed change command
This commit is contained in:
44
inject.js
44
inject.js
@@ -18,11 +18,6 @@ var tc = {
|
||||
vine.co
|
||||
imgur.com
|
||||
teams.microsoft.com
|
||||
`.replace(regStrip, ""),
|
||||
blacklistrc: `\
|
||||
twitch.tv
|
||||
pluralsight.com
|
||||
teamtreehouse.com
|
||||
`.replace(regStrip, "")
|
||||
}
|
||||
};
|
||||
@@ -85,8 +80,7 @@ chrome.storage.sync.get(tc.settings, function(storage) {
|
||||
startHidden: tc.settings.startHidden,
|
||||
enabled: tc.settings.enabled,
|
||||
controllerOpacity: tc.settings.controllerOpacity,
|
||||
blacklist: tc.settings.blacklist.replace(regStrip, ""),
|
||||
blacklistrc: tc.settings.blacklistrc.replace(regStrip, "")
|
||||
blacklist: tc.settings.blacklist.replace(regStrip, "")
|
||||
});
|
||||
}
|
||||
tc.settings.lastSpeed = Number(storage.lastSpeed);
|
||||
@@ -97,7 +91,6 @@ chrome.storage.sync.get(tc.settings, function(storage) {
|
||||
tc.settings.startHidden = Boolean(storage.startHidden);
|
||||
tc.settings.controllerOpacity = Number(storage.controllerOpacity);
|
||||
tc.settings.blacklist = String(storage.blacklist);
|
||||
tc.settings.blacklistrc = String(storage.blacklistrc);
|
||||
|
||||
// ensure that there is a "display" binding (for upgrades from versions that had it as a separate binding)
|
||||
if (tc.settings.keyBindings.filter(x => x.action == "display").length == 0) {
|
||||
@@ -344,43 +337,31 @@ function isBlacklisted() {
|
||||
return blacklisted;
|
||||
}
|
||||
|
||||
function isRateChangeBlocked() {
|
||||
blockRateChange = false;
|
||||
tc.settings.blacklistrc.split("\n").forEach(match => {
|
||||
match = match.replace(regStrip, "");
|
||||
if (match.length == 0) {
|
||||
return;
|
||||
var coolDown = false;
|
||||
function refreshCoolDown() {
|
||||
if (coolDown) {
|
||||
clearTimeout(coolDown);
|
||||
}
|
||||
if (match.startsWith("/")) {
|
||||
try {
|
||||
var regexp = new RegExp(match);
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
var regexp = new RegExp(escapeStringRegExp(match));
|
||||
}
|
||||
if (regexp.test(location.href)) {
|
||||
blockRateChange = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
return blockRateChange;
|
||||
coolDown = setTimeout(function() {
|
||||
coolDown = false;
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function initializeWhenReady(document) {
|
||||
if (isBlacklisted()) {
|
||||
return;
|
||||
}
|
||||
if (isRateChangeBlocked()) {
|
||||
document.body.addEventListener(
|
||||
"ratechange",
|
||||
function(event) {
|
||||
if (coolDown) {
|
||||
refreshCoolDown();
|
||||
console.log("Speed event propagation blocked");
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
},
|
||||
true
|
||||
);
|
||||
}
|
||||
window.onload = () => {
|
||||
initializeNow(window.document);
|
||||
};
|
||||
@@ -602,6 +583,7 @@ function setSpeed(controller, video, speed) {
|
||||
video.playbackRate = Number(speedvalue);
|
||||
var speedIndicator = controller.shadowRoot.querySelector("span");
|
||||
speedIndicator.textContent = speedvalue;
|
||||
refreshCoolDown();
|
||||
}
|
||||
|
||||
function runAction(action, document, value, e) {
|
||||
|
16
options.html
16
options.html
@@ -168,22 +168,6 @@
|
||||
</label>
|
||||
<textarea id="blacklist" rows="10" cols="50"></textarea>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label for="blacklistrc">
|
||||
Sites to forcefully block ratechange listeners<br />
|
||||
(add here if video speed can't be adjusted or "bounces back" after
|
||||
changing)<br />
|
||||
<br />
|
||||
<em>
|
||||
*Important: Use sparingly as this may cause unexpected website and
|
||||
extension behavior.
|
||||
</em>
|
||||
<br />
|
||||
<br />
|
||||
<em><a href="https://www.regexpal.com/">Regex</a> is supported.</em>
|
||||
</label>
|
||||
<textarea id="blacklistrc" rows="10" cols="50"></textarea>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<button id="save">Save</button>
|
||||
|
28
options.js
28
options.js
@@ -23,11 +23,6 @@ var tcDefaults = {
|
||||
vine.co
|
||||
imgur.com
|
||||
teams.microsoft.com
|
||||
`.replace(regStrip, ""),
|
||||
blacklistrc: `\
|
||||
twitch.tv
|
||||
pluralsight.com
|
||||
teamtreehouse.com
|
||||
`.replace(regStrip, "")
|
||||
};
|
||||
|
||||
@@ -202,24 +197,6 @@ function validate() {
|
||||
}
|
||||
}
|
||||
});
|
||||
document
|
||||
.getElementById("blacklistrc")
|
||||
.value.split("\n")
|
||||
.forEach(match => {
|
||||
match = match.replace(regStrip, "");
|
||||
if (match.startsWith("/")) {
|
||||
try {
|
||||
var regexp = new RegExp(match);
|
||||
} catch (err) {
|
||||
status.textContent =
|
||||
"Error: Invalid ratechange blacklist regex: " +
|
||||
match +
|
||||
". Unable to save";
|
||||
valid = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
return valid;
|
||||
}
|
||||
|
||||
@@ -239,7 +216,6 @@ function save_options() {
|
||||
var startHidden = document.getElementById("startHidden").checked;
|
||||
var controllerOpacity = document.getElementById("controllerOpacity").value;
|
||||
var blacklist = document.getElementById("blacklist").value;
|
||||
var blacklistrc = document.getElementById("blacklistrc").value;
|
||||
|
||||
chrome.storage.sync.remove([
|
||||
"resetSpeed",
|
||||
@@ -262,8 +238,7 @@ function save_options() {
|
||||
startHidden: startHidden,
|
||||
controllerOpacity: controllerOpacity,
|
||||
keyBindings: keyBindings,
|
||||
blacklist: blacklist.replace(regStrip, ""),
|
||||
blacklistrc: blacklistrc.replace(regStrip, "")
|
||||
blacklist: blacklist.replace(regStrip, "")
|
||||
},
|
||||
function() {
|
||||
// Update status to let user know options were saved.
|
||||
@@ -286,7 +261,6 @@ function restore_options() {
|
||||
document.getElementById("controllerOpacity").value =
|
||||
storage.controllerOpacity;
|
||||
document.getElementById("blacklist").value = storage.blacklist;
|
||||
document.getElementById("blacklistrc").value = storage.blacklistrc;
|
||||
|
||||
// ensure that there is a "display" binding for upgrades from versions that had it as a separate binding
|
||||
if (storage.keyBindings.filter(x => x.action == "display").length == 0) {
|
||||
|
Reference in New Issue
Block a user