auto (un)group
This commit is contained in:
parent
75751d1431
commit
c5cbacb644
3 changed files with 52 additions and 6 deletions
23
README.md
23
README.md
|
@ -1,9 +1,24 @@
|
|||
# chromiutil
|
||||
|
||||
utility scripts for chrome. current features:
|
||||
utility scripts for chromium. 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
|
||||
- <key>alt-p</key> to put videos in pip (picture in picture)
|
||||
- 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
|
||||
- automatic tab group collapsing (read note below)
|
||||
|
||||
to make automatic tab group collapsing work, you need to hijack ctrl{-shift}-tab.
|
||||
you can do so by running the code on `chrome://extensions`
|
||||
|
||||
```js
|
||||
chrome.developerPrivate.updateExtensionCommand({
|
||||
extensionId: "<whatever id chrome chooses>", commandName: "nextTab",
|
||||
keybinding: "Ctrl+Tab"
|
||||
});
|
||||
|
||||
chrome.developerPrivate.updateExtensionCommand({
|
||||
extensionId: "<the same id again>", commandName: "prevTab",
|
||||
keybinding: "Ctrl+Shift+Tab"
|
||||
});
|
||||
```
|
||||
|
||||
|
|
|
@ -1,18 +1,38 @@
|
|||
console.log("hi");
|
||||
|
||||
// ran on keyboard shortcut
|
||||
// configure your own in manifest.json
|
||||
// dont forget to hijack for {next,prev}Tab!
|
||||
chrome.commands.onCommand.addListener(async (command) => {
|
||||
switch(command) {
|
||||
case "pip":
|
||||
case "pip": {
|
||||
run(await getTab(), "pip.js");
|
||||
break;
|
||||
}
|
||||
case "nextTab":
|
||||
case "prevTab": {
|
||||
const tab = await getTab();
|
||||
const tabs = await chrome.tabs.query({ currentWindow: true });
|
||||
const index = tabs.findIndex(i => i.id === tab);
|
||||
const groups = await chrome.tabGroups.query({ windowId: tab.windowId });
|
||||
const next = (index + (command === "prevTab" ? -1 : 1) + tabs.length) % tabs.length;
|
||||
chrome.tabs.update(tabs[next].id, { active: true });
|
||||
for(let group of groups) {
|
||||
if(group.id === tabs[next].groupId) continue;
|
||||
chrome.tabGroups.update(group.id, { collapsed: true });
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// ran on every tab
|
||||
chrome.tabs.onUpdated.addListener((tab, { status }) => {
|
||||
if(status !== "complete") return;
|
||||
run(tab, "altspeed.js");
|
||||
});
|
||||
|
||||
// get the current tab id
|
||||
async function getTab() {
|
||||
const queryOptions = { active: true, currentWindow: true };
|
||||
const [tab] = await chrome.tabs.query(queryOptions);
|
||||
|
@ -20,6 +40,7 @@ async function getTab() {
|
|||
return tab.id;
|
||||
}
|
||||
|
||||
// run a script on a tab
|
||||
async function run(tabId, file) {
|
||||
console.log(tabId);
|
||||
chrome.scripting.executeScript({
|
||||
|
|
|
@ -6,11 +6,13 @@
|
|||
"permissions": [
|
||||
"tabs",
|
||||
"activeTab",
|
||||
"tabGroups",
|
||||
"commands",
|
||||
"scripting"
|
||||
],
|
||||
"host_permissions": [
|
||||
"*://*/*"
|
||||
"http://*/*",
|
||||
"https://*/*"
|
||||
],
|
||||
"background": {
|
||||
"service_worker": "background.js"
|
||||
|
@ -19,6 +21,14 @@
|
|||
"pip": {
|
||||
"suggested_key": "Alt+P",
|
||||
"description": "Activate picture in picture picker"
|
||||
},
|
||||
"prevTab": {
|
||||
"suggested_key": "Alt+1",
|
||||
"description": "(prev. tab, placeholder keyboard shortcut)"
|
||||
},
|
||||
"nextTab": {
|
||||
"suggested_key": "Alt+2",
|
||||
"description": "(next tab, placeholder keyboard shortcut"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue