-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
29 lines (27 loc) · 1.05 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
// Initialize butotn with users's prefered color
let format = document.getElementById("format");
// When the button is clicked, inject setPageBackgroundColor into current page
format.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true }) ?? null;
if(tab){
let text = document.getElementById('unformatted_string').value ?? null;
if(text !==null){
text = encodeURI(text.replace(/#/g, '%23'));
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: generateFormatUrl,
args: [text],
});
}
}else{
console.log("No tab found !");
}
});
// The body of this function will be execuetd as a content script inside the
// current page
function generateFormatUrl(json) {
// check if the url is a medium article
let new_url = "https://jsonformatter.curiousconcept.com/?data="+json+"&process=true";
console.log("new_url", new_url);
window.open(new_url, "_blank");
}