Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shortcuts (toggle & open on alt+click) #435

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions addon/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ browser.contextMenus.create({
documentUrlPatterns: ["<all_urls>"],
});

browser.commands.onCommand.addListener(async command => {
if (command === "toggle-sidebar") {
await browser.sidebarAction.toggle();
}
});

browser.contextMenus.onClicked.addListener(async (info, tab) => {
let url;
let favIconUrl;
Expand Down
16 changes: 16 additions & 0 deletions addon/content-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function getLinkNode(e) {
let target = e.target;
while ((target.tagName !== "A" || !target.href) && target.parentNode) {
target = target.parentNode;
}
return target;
}

function openUrl(e) {
let target = getLinkNode(e);
if (target.tagName !== "A" || !e.altKey) return;

browser.runtime.sendMessage({type: "openUrl", url: target.href});
}

window.addEventListener("click", openUrl);
14 changes: 14 additions & 0 deletions addon/manifest.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,26 @@
"strict_min_version": "57.0a1"
}
},
"commands": {
"toggle-sidebar": {
"suggested_key": {
"default": "Alt+1"
},
"description": "Toggle the sidebar"
}
},
"background": {
"scripts": [
"build/buildSettings.js",
"background.js"
]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content-script.js"]
}
],
"browser_action": {
"default_icon": "side-view.svg",
"default_popup": "popup.html",
Expand Down
Loading