alt = 5x speed
This commit is contained in:
parent
f0e9372e8a
commit
75751d1431
4 changed files with 46 additions and 4 deletions
9
README.md
Normal file
9
README.md
Normal 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
20
altspeed.js
Normal 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;
|
||||
});
|
||||
})();
|
||||
|
|
@ -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],
|
||||
});
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
"commands",
|
||||
"scripting"
|
||||
],
|
||||
"host_permissions": [
|
||||
"*://*/*"
|
||||
],
|
||||
"background": {
|
||||
"service_worker": "background.js"
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue