Skip to content

Commit 1b57dab

Browse files
committed
Added popup for browser action
1 parent 03f7c17 commit 1b57dab

File tree

5 files changed

+56
-1
lines changed

5 files changed

+56
-1
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/background-script.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import { Buffer } from 'buffer'
44

55

66

7+
browser.runtime.onMessage.addListener(notify);
8+
9+
function notify(message) {
10+
if (message.direction === "from-menu-script") {
11+
if (message.message.action === 'grant') {
12+
console.log('granting acces to', message.message.target);
13+
//TODO implement
14+
}
15+
}
16+
}
717

818
let ports = []
919

webext/manifest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111

1212
"permissions": [
13+
"activeTab",
1314
"nativeMessaging",
1415
"<all_urls>"
1516
],
@@ -22,7 +23,8 @@
2223
],
2324

2425
"browser_action": {
25-
"default_icon": "icons/message.svg"
26+
"default_icon": "icons/message.svg",
27+
"default_popup": "menu.html"
2628
},
2729

2830
"browser_specific_settings": {

webext/menu-script.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
console.log('menu opened')
2+
const menuArea = document.getElementById('options')
3+
console.log(document, menuArea)
4+
// this doesn't work: browser.tabs.getCurrent().then(...
5+
browser.tabs.query({ "active": true, "currentWindow": true, "windowType": "normal" }).then(
6+
tabs => tabs[0]
7+
).then(
8+
tab => {
9+
console.log('tab', tab)
10+
const relevantURL = tab.url.split('?')[0].split('#')[0]
11+
menuArea.innerHTML += `Allow the page at ${relevantURL} to access SSB?`
12+
const button = document.createElement('button')
13+
button.innerText = 'Grant'
14+
button.addEventListener('click', () => {
15+
16+
browser.runtime.sendMessage({
17+
direction: "from-menu-script",
18+
message: {
19+
action: 'grant',
20+
target: relevantURL
21+
}
22+
});
23+
})
24+
menuArea.appendChild(button)
25+
},
26+
error => {
27+
console.log('error', error)
28+
})

webext/menu.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<head>
3+
4+
</head>
5+
<body>
6+
<h1>SSBversive</h1>
7+
<div id="options"></div>
8+
<script src="menu-script.js" ></script>
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)