-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
30 lines (27 loc) · 1.14 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
import Analytics from "./google-analytics.js";
document.addEventListener("DOMContentLoaded", () => {
const processPageButton = document.getElementById("processPage");
if (processPageButton) {
processPageButton.addEventListener("click", () => {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
chrome.scripting.executeScript({
target: { tabId: tabs[0].id },
function: processPageContent,
});
// Close the popup after initiating the script
window.close();
});
});
}
document.getElementById("popupTitle").textContent = chrome.i18n.getMessage("popupTitle");
document.getElementById("popupInstructions").innerHTML =
chrome.i18n.getMessage("popupInstructions");
document.getElementById("processPage").textContent = chrome.i18n.getMessage("popupButton");
document.getElementById("popupChooseMethod").textContent =
chrome.i18n.getMessage("popupChooseMethod");
});
async function processPageContent() {
const selection = window.getSelection().toString();
window.processBullshitContent(selection);
Analytics.fireEvent("popup_translate_button_click");
}