Added whitelist button
This commit is contained in:
parent
9485d43800
commit
cd69333f41
Binary file not shown.
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.4 KiB |
BIN
icons/logo-big-dark.png
Normal file
BIN
icons/logo-big-dark.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
@ -2,7 +2,7 @@
|
||||
|
||||
"manifest_version": 2,
|
||||
"name": "Private Keyboard",
|
||||
"version": "1.5",
|
||||
"version": "1.6",
|
||||
|
||||
|
||||
"description": "Protect against keyboard biometrics",
|
||||
@ -12,7 +12,8 @@
|
||||
|
||||
"permissions": [
|
||||
"<all_urls>",
|
||||
"storage"
|
||||
"storage",
|
||||
"tabs"
|
||||
],
|
||||
|
||||
|
||||
@ -24,6 +25,14 @@
|
||||
"page": "settings/options.html"
|
||||
},
|
||||
|
||||
|
||||
"browser_action": {
|
||||
"default_icon": "icons/keyboard-ico.png",
|
||||
"default_title": "Private Keyboard",
|
||||
"default_popup": "settings/button.html"
|
||||
},
|
||||
|
||||
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"id": "keyboardaddon@voidnet.tech"
|
||||
|
41
settings/button.css
Normal file
41
settings/button.css
Normal file
@ -0,0 +1,41 @@
|
||||
body{
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
header{
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
#reloadPage{
|
||||
display: none;
|
||||
}
|
||||
|
||||
button {
|
||||
margin-top: 10px;
|
||||
box-shadow:inset 0px 1px 0px 0px #bee2f9;
|
||||
background-color:#307cac;
|
||||
border-radius:6px;
|
||||
border:1px solid #3866a3;
|
||||
display:inline-block;
|
||||
cursor:pointer;
|
||||
color:white;
|
||||
font-family:Arial;
|
||||
font-size:15px;
|
||||
font-weight:bold;
|
||||
padding:6px 10px;
|
||||
text-decoration:none;
|
||||
text-shadow:0px 1px 0px #7cacde;
|
||||
width: 75%;
|
||||
margin-left: 15%;
|
||||
}
|
||||
button:hover {
|
||||
background:linear-gradient(to bottom, #468ccf 5%, #63b8ee 100%);
|
||||
background-color:#468ccf;
|
||||
}
|
||||
button:active {
|
||||
position:relative;
|
||||
top:1px;
|
||||
}
|
||||
button[disabled=true]{
|
||||
opacity: 50%;
|
||||
}
|
||||
|
14
settings/button.html
Normal file
14
settings/button.html
Normal file
@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Private Keyboard</title>
|
||||
<link rel="stylesheet" href="./button.css">
|
||||
<script src="./button.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<header id="siteDomain"></header>
|
||||
<button id="toggleSite">Disable Keyboard Privacy</button>
|
||||
<p id="reloadPage">Refresh the page to apply</p>
|
||||
</body>
|
||||
</html>
|
119
settings/button.js
Normal file
119
settings/button.js
Normal file
@ -0,0 +1,119 @@
|
||||
function reportError(e){
|
||||
console.debug(e)
|
||||
}
|
||||
|
||||
function extractHostname(url) {
|
||||
// Credit to stackoverflow users https://stackoverflow.com/a/23945027
|
||||
let hostname = ''
|
||||
//find & remove protocol (http, ftp, etc.) and get hostname
|
||||
|
||||
if (url.indexOf("//") > -1) {
|
||||
hostname = url.split('/')[2];
|
||||
}
|
||||
else {
|
||||
hostname = url.split('/')[0];
|
||||
}
|
||||
|
||||
//find & remove port number
|
||||
hostname = hostname.split(':')[0];
|
||||
//find & remove "?"
|
||||
hostname = hostname.split('?')[0];
|
||||
|
||||
return hostname;
|
||||
}
|
||||
|
||||
browser.storage.sync.get("keyboardprivacywhitelist")
|
||||
|
||||
.then(function(val){
|
||||
if (typeof val.keyboardprivacywhitelist === 'undefined'){
|
||||
return
|
||||
}
|
||||
browser.tabs.query({active: true, currentWindow: true})
|
||||
.then(function(tabVal){
|
||||
let hostname = extractHostname(tabVal[0].url).replace('www.', '')
|
||||
document.getElementById('siteDomain').innerText = hostname
|
||||
if (val.keyboardprivacywhitelist.includes(hostname)) {
|
||||
document.getElementById('toggleSite').innerText = 'Enable Keyboard Privacy'
|
||||
}
|
||||
})
|
||||
.catch(reportError);
|
||||
},
|
||||
function(val){
|
||||
console.debug(val)
|
||||
}
|
||||
)
|
||||
|
||||
function fixDuplicateCommas(){
|
||||
// Yeah i'm lazy
|
||||
browser.storage.sync.get("keyboardprivacywhitelist")
|
||||
|
||||
.then(function(val){
|
||||
let whitelist = val.keyboardprivacywhitelist
|
||||
console.debug('whitelist ' + whitelist)
|
||||
if (typeof val.keyboardprivacywhitelist === 'undefined' || val.keyboardprivacywhitelist == ''){
|
||||
return
|
||||
}
|
||||
whitelist = whitelist.replaceAll(',,', '')
|
||||
if (whitelist.endsWith(',')){
|
||||
whitelist = whitelist.substring(0, whitelist.length - 1);
|
||||
}
|
||||
browser.storage.sync.set({
|
||||
keyboardprivacywhitelist: whitelist
|
||||
});
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function changeWhitelist(domain, add){
|
||||
browser.storage.sync.get("keyboardprivacywhitelist")
|
||||
|
||||
.then(function(val){
|
||||
let whitelist = val.keyboardprivacywhitelist
|
||||
let comma = ','
|
||||
if (typeof val.keyboardprivacywhitelist === 'undefined' || val.keyboardprivacywhitelist == ''){
|
||||
whitelist = ''
|
||||
comma = ''
|
||||
}
|
||||
if (domain.startsWith('www.')){
|
||||
domain = domain.replace('www.', '')
|
||||
}
|
||||
if (add){
|
||||
browser.storage.sync.set({
|
||||
keyboardprivacywhitelist: whitelist + comma + domain
|
||||
});
|
||||
}
|
||||
else{
|
||||
if (! whitelist.endsWith(domain)){
|
||||
comma = ','
|
||||
}
|
||||
else{
|
||||
comma = ''
|
||||
}
|
||||
browser.storage.sync.set({
|
||||
keyboardprivacywhitelist: whitelist.replace(domain + comma, '')
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
document.getElementById('toggleSite').onclick = async function(){
|
||||
if (document.getElementById('toggleSite').getAttribute('disabled')){
|
||||
console.debug('disabled still')
|
||||
return
|
||||
}
|
||||
document.getElementById('toggleSite').setAttribute('disabled', true)
|
||||
if (document.getElementById('toggleSite').innerText.startsWith('Disable')){
|
||||
document.getElementById('toggleSite').innerText = 'Enable Keyboard Privacy'
|
||||
changeWhitelist(document.getElementById('siteDomain').innerText, true)
|
||||
}
|
||||
else if (document.getElementById('toggleSite').innerText.startsWith('Enable')){
|
||||
document.getElementById('toggleSite').innerText = 'Disable Keyboard Privacy'
|
||||
changeWhitelist(document.getElementById('siteDomain').innerText, false)
|
||||
}
|
||||
setTimeout(function(){fixDuplicateCommas()}, 1000)
|
||||
setTimeout(function(){
|
||||
document.getElementById('toggleSite').removeAttribute('disabled')
|
||||
}, 3000)
|
||||
document.getElementById('reloadPage').style.display = 'block'
|
||||
}
|
Loading…
Reference in New Issue
Block a user