Skip to content

Commit c60eaeb

Browse files
committedJun 15, 2022
First phase of the popup page
1 parent deca179 commit c60eaeb

9 files changed

+89
-7
lines changed
 

‎Firefox/background.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ if(localStorage.getItem("state") === "disable") {
1111

1212
browser.runtime.onMessage.addListener(handleMessage); // Listen message from main.js
1313

14-
browser.browserAction.onClicked.addListener(changeMode); // If the user click on the icon of the toolBar
14+
browser.runtime.onMessage.addListener(changeModeMessage); // Listen message from smartReader_popup.js

‎Firefox/background/changeMode.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function changeMode() {
55
By storing the state on the localStorage
66
77
*/
8-
8+
99
if(localStorage.getItem("state") === "enable") {
1010

1111
localStorage.setItem("state", "disable");

‎Firefox/background/handleMessage.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function handleMessage(message, sender, sendResponse) {
22

3-
/* Serve to communicate with the content script: main.js
3+
/* Serve to communicate with the content script: main.js and the popup page : smartReader_popup.js
44
55
If we receive a message contening "mode: state", we're
66
replying the state
@@ -21,8 +21,11 @@ function handleMessage(message, sender, sendResponse) {
2121

2222
sendResponse({mode: message});
2323
}
24-
else {
2524

26-
sendResponse({mode: "disable"});
25+
if(message.changeMode === "yep") {
26+
27+
changeMode();
28+
29+
sendResponse({state: "done"});
2730
}
2831
}

‎Firefox/manifest.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"16": "/icons/button/smartReader-white-16.png",
5656
"32": "/icons/button/smartReader-white-32.png"
5757
},
58-
"default_title": "Change mode",
58+
"default_title": "Smart Reader settings",
5959
"theme_icons": [{
6060
"light": "/icons/button/smartReader-white-16.png",
6161
"dark": "/icons/button/smartReader-black-16.png",
@@ -64,6 +64,7 @@
6464
"light": "/icons/button/smartReader-white-32.png",
6565
"dark": "/icons/button/smartReader-black-32.png",
6666
"size": 32
67-
}]
67+
}],
68+
"default_popup": "/popup/smartReader_popup.html"
6869
}
6970
}

‎Firefox/popup/img/button_off.png

11.1 KB
Loading

‎Firefox/popup/img/button_on.png

15.6 KB
Loading

‎Firefox/popup/smartReader_popup.css

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
html, body {
2+
width: 200px;
3+
}
4+
5+
body {
6+
overflow: hidden;
7+
background-color: rgb(43, 42, 51);
8+
}
9+
10+
#popup_content {
11+
overflow: hidden;
12+
display: flex;
13+
flex-direction: column;
14+
}
15+
16+
#changeMode_button {
17+
display: flex;
18+
justify-content: center;
19+
}
20+
21+
#state_button {
22+
border: none;
23+
background: none;
24+
cursor: pointer;
25+
}
26+
#state_img {
27+
width: 80px;
28+
}

‎Firefox/popup/smartReader_popup.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
3+
<html>
4+
<head>
5+
<meta charset="utf-8">
6+
<link rel="stylesheet" href="smartReader_popup.css"/>
7+
</head>
8+
9+
<body>
10+
<div id="popup-content">
11+
<div id="changeMode_button">
12+
<button id="state_button" type="button"><img id="state_img"/></button>
13+
</div>
14+
15+
</div>
16+
17+
<script src="smartReader_popup.js"></script>
18+
</body>
19+
</html>

‎Firefox/popup/smartReader_popup.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var button = document.getElementById("state_img");
2+
3+
function resetButton() {
4+
5+
browser.runtime.sendMessage({mode: "state"}, function(message) {
6+
7+
if(message.mode === "enable") {
8+
9+
button.src="img/button_on.png";
10+
11+
} else {
12+
13+
button.src="img/button_off.png";
14+
}
15+
});
16+
}
17+
18+
function changeMode() {
19+
20+
browser.runtime.sendMessage({changeMode: "yep"}, function(message) {
21+
22+
if(message.state === "done") {
23+
24+
resetButton();
25+
}
26+
});
27+
}
28+
29+
button.addEventListener("click", changeMode);
30+
31+
resetButton();

0 commit comments

Comments
 (0)
Please sign in to comment.