1
0
mirror of https://github.com/nileshtrivedi/better synced 2025-01-16 14:30:31 +01:00
migliori-alternative/contentscript.js

61 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-07-31 22:57:32 +02:00
// document.body.style.border = "15px solid red";
/*
2020-08-02 19:34:43 +02:00
IN PROGRESS:
- List of alternatives should be loaded from a user-specified external source. Can be modified via options.html/options.js
TODO
- Pop-up should be formatted to look better.
- Pop-up should be dismissable (per URL / per domain).
- Once dismissed, popup should not be shown on the same url/domain. Use cookies or localStorage for this.
- Since we're replacing innerHTML, we should protect against XSS attacks.
2020-08-02 20:00:38 +02:00
- Fix and test the options UI
- Test and fix for Chrome, Brave & Firefox
2020-07-31 22:57:32 +02:00
*/
function showBetter(alternative) {
if(!alternative) return;
let betterdiv = document.createElement("div");
2020-08-04 17:09:13 +02:00
betterdiv.style.backgroundColor = "#ffcc49";
2020-07-31 22:57:32 +02:00
betterdiv.style.color = "red";
betterdiv.style.position = "fixed";
betterdiv.style.bottom = "10px";
betterdiv.style.right = "10px";
2020-08-04 17:09:13 +02:00
betterdiv.style.width = "300px";
betterdiv.style.boxShadow = "0px 10px 30px #222222";
betterdiv.style.padding = "12px";
2020-07-31 22:57:32 +02:00
betterdiv.style.height = "200px";
betterdiv.style.textAlign = "center";
betterdiv.style.fontSize = "20px";
2020-08-04 17:09:13 +02:00
let betterBrandText = document.createElement("h1");
betterBrandText.innerHTML = "Better"
betterBrandText.setAttribute("style", "font-size: 32px; color: #222222; font-weight: bold; margin: 12px;")
let alternativeText = document.createElement("p");
alternativeText.innerHTML = alternative
alternativeText.setAttribute("style", "font-size: 20px; color: #222222; font-weight: bold; margin-top: 24px;")
let alternativeCTA = document.createElement("a")
alternativeCTA.innerHTML = "Check it out →"
alternativeCTA.setAttribute("style", "display: inline-block; padding: 12px 24px; background-color: #222222; color: #ffffff; border-radius: 4px;")
let dismissButton = document.createElement("button")
dismissButton.innerHTML = "✗ Dismiss suggestion for this URL"
dismissButton.setAttribute("style", "display: block; font-size: 14px; margin: 16px auto;")
betterdiv.appendChild(betterBrandText);
betterdiv.appendChild(alternativeText);
betterdiv.appendChild(alternativeCTA);
betterdiv.appendChild(dismissButton);
2020-07-31 22:57:32 +02:00
document.body.appendChild(betterdiv);
}
2020-08-02 19:34:43 +02:00
chrome.runtime.sendMessage({type: 'getMatch', url: document.location.href}, (response) => {
if (response) {
showBetter(response);
}
});