mirror of
https://github.com/SoPat712/videospeed.git
synced 2025-08-22 02:18:45 -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
|
vine.co
|
||||||
imgur.com
|
imgur.com
|
||||||
teams.microsoft.com
|
teams.microsoft.com
|
||||||
`.replace(regStrip, ""),
|
|
||||||
blacklistrc: `\
|
|
||||||
twitch.tv
|
|
||||||
pluralsight.com
|
|
||||||
teamtreehouse.com
|
|
||||||
`.replace(regStrip, "")
|
`.replace(regStrip, "")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -85,8 +80,7 @@ chrome.storage.sync.get(tc.settings, function(storage) {
|
|||||||
startHidden: tc.settings.startHidden,
|
startHidden: tc.settings.startHidden,
|
||||||
enabled: tc.settings.enabled,
|
enabled: tc.settings.enabled,
|
||||||
controllerOpacity: tc.settings.controllerOpacity,
|
controllerOpacity: tc.settings.controllerOpacity,
|
||||||
blacklist: tc.settings.blacklist.replace(regStrip, ""),
|
blacklist: tc.settings.blacklist.replace(regStrip, "")
|
||||||
blacklistrc: tc.settings.blacklistrc.replace(regStrip, "")
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
tc.settings.lastSpeed = Number(storage.lastSpeed);
|
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.startHidden = Boolean(storage.startHidden);
|
||||||
tc.settings.controllerOpacity = Number(storage.controllerOpacity);
|
tc.settings.controllerOpacity = Number(storage.controllerOpacity);
|
||||||
tc.settings.blacklist = String(storage.blacklist);
|
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)
|
// 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) {
|
if (tc.settings.keyBindings.filter(x => x.action == "display").length == 0) {
|
||||||
@@ -344,43 +337,31 @@ function isBlacklisted() {
|
|||||||
return blacklisted;
|
return blacklisted;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRateChangeBlocked() {
|
var coolDown = false;
|
||||||
blockRateChange = false;
|
function refreshCoolDown() {
|
||||||
tc.settings.blacklistrc.split("\n").forEach(match => {
|
if (coolDown) {
|
||||||
match = match.replace(regStrip, "");
|
clearTimeout(coolDown);
|
||||||
if (match.length == 0) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (match.startsWith("/")) {
|
coolDown = setTimeout(function() {
|
||||||
try {
|
coolDown = false;
|
||||||
var regexp = new RegExp(match);
|
}, 1000);
|
||||||
} catch (err) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var regexp = new RegExp(escapeStringRegExp(match));
|
|
||||||
}
|
|
||||||
if (regexp.test(location.href)) {
|
|
||||||
blockRateChange = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return blockRateChange;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeWhenReady(document) {
|
function initializeWhenReady(document) {
|
||||||
if (isBlacklisted()) {
|
if (isBlacklisted()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isRateChangeBlocked()) {
|
|
||||||
document.body.addEventListener(
|
document.body.addEventListener(
|
||||||
"ratechange",
|
"ratechange",
|
||||||
function(event) {
|
function(event) {
|
||||||
|
if (coolDown) {
|
||||||
|
refreshCoolDown();
|
||||||
|
console.log("Speed event propagation blocked");
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
}
|
|
||||||
window.onload = () => {
|
window.onload = () => {
|
||||||
initializeNow(window.document);
|
initializeNow(window.document);
|
||||||
};
|
};
|
||||||
@@ -602,6 +583,7 @@ function setSpeed(controller, video, speed) {
|
|||||||
video.playbackRate = Number(speedvalue);
|
video.playbackRate = Number(speedvalue);
|
||||||
var speedIndicator = controller.shadowRoot.querySelector("span");
|
var speedIndicator = controller.shadowRoot.querySelector("span");
|
||||||
speedIndicator.textContent = speedvalue;
|
speedIndicator.textContent = speedvalue;
|
||||||
|
refreshCoolDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
function runAction(action, document, value, e) {
|
function runAction(action, document, value, e) {
|
||||||
|
16
options.html
16
options.html
@@ -168,22 +168,6 @@
|
|||||||
</label>
|
</label>
|
||||||
<textarea id="blacklist" rows="10" cols="50"></textarea>
|
<textarea id="blacklist" rows="10" cols="50"></textarea>
|
||||||
</div>
|
</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>
|
</section>
|
||||||
|
|
||||||
<button id="save">Save</button>
|
<button id="save">Save</button>
|
||||||
|
28
options.js
28
options.js
@@ -23,11 +23,6 @@ var tcDefaults = {
|
|||||||
vine.co
|
vine.co
|
||||||
imgur.com
|
imgur.com
|
||||||
teams.microsoft.com
|
teams.microsoft.com
|
||||||
`.replace(regStrip, ""),
|
|
||||||
blacklistrc: `\
|
|
||||||
twitch.tv
|
|
||||||
pluralsight.com
|
|
||||||
teamtreehouse.com
|
|
||||||
`.replace(regStrip, "")
|
`.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;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,7 +216,6 @@ function save_options() {
|
|||||||
var startHidden = document.getElementById("startHidden").checked;
|
var startHidden = document.getElementById("startHidden").checked;
|
||||||
var controllerOpacity = document.getElementById("controllerOpacity").value;
|
var controllerOpacity = document.getElementById("controllerOpacity").value;
|
||||||
var blacklist = document.getElementById("blacklist").value;
|
var blacklist = document.getElementById("blacklist").value;
|
||||||
var blacklistrc = document.getElementById("blacklistrc").value;
|
|
||||||
|
|
||||||
chrome.storage.sync.remove([
|
chrome.storage.sync.remove([
|
||||||
"resetSpeed",
|
"resetSpeed",
|
||||||
@@ -262,8 +238,7 @@ function save_options() {
|
|||||||
startHidden: startHidden,
|
startHidden: startHidden,
|
||||||
controllerOpacity: controllerOpacity,
|
controllerOpacity: controllerOpacity,
|
||||||
keyBindings: keyBindings,
|
keyBindings: keyBindings,
|
||||||
blacklist: blacklist.replace(regStrip, ""),
|
blacklist: blacklist.replace(regStrip, "")
|
||||||
blacklistrc: blacklistrc.replace(regStrip, "")
|
|
||||||
},
|
},
|
||||||
function() {
|
function() {
|
||||||
// Update status to let user know options were saved.
|
// Update status to let user know options were saved.
|
||||||
@@ -286,7 +261,6 @@ function restore_options() {
|
|||||||
document.getElementById("controllerOpacity").value =
|
document.getElementById("controllerOpacity").value =
|
||||||
storage.controllerOpacity;
|
storage.controllerOpacity;
|
||||||
document.getElementById("blacklist").value = storage.blacklist;
|
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
|
// 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) {
|
if (storage.keyBindings.filter(x => x.action == "display").length == 0) {
|
||||||
|
Reference in New Issue
Block a user