-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filtered out special characters from selected text
- Loading branch information
1 parent
2965ea2
commit f386739
Showing
1 changed file
with
33 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,39 @@ | ||
|
||
let query = {active: true, currentWindow: true}; | ||
let query = { active: true, currentWindow: true }; | ||
|
||
chrome.tabs.query(query, gotTabs); | ||
function gotTabs(tabs) { | ||
let msg = { | ||
txt: "hello from popup" | ||
} | ||
|
||
chrome.tabs.sendMessage(tabs[0].id, msg, function(response){ | ||
if(response.swor === "error"){ | ||
document.getElementById('word').innerHTML = "Please select a word!"; | ||
} | ||
else{ | ||
dictionary(response.swor) | ||
} | ||
}); | ||
let msg = { | ||
txt: "hello from popup", | ||
}; | ||
|
||
} | ||
chrome.tabs.sendMessage(tabs[0].id, msg, function (response) { | ||
if (response.swor === "error") { | ||
document.getElementById("word").innerHTML = "Please select a word!"; | ||
} else { | ||
let swo = response.swor; | ||
swo = swo.replace(/[^a-zA-Z ]/g, ""); | ||
dictionary(swo); | ||
} | ||
}); | ||
} | ||
|
||
async function dictionary(query){ | ||
let url = `https://api.dictionaryapi.dev/api/v2/entries/en/${query}`; | ||
let response = await fetch(url); | ||
let json = await response.json(); | ||
if(json && !json.title){ | ||
document.getElementById('word').innerHTML = json[0].word; | ||
document.getElementById('phonetic').innerHTML = `${json[0].phonetic ? json[0].phonetic : ""} (${json[0].meanings[0].partOfSpeech})`; | ||
document.getElementById('definition').innerHTML = json[0].meanings[0].definitions[0].definition; | ||
if(json[0].meanings[0].definitions[0].example){ | ||
document.getElementById('example').innerHTML = `Example: ${json[0].meanings[0].definitions[0].example}`; | ||
} | ||
}else if(json.title){ | ||
document.getElementById('error').innerHTML = "⚠ " + json.title; | ||
async function dictionary(query) { | ||
let url = `https://api.dictionaryapi.dev/api/v2/entries/en/${query}`; | ||
let response = await fetch(url); | ||
let json = await response.json(); | ||
if (json && !json.title) { | ||
document.getElementById("word").innerHTML = json[0].word; | ||
document.getElementById("phonetic").innerHTML = `${ | ||
json[0].phonetic ? json[0].phonetic : "" | ||
} (${json[0].meanings[0].partOfSpeech})`; | ||
document.getElementById("definition").innerHTML = | ||
json[0].meanings[0].definitions[0].definition; | ||
if (json[0].meanings[0].definitions[0].example) { | ||
document.getElementById( | ||
"example" | ||
).innerHTML = `Example: ${json[0].meanings[0].definitions[0].example}`; | ||
} | ||
} | ||
} else if (json.title) { | ||
document.getElementById("error").innerHTML = "⚠ " + json.title; | ||
} | ||
} |