Finished popup approach

button-approach-no-buffer
Kevin F 6 months ago
parent b3c0097270
commit 866777686c
  1. 74
      background.js
  2. 11
      manifest.json
  3. 2
      settings/button.html
  4. 63
      settings/keybuffer2.js

@ -20,9 +20,7 @@ let lastActive = null
const defaultHosts = "<all_urls>";
let appCode = function (){
let keyBuffer = ""
let elementToSendBuffer = null
let bufferTimeout = setTimeout(function(){}, 1)
let lastActive = document.createElement("p")
let popupEnabled = false
let popupGetter = browser.storage.sync.get("keyboardprivacyprompt")
popupGetter.then(function(val){
@ -201,65 +199,37 @@ let appCode = function (){
whitelist.then(shouldRunKeyboardPrivacy, noKeyboardPrivacySettings)
browser.runtime.onMessage.addListener(request => {
console.log(request.keys);
if (request.keys == "GetSet"){
keyBuffer = elementToSendBuffer.value
return Promise.resolve({response: elementToSendBuffer.value});
document.addEventListener('focus', function(e){
let active = document.activeElement;
if (active.tagName == "INPUT" || active.tagName == "TEXTAREA") {
lastActive = active
}
})
clearTimeout(bufferTimeout)
browser.runtime.onMessage.addListener(request => {
let active = document.activeElement
if (request.keys == "Backspace"){
keyBuffer = keyBuffer.slice(0, -1)
}
else if (request.keys == "Tab"){
keyBuffer += "\t"
if (request.getCurrent){
if (active.tagName != "INPUT" && active.tagName != "TEXTAREA") {
if (lastActive.tagName != "INPUT" && lastActive.tagName != "TEXTAREA"){
console.debug("no current active or last active")
return Promise.resolve({response: false});
}
return Promise.resolve({response: lastActive.value});
}
return Promise.resolve({response: active.value});
}
else if(request.keys.length > 4){
// pass
if (active.tagName != "INPUT" && active.tagName != "TEXTAREA"){
lastActive.value = request.keys
}
else{
keyBuffer += request.keys;
}
if (request.isEmpty){
keyBuffer = ""
sendBuffer()
document.activeElement.value = request.keys
lastActive = document.activeElement
}
bufferTimeout = setTimeout(function(){sendBuffer()}, 100)
return Promise.resolve({response: "ack"});
});
function sendBuffer(){
if (elementToSendBuffer == null){
bufferTimeout = setTimeout(function(){sendBuffer()}, 100)
return
}
console.debug("sending buffer to " + elementToSendBuffer)
elementToSendBuffer.value = keyBuffer
}
function setSendEl(e){
let activeEl = document.activeElement
if (activeEl.tagName != "INPUT" && activeEl.tagName != "TEXTAREA"){
keyBuffer = ""
return
}
console.debug("active el is " + activeEl.tagName)
elementToSendBuffer = activeEl
keyBuffer = activeEl.value
}
document.addEventListener('focus', setSendEl)
document.addEventListener('click', setSendEl)
}
const dummyStr = ''

@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "Private Keyboard",
"version": "1.9",
"version": "2.0",
"description": "Protect against keyboard biometrics",
@ -32,6 +32,15 @@
"default_popup": "settings/button.html"
},
"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+1"
}
}
},
"browser_specific_settings": {
"gecko": {

@ -13,6 +13,6 @@
<p id="reloadPage">Refresh the page to apply</p>
<br>
<textarea id="keyBuffer" cols="20" rows="10" placeholder="Text typed here will be sent to active input/textarea elements."></textarea>
<textarea tabindex="0" id="keyBuffer" cols="20" rows="10" placeholder="Text typed here will be sent to active input/textarea elements. Breaks on many sites, but is faster than typing directly on the page"></textarea>
</body>
</html>

@ -5,40 +5,17 @@ function onError(error) {
}
function doSendMsg(msg, tabs) {
let empty = false;
if (document.getElementById('keyBuffer').value.length == 0){
empty = true;
}
for (let tab of tabs) {
browser.tabs.sendMessage(
tab.id,
{keys: msg, isEmpty: empty}
).then(response => {
console.log("Message from the content script:");
console.log(response.response);
}).catch(onError);
}
}
function getCurrent(){
browser.tabs.query({
currentWindow: true
}).then(function(tabs){
for (let tab of tabs) {
browser.tabs.sendMessage(
tab.id,
{keys: "GetSet", isEmpty: false}
{keys: msg, getCurrent: false}
).then(response => {
console.log("Message from the content script:");
console.log(response.response);
document.getElementById('keyBuffer').value = response.response
}).catch(onError);
}
}).catch(onError);
}
}
let sender = async function(e){
@ -58,14 +35,42 @@ let sender = async function(e){
}
let sendMessageToTabs = function(tabs){
doSendMsg(e.key, tabs)
doSendMsg(document.getElementById('keyBuffer').value, tabs)
}
browser.tabs.query({
currentWindow: true
currentWindow: true,
active: true
}).then(sendMessageToTabs).catch(onError);
}
setTimeout(function(){getCurrent()}, 10)
function getCurrent(){
browser.tabs.query({
currentWindow: true,
active: true
}).then(function(tabs){
for (let tab of tabs) {
browser.tabs.sendMessage(
tab.id,
{keys: "", getCurrent: true}
).then(response => {
console.debug(response)
if (response.response === undefined || response.response === false){
//document.getElementById('keyBuffer').value = "No element in focus. Focus an element and reopen this."
return
}
document.getElementById('keyBuffer').value = response.response
}).catch(onError);
}
}).catch(onError);
}
getCurrent()
document.getElementById("keyBuffer").focus()
document.getElementById('keyBuffer').onkeydown = sender
//document.getElementById('keyBuffer').onpaste = sender
document.getElementById('keyBuffer').onpaste = sender
Loading…
Cancel
Save