mirror of
https://github.com/nileshtrivedi/better
synced 2025-01-15 05:56:28 +01:00
feat: permanently dismiss popup
This commit is contained in:
parent
308fd86d7f
commit
562d35d6dd
@ -35,7 +35,7 @@ function onStartup(){
|
|||||||
function getMatch(url){
|
function getMatch(url){
|
||||||
var match = BETTER_ALTERNATIVES.find(pattern => url.match(new RegExp(pattern.urlPattern)));
|
var match = BETTER_ALTERNATIVES.find(pattern => url.match(new RegExp(pattern.urlPattern)));
|
||||||
if(match && match.alternatives)
|
if(match && match.alternatives)
|
||||||
return match.alternatives;
|
return match;
|
||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,8 +53,9 @@ function createRecommendedAlt(recommendedAlternative) {
|
|||||||
return recommendedAlt;
|
return recommendedAlt;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showBetter(alternatives) {
|
function showBetter(match) {
|
||||||
if(!alternatives) return;
|
if(!match || !match.alternatives) return;
|
||||||
|
let alternatives = match.alternatives;
|
||||||
|
|
||||||
let betterdiv = document.createElement("div");
|
let betterdiv = document.createElement("div");
|
||||||
betterdiv.setAttribute("style",
|
betterdiv.setAttribute("style",
|
||||||
@ -71,12 +72,35 @@ function showBetter(alternatives) {
|
|||||||
let dismissButton = document.createElement("button");
|
let dismissButton = document.createElement("button");
|
||||||
dismissButton.innerHTML = "✗ Dismiss suggestion for this URL";
|
dismissButton.innerHTML = "✗ Dismiss suggestion for this URL";
|
||||||
dismissButton.setAttribute("style", "display: block; font-size: 14px; margin: 16px auto;");
|
dismissButton.setAttribute("style", "display: block; font-size: 14px; margin: 16px auto;");
|
||||||
|
dismissButton.addEventListener("click", () => {
|
||||||
|
document.body.removeChild(betterdiv);
|
||||||
|
dismissPermanently(match);
|
||||||
|
})
|
||||||
|
|
||||||
betterdiv.appendChild(dismissButton);
|
betterdiv.appendChild(dismissButton);
|
||||||
document.body.appendChild(betterdiv);
|
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) => {
|
chrome.runtime.sendMessage({type: 'getMatch', url: document.location.href}, (response) => {
|
||||||
if (response) {
|
if (response) {
|
||||||
showBetter(response);
|
ifNotDissmissed(response, showBetter);
|
||||||
}
|
}
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user