1
0
mirror of https://github.com/nileshtrivedi/better synced 2024-12-28 06:00:37 +01:00

feat: permanently dismiss popup

This commit is contained in:
Mitesh Shah 2020-08-06 16:11:23 +05:30
parent 308fd86d7f
commit 562d35d6dd
2 changed files with 28 additions and 4 deletions

View File

@ -35,7 +35,7 @@ function onStartup(){
function getMatch(url){
var match = BETTER_ALTERNATIVES.find(pattern => url.match(new RegExp(pattern.urlPattern)));
if(match && match.alternatives)
return match.alternatives;
return match;
else return null;
}

View File

@ -53,8 +53,9 @@ function createRecommendedAlt(recommendedAlternative) {
return recommendedAlt;
}
function showBetter(alternatives) {
if(!alternatives) return;
function showBetter(match) {
if(!match || !match.alternatives) return;
let alternatives = match.alternatives;
let betterdiv = document.createElement("div");
betterdiv.setAttribute("style",
@ -71,12 +72,35 @@ function showBetter(alternatives) {
let dismissButton = document.createElement("button");
dismissButton.innerHTML = "✗ Dismiss suggestion for this URL";
dismissButton.setAttribute("style", "display: block; font-size: 14px; margin: 16px auto;");
dismissButton.addEventListener("click", () => {
document.body.removeChild(betterdiv);
dismissPermanently(match);
})
betterdiv.appendChild(dismissButton);
document.body.appendChild(betterdiv);
}
function dismissPermanently(match) {
let key = `dismiss@${match.urlPattern}`
chrome.storage.local.set({
[key]: true,
});
}
function ifNotDissmissed(match, callback) {
let key = `dismiss@${match.urlPattern}`
chrome.storage.local.get(key, (item) => {
if (item && item[key]) {
return;
} else {
callback(match);
}
})
}
chrome.runtime.sendMessage({type: 'getMatch', url: document.location.href}, (response) => {
if (response) {
showBetter(response);
ifNotDissmissed(response, showBetter);
}
});