2022-02-19 18:34:08 +00:00
|
|
|
let started = false
|
2022-02-19 07:04:13 +00:00
|
|
|
|
|
|
|
function onError(error) {
|
|
|
|
console.error(`Error: ${error}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
function doSendMsg(msg, tabs) {
|
2022-02-19 18:34:08 +00:00
|
|
|
let empty = false;
|
|
|
|
if (document.getElementById('keyBuffer').value.length == 0){
|
|
|
|
empty = true;
|
|
|
|
}
|
2022-02-19 07:04:13 +00:00
|
|
|
for (let tab of tabs) {
|
|
|
|
browser.tabs.sendMessage(
|
|
|
|
tab.id,
|
2022-02-19 18:34:08 +00:00
|
|
|
{keys: msg, isEmpty: empty}
|
2022-02-19 07:04:13 +00:00
|
|
|
).then(response => {
|
|
|
|
console.log("Message from the content script:");
|
|
|
|
console.log(response.response);
|
|
|
|
}).catch(onError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-19 18:34:08 +00:00
|
|
|
function getCurrent(){
|
2022-02-19 07:04:13 +00:00
|
|
|
|
2022-02-19 18:34:08 +00:00
|
|
|
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);
|
|
|
|
}
|
2022-02-19 07:04:13 +00:00
|
|
|
|
|
|
|
|
2022-02-19 18:34:08 +00:00
|
|
|
let sender = async function(e){
|
2022-02-19 07:04:13 +00:00
|
|
|
|
|
|
|
let sendMessageToTabs = function(tabs){
|
|
|
|
doSendMsg(e.key, tabs)
|
|
|
|
}
|
|
|
|
|
|
|
|
browser.tabs.query({
|
|
|
|
currentWindow: true
|
|
|
|
}).then(sendMessageToTabs).catch(onError);
|
|
|
|
|
|
|
|
}
|
2022-02-19 18:34:08 +00:00
|
|
|
setTimeout(function(){getCurrent()}, 10)
|
2022-02-19 07:04:13 +00:00
|
|
|
document.getElementById('keyBuffer').onkeydown = sender
|
|
|
|
//document.getElementById('keyBuffer').onpaste = sender
|