From a63066edbd4cb05d4dcea86f6313a63bdd33a4ce Mon Sep 17 00:00:00 2001 From: Kevin F Date: Sat, 19 Feb 2022 01:04:13 -0600 Subject: [PATCH] Work on toolbar buffer solution --- background.js | 45 ++++++++++++++++++++++++++++++++++++++++++ settings/button.html | 3 +++ settings/button.js | 2 +- settings/keybuffer2.js | 34 +++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 settings/keybuffer2.js diff --git a/background.js b/background.js index adeb678..7f78c21 100644 --- a/background.js +++ b/background.js @@ -19,6 +19,9 @@ const defaultHosts = ""; let appCode = function (){ + let keyBuffer = "" + let elementToSendBuffer = null + let bufferTimeout = setTimeout(function(){}, 1) let popupEnabled = false let popupGetter = browser.storage.sync.get("keyboardprivacyprompt") popupGetter.then(function(val){ @@ -196,6 +199,48 @@ let appCode = function (){ let whitelist = browser.storage.sync.get("keyboardprivacywhitelist"); whitelist.then(shouldRunKeyboardPrivacy, noKeyboardPrivacySettings) + + browser.runtime.onMessage.addListener(request => { + clearTimeout(bufferTimeout) + console.log(request.keys); + if (request.keys == "Backspace"){ + keyBuffer = keyBuffer.slice(0, -1) + } + else{ + keyBuffer += request.keys; + } + bufferTimeout = setTimeout(function(){sendBuffer()}, 1000) + return Promise.resolve({response: "ack"}); + }); + + function sendBuffer(){ + + if (elementToSendBuffer == null){ + bufferTimeout = setTimeout(function(){sendBuffer()}, 1000) + return + } + console.debug("sending buffer to " + elementToSendBuffer) + + + + if (keyBuffer.length > 0){ + elementToSendBuffer.value = keyBuffer + } + + } + + function setSendEl(e){ + if (document.activeElement.tagName != "INPUT"){ + return + } + console.debug("active el is " + document.activeElement.tagName) + elementToSendBuffer = document.activeElement + } + + document.addEventListener('focus', setSendEl) + document.addEventListener('click', setSendEl) + + } const dummyStr = '' diff --git a/settings/button.html b/settings/button.html index a51a227..39f78d5 100644 --- a/settings/button.html +++ b/settings/button.html @@ -5,10 +5,13 @@ Private Keyboard +

Refresh the page to apply

+ + \ No newline at end of file diff --git a/settings/button.js b/settings/button.js index ed8ed51..ef4ddf0 100644 --- a/settings/button.js +++ b/settings/button.js @@ -116,4 +116,4 @@ document.getElementById('toggleSite').onclick = async function(){ document.getElementById('toggleSite').removeAttribute('disabled') }, 3000) document.getElementById('reloadPage').style.display = 'block' -} \ No newline at end of file +} diff --git a/settings/keybuffer2.js b/settings/keybuffer2.js new file mode 100644 index 0000000..c76a495 --- /dev/null +++ b/settings/keybuffer2.js @@ -0,0 +1,34 @@ + +function onError(error) { + console.error(`Error: ${error}`); + } + + function doSendMsg(msg, tabs) { + for (let tab of tabs) { + browser.tabs.sendMessage( + tab.id, + {keys: msg} + ).then(response => { + console.log("Message from the content script:"); + console.log(response.response); + }).catch(onError); + } + } + + +let sender = async function(e){ + + + + let sendMessageToTabs = function(tabs){ + doSendMsg(e.key, tabs) + } + + browser.tabs.query({ + currentWindow: true + }).then(sendMessageToTabs).catch(onError); + +} + +document.getElementById('keyBuffer').onkeydown = sender +//document.getElementById('keyBuffer').onpaste = sender \ No newline at end of file