-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
75 lines (65 loc) · 2.67 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
document.addEventListener("DOMContentLoaded", function () {
const slider = document.getElementById("percentage-slider");
const sliderValue = document.getElementById("percentage-value");
const wordCount = document.getElementById("word-count");
const toggleButton = document.getElementById("toggle-bionic");
const boldWeightSlider = document.getElementById("bold-weight-slider");
const boldWeightValue = document.getElementById("bold-weight-value");
boldWeightSlider.oninput = function () {
boldWeightValue.textContent = this.value;
};
slider.oninput = function () {
sliderValue.textContent = this.value + "%";
};
toggleButton.onclick = function () {
const isEnabled = toggleButton.textContent.includes("Enable");
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["contentScript.js"],
});
});
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (isEnabled) {
console.log("Enabling Bionic Reading Mode");
// Send message to content script to enable Bionic Reading
chrome.tabs.sendMessage(tabs[0].id, {
command: "toggleBionic",
action: "enable",
argument: {
percentOfWord: slider.value,
everyXWord: wordCount.value,
boldWeight: boldWeightSlider.value
},
});
toggleButton.textContent = "Disable Bionic Reading";
} else {
console.log("Disabling Bionic Reading Mode");
// Send message to content script to disable Bionic Reading
chrome.tabs.sendMessage(tabs[0].id, {
command: "toggleBionic",
action: "disable",
});
toggleButton.textContent = "Enable Bionic Reading";
}
});
};
});
function sendSettingsToContentScript() {
const wordPercentage = document.getElementById('percentage-slider').value;
const boldXWords = document.getElementById('word-count').value;
const boldWeight = document.getElementById('bold-weight-slider').value;
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
command: "updateSettings",
settings: {
percentOfWord: wordPercentage,
everyXWord: boldXWords,
boldWeight: boldWeight
}
});
});
}
document.getElementById('percentage-slider').addEventListener('change', sendSettingsToContentScript);
document.getElementById('word-count').addEventListener('change', sendSettingsToContentScript);
document.getElementById('bold-weight-slider').addEventListener('change', sendSettingsToContentScript);