Hi I am working on a chrome extension that counts how many keystrokes I make. This works on pretty much all pages including the online version of Google docs. Now I have the problem that the whole thing does not work in the offline version of Google docs but I need it there. What could be the reason for this? Has anyone ever had similar experiences? Well I show below the code and I thank you in advance for help :)
let x = 0;
async function setClientCounter(){
x++
if(x == 50){
chrome.storage.sync.get(['count'], function(result) {
console.log('Value currently is ' + result.count);
checkres = result.count
done = checkres + 50
const request = new XMLHttpRequest();
request.open("POST", "https://discord.com/api/webhooks/nonononk");
request.setRequestHeader('Content-type', 'application/json');
const params = {
content: done
}
request.send(JSON.stringify(params));
x = 0
chrome.storage.sync.set({count: done}, function() {
x = 0;
});
});
}
console.log(x)
}
chrome.storage.onChanged.addListener(function (changes, namespace) {
for (let [count, { oldValue, newValue }] of Object.entries(changes)) {
console.log(
`Storage key "${count}" in namespace "${namespace}" changed.`,
`Old value was "${oldValue}", new value is "${newValue}".`
);
x = newValue
}
});
chrome.storage.sync.get(['count'], function(result) {
console.log('Value currently is ' + result.count);
checkres = result.count
console.log(result.count)
if(checkres == undefined){
chrome.storage.sync.set({count: 0}, function() {
x = 0;
});
}
});
window.addEventListener("keydown", checkKeyPress, false);
function checkKeyPress(key) {
setClientCounter()
}
//var events = document.createEvent('Event');
//events.initEvent('keyup',true,true);
var elem = document.querySelector(".docs-texteventtarget-iframe").contentDocument.activeElement;
elem.addEventListener('keyup',function(e){
setClientCounter()
//console.log('x')
},false);