我正在尝试进行chrome扩展,但是我的事件监听器不会触发。这是我的代码:
document.querySelector(".bird").ondblclick = () => init();
const init = () => {
//hide unnessecary elements
window.scrollTo(0, document.body.scrollHeight);
document.querySelector("#footer").style.opacity = 0;
document.body.style.overflow = "hidden";
//Now we create the game UI
let UI = document.createElement("DIV");
UI.id = "Game-UI";
//after we created the game UI we will append all elements to the UI
let startText = document.createElement("SPAN");
startText.innerHTML = "Press space to start...";
startText.className = "startText";
UI.append(startText);
document.body.append(UI);
//if the UI is loaded then we start doing things this is to prevent the script from executing to fast
startText.addEventListener("load", flicker);
}
const flicker = () => { //this needs to fire
console.log("this");
(() => { //in here we do the flicker animation for the starttext
let on = true;
setInterval(function() {
on != on;
if (on) {
console.log("reached!");
}
}, 2000);
});
}
我在网上搜索,但找不到该问题的任何解决方案。我还注意到,在chrome事件检查器中找不到对注入文件的任何引用。
另外,这是我的清单:
{
"name": "Ontdek Het Wad easteregg",
"version": "1.0",
"description": "Super dom dit",
"content_scripts": [
{
"matches": ["https://www.ontdekhetwad.nl/*"],
"run_at": "document_end",
"js": ["/js/src/game.js", "/js/includes/matter.min.js"],
"css": ["/css/gameUI.css"]
}
],
"manifest_version": 2
}