Finished popup approach
This commit is contained in:
parent
b3c0097270
commit
866777686c
@ -20,9 +20,7 @@ let lastActive = null
|
|||||||
const defaultHosts = "<all_urls>";
|
const defaultHosts = "<all_urls>";
|
||||||
|
|
||||||
let appCode = function (){
|
let appCode = function (){
|
||||||
let keyBuffer = ""
|
let lastActive = document.createElement("p")
|
||||||
let elementToSendBuffer = null
|
|
||||||
let bufferTimeout = setTimeout(function(){}, 1)
|
|
||||||
let popupEnabled = false
|
let popupEnabled = false
|
||||||
let popupGetter = browser.storage.sync.get("keyboardprivacyprompt")
|
let popupGetter = browser.storage.sync.get("keyboardprivacyprompt")
|
||||||
popupGetter.then(function(val){
|
popupGetter.then(function(val){
|
||||||
@ -201,65 +199,37 @@ let appCode = function (){
|
|||||||
whitelist.then(shouldRunKeyboardPrivacy, noKeyboardPrivacySettings)
|
whitelist.then(shouldRunKeyboardPrivacy, noKeyboardPrivacySettings)
|
||||||
|
|
||||||
|
|
||||||
|
document.addEventListener('focus', function(e){
|
||||||
|
let active = document.activeElement;
|
||||||
|
if (active.tagName == "INPUT" || active.tagName == "TEXTAREA") {
|
||||||
|
lastActive = active
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener(request => {
|
browser.runtime.onMessage.addListener(request => {
|
||||||
|
let active = document.activeElement
|
||||||
|
|
||||||
console.log(request.keys);
|
if (request.getCurrent){
|
||||||
if (request.keys == "GetSet"){
|
if (active.tagName != "INPUT" && active.tagName != "TEXTAREA") {
|
||||||
keyBuffer = elementToSendBuffer.value
|
if (lastActive.tagName != "INPUT" && lastActive.tagName != "TEXTAREA"){
|
||||||
return Promise.resolve({response: elementToSendBuffer.value});
|
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});
|
||||||
|
}
|
||||||
|
if (active.tagName != "INPUT" && active.tagName != "TEXTAREA"){
|
||||||
|
|
||||||
clearTimeout(bufferTimeout)
|
lastActive.value = request.keys
|
||||||
|
|
||||||
if (request.keys == "Backspace"){
|
|
||||||
keyBuffer = keyBuffer.slice(0, -1)
|
|
||||||
}
|
|
||||||
else if (request.keys == "Tab"){
|
|
||||||
keyBuffer += "\t"
|
|
||||||
}
|
|
||||||
else if(request.keys.length > 4){
|
|
||||||
// pass
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
keyBuffer += request.keys;
|
document.activeElement.value = request.keys
|
||||||
|
lastActive = document.activeElement
|
||||||
}
|
}
|
||||||
if (request.isEmpty){
|
|
||||||
keyBuffer = ""
|
|
||||||
sendBuffer()
|
|
||||||
}
|
|
||||||
bufferTimeout = setTimeout(function(){sendBuffer()}, 100)
|
|
||||||
return Promise.resolve({response: "ack"});
|
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 = ''
|
const dummyStr = ''
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Private Keyboard",
|
"name": "Private Keyboard",
|
||||||
"version": "1.9",
|
"version": "2.0",
|
||||||
|
|
||||||
|
|
||||||
"description": "Protect against keyboard biometrics",
|
"description": "Protect against keyboard biometrics",
|
||||||
@ -32,6 +32,15 @@
|
|||||||
"default_popup": "settings/button.html"
|
"default_popup": "settings/button.html"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"commands": {
|
||||||
|
"_execute_browser_action": {
|
||||||
|
"suggested_key": {
|
||||||
|
"default": "Ctrl+1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"browser_specific_settings": {
|
"browser_specific_settings": {
|
||||||
"gecko": {
|
"gecko": {
|
||||||
|
@ -13,6 +13,6 @@
|
|||||||
<p id="reloadPage">Refresh the page to apply</p>
|
<p id="reloadPage">Refresh the page to apply</p>
|
||||||
|
|
||||||
<br>
|
<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>
|
</body>
|
||||||
</html>
|
</html>
|
@ -5,14 +5,11 @@ function onError(error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function doSendMsg(msg, tabs) {
|
function doSendMsg(msg, tabs) {
|
||||||
let empty = false;
|
|
||||||
if (document.getElementById('keyBuffer').value.length == 0){
|
|
||||||
empty = true;
|
|
||||||
}
|
|
||||||
for (let tab of tabs) {
|
for (let tab of tabs) {
|
||||||
browser.tabs.sendMessage(
|
browser.tabs.sendMessage(
|
||||||
tab.id,
|
tab.id,
|
||||||
{keys: msg, isEmpty: empty}
|
{keys: msg, getCurrent: false}
|
||||||
).then(response => {
|
).then(response => {
|
||||||
console.log("Message from the content script:");
|
console.log("Message from the content script:");
|
||||||
console.log(response.response);
|
console.log(response.response);
|
||||||
@ -20,26 +17,6 @@ function onError(error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrent(){
|
|
||||||
|
|
||||||
browser.tabs.query({
|
|
||||||
currentWindow: true
|
|
||||||
}).then(function(tabs){
|
|
||||||
for (let tab of tabs) {
|
|
||||||
browser.tabs.sendMessage(
|
|
||||||
tab.id,
|
|
||||||
{keys: "GetSet", isEmpty: 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){
|
let sender = async function(e){
|
||||||
|
|
||||||
@ -58,14 +35,42 @@ let sender = async function(e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
let sendMessageToTabs = function(tabs){
|
let sendMessageToTabs = function(tabs){
|
||||||
doSendMsg(e.key, tabs)
|
doSendMsg(document.getElementById('keyBuffer').value, tabs)
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.tabs.query({
|
browser.tabs.query({
|
||||||
currentWindow: true
|
currentWindow: true,
|
||||||
|
active: true
|
||||||
}).then(sendMessageToTabs).catch(onError);
|
}).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').onkeydown = sender
|
||||||
//document.getElementById('keyBuffer').onpaste = sender
|
document.getElementById('keyBuffer').onpaste = sender
|
Loading…
Reference in New Issue
Block a user