alt = 5x speed

This commit is contained in:
sample-text-here 2021-09-24 16:28:16 -07:00
parent f0e9372e8a
commit 75751d1431
4 changed files with 46 additions and 4 deletions

9
README.md Normal file
View file

@ -0,0 +1,9 @@
# chromiutil
utility scripts for chrome. current features:
- <key>alt-p</key> to put videos in pip
- if multiple videos are found, you can pick which one to put in pip
- press again to unpip
- hold alt to temporarily speed up videos 5x

20
altspeed.js Normal file
View file

@ -0,0 +1,20 @@
(() => {
let target = null;
window.addEventListener("keydown", e => {
if(e.key !== "Alt") return;
const active = document.activeFocus ?? document.activeElement;
const vid = active?.querySelector("video");
if(!vid) return;
vid.playbackRate = 5; // change to whatever you like
target = vid;
});
window.addEventListener("keyup", e => {
if(e.key !== "Alt") return;
if(!target) return;
target.playbackRate = 1;
target = null;
});
})();

View file

@ -1,19 +1,29 @@
console.log("hi");
chrome.commands.onCommand.addListener((command) => {
chrome.commands.onCommand.addListener(async (command) => {
switch(command) {
case "pip":
run("pip.js");
run(await getTab(), "pip.js");
break;
}
});
async function run(file) {
chrome.tabs.onUpdated.addListener((tab, { status }) => {
if(status !== "complete") return;
run(tab, "altspeed.js");
});
async function getTab() {
const queryOptions = { active: true, currentWindow: true };
const [tab] = await chrome.tabs.query(queryOptions);
if(!tab) return;
return tab.id;
}
async function run(tabId, file) {
console.log(tabId);
chrome.scripting.executeScript({
target: { tabId: tab.id},
target: { tabId },
files: [file],
});
}

View file

@ -9,6 +9,9 @@
"commands",
"scripting"
],
"host_permissions": [
"*://*/*"
],
"background": {
"service_worker": "background.js"
},