Implemented whitelist.

This commit is contained in:
Adrian Victor 2024-10-24 17:04:26 -03:00
commit bcfe8fdfab
6 changed files with 116 additions and 10 deletions

BIN
img/mango-full.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 KiB

View file

@ -1 +1,17 @@
<p>follow development at <a href="https://git.disroot.org/adrianvictor/mango">Git</a></p> <!DOCTYPE html>
<html>
<head>
<title>Mango</title>
<script src="mangoui.js" defer></script>
<link rel="stylesheet" href="mangoUI.css">
</head>
<body>
<h1 id="title">mango</h1>
<h2 id="source">whitelist</h2>
<textarea placeholder="Domain only, separated by new line, see the example:
example.com
example2.com" id="whitelist" rows="10" cols="30"></textarea><br>
<button id="whitelistSave">save</button>
<p><a href="https://git.disroot.org/adrianvictor/mango">source-code</a></p>
</body>
</html>

View file

@ -1,9 +1,26 @@
var styles = ` console.log("[Mango] Let's get the business done.")
function checkWhitelist(url) {
return browser.storage.local.get("whitelist").then((result) => {
const whitelist = result.whitelist || [];
return whitelist.includes(url);
});
}
const currentHostname = location.hostname;
checkWhitelist(currentHostname).then((isWhitelisted) => {
if (!isWhitelisted) {
const styles = `
* { * {
border-radius: 0 !important; border-radius: 0 !important;
} }
` `;
var injectedStyle = document.createElement("style") const injectedStyle = document.createElement("style");
injectedStyle.type = "text/css" injectedStyle.type = "text/css";
injectedStyle.innerText = styles injectedStyle.innerText = styles;
document.head.appendChild(injectedStyle) document.head.appendChild(injectedStyle);
} else {
console.log("[Mango] Mercy! This page is whitelisted.")
}
});

51
mangoUI.css Normal file
View file

@ -0,0 +1,51 @@
body {
background-color: black;
color: white;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
a {
color: orangered;
text-decoration: none;
}
a:hover {
color: white;
}
body::before {
content: "";
background-image: url(/img/mango-full.jpg);
position: absolute;
background-size: cover;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: -1;
opacity: .25;
}
#whitelist {
background-color: black;
margin-bottom: 10px;
color: white;
}
#title {
font-weight: 300;
font-size: 50px;
margin: 0;
}
#whitelistSave {
border: 1px solid white;
background-color: black;
color: white;
font-size: large;
}
h2 {
font-weight: 300;
margin-top: 0;
}

14
mangoui.js Normal file
View file

@ -0,0 +1,14 @@
document.getElementById('whitelistSave').addEventListener('click', () => {
const whitelist = document.getElementById('whitelist').value.split('\n').map(line => line.trim()).filter(line => line);
browser.storage.local.set({ whitelist: whitelist });
console.log('Whitelist saved!');
});
browser.storage.local.get("whitelist").then((result) => {
const whitelist = result.whitelist || [];
document.getElementById('whitelist').value = whitelist.join('\n');
}).catch((error) => {
console.error("Error retrieving the whitelist:", error);
});

View file

@ -2,7 +2,6 @@
"manifest_version": 2, "manifest_version": 2,
"name": "Mango", "name": "Mango",
"version": "1.0", "version": "1.0",
"description": "Obliterates rounded corners.", "description": "Obliterates rounded corners.",
"icons": { "icons": {
@ -10,6 +9,10 @@
"96": "img/mango-96.jpg" "96": "img/mango-96.jpg"
}, },
"default_icon": {
"96": "img/mango-96.jpg"
},
"browser_specific_settings": { "browser_specific_settings": {
"gecko": { "gecko": {
"id": "adrianvictor.mango@disroot.org" "id": "adrianvictor.mango@disroot.org"
@ -22,6 +25,11 @@
"default_popup": "mango.html" "default_popup": "mango.html"
}, },
"permissions": [
"storage",
"activeTab"
],
"content_scripts": [ "content_scripts": [
{ {
"matches": ["<all_urls>"], "matches": ["<all_urls>"],