fixes #332 with adding keydown listener to parent (#334)

fixes #332
this adds keydown listener to parent document if there is one.
it does not use background files which uses unnecessary ram
This commit is contained in:
Can Arslan
2018-05-15 09:20:42 +02:00
committed by Ilya Grigorik
parent 0999acc7fc
commit e84e19069d

View File

@@ -203,7 +203,13 @@ chrome.runtime.sendMessage({}, function(response) {
} }
} }
} }
inIframe () {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
function initializeNow(document) { function initializeNow(document) {
// enforce init-once due to redundant callers // enforce init-once due to redundant callers
if (!document.body || document.body.classList.contains('vsc-initialized')) { if (!document.body || document.body.classList.contains('vsc-initialized')) {
@@ -220,8 +226,12 @@ chrome.runtime.sendMessage({}, function(response) {
link.rel = 'stylesheet'; link.rel = 'stylesheet';
document.head.appendChild(link); document.head.appendChild(link);
} }
var docs = Array(document)
if(inIframe())
docs.push(window.top.document);
document.addEventListener('keydown', function(event) { docs.forEach(function(doc) {
doc.addEventListener('keydown', function(event) {
var keyCode = event.keyCode; var keyCode = event.keyCode;
// Ignore if following modifier is active. // Ignore if following modifier is active.
@@ -261,6 +271,7 @@ chrome.runtime.sendMessage({}, function(response) {
return false; return false;
}, true); }, true);
});
function checkForVideo(node, parent, added) { function checkForVideo(node, parent, added) {
if (node.nodeName === 'VIDEO') { if (node.nodeName === 'VIDEO') {