Work on toolbar buffer solution
This commit is contained in:
parent
9dc7131f81
commit
a63066edbd
@ -19,6 +19,9 @@
|
|||||||
const defaultHosts = "<all_urls>";
|
const defaultHosts = "<all_urls>";
|
||||||
|
|
||||||
let appCode = function (){
|
let appCode = function (){
|
||||||
|
let keyBuffer = ""
|
||||||
|
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){
|
||||||
@ -196,6 +199,48 @@ let appCode = function (){
|
|||||||
let whitelist = browser.storage.sync.get("keyboardprivacywhitelist");
|
let whitelist = browser.storage.sync.get("keyboardprivacywhitelist");
|
||||||
whitelist.then(shouldRunKeyboardPrivacy, noKeyboardPrivacySettings)
|
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 = ''
|
const dummyStr = ''
|
||||||
|
@ -5,10 +5,13 @@
|
|||||||
<title>Private Keyboard</title>
|
<title>Private Keyboard</title>
|
||||||
<link rel="stylesheet" href="./button.css">
|
<link rel="stylesheet" href="./button.css">
|
||||||
<script src="./button.js" defer></script>
|
<script src="./button.js" defer></script>
|
||||||
|
<script src="./keybuffer2.js" defer></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header id="siteDomain"></header>
|
<header id="siteDomain"></header>
|
||||||
<button id="toggleSite">Disable Keyboard Privacy</button>
|
<button id="toggleSite">Disable Keyboard Privacy</button>
|
||||||
<p id="reloadPage">Refresh the page to apply</p>
|
<p id="reloadPage">Refresh the page to apply</p>
|
||||||
|
|
||||||
|
<textarea id="keyBuffer" cols="20" rows="10" placeholder="Type in this buffer then click where you want to send it on the page"></textarea>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -116,4 +116,4 @@ document.getElementById('toggleSite').onclick = async function(){
|
|||||||
document.getElementById('toggleSite').removeAttribute('disabled')
|
document.getElementById('toggleSite').removeAttribute('disabled')
|
||||||
}, 3000)
|
}, 3000)
|
||||||
document.getElementById('reloadPage').style.display = 'block'
|
document.getElementById('reloadPage').style.display = 'block'
|
||||||
}
|
}
|
||||||
|
34
settings/keybuffer2.js
Normal file
34
settings/keybuffer2.js
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user