diff --git a/icons/keyboard-ico.png b/icons/keyboard-ico.png index 1438985..67c290d 100644 Binary files a/icons/keyboard-ico.png and b/icons/keyboard-ico.png differ diff --git a/icons/logo-big-dark.png b/icons/logo-big-dark.png new file mode 100644 index 0000000..135e6e3 Binary files /dev/null and b/icons/logo-big-dark.png differ diff --git a/manifest.json b/manifest.json index ce437db..7a37d1c 100644 --- a/manifest.json +++ b/manifest.json @@ -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": [ "", - "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" diff --git a/settings/button.css b/settings/button.css new file mode 100644 index 0000000..73d60a3 --- /dev/null +++ b/settings/button.css @@ -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%; +} + diff --git a/settings/button.html b/settings/button.html new file mode 100644 index 0000000..a51a227 --- /dev/null +++ b/settings/button.html @@ -0,0 +1,14 @@ + + + + + Private Keyboard + + + + +
+ +

Refresh the page to apply

+ + \ No newline at end of file diff --git a/settings/button.js b/settings/button.js new file mode 100644 index 0000000..ed8ed51 --- /dev/null +++ b/settings/button.js @@ -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' +} \ No newline at end of file