Created
April 12, 2022 20:40
-
-
Save dotproto/bd0fb6050bcd3a8aea0e797bf84646b6 to your computer and use it in GitHub Desktop.
Double click action in Manifest V3. Heavily based on Turn Off the Lights.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let alreadyClicked = false; | |
let timer; | |
chrome.action.onClicked.addListener(function(tab) { | |
let wasClicked = alreadyClicked; | |
// Reset state | |
if (wasClicked) { | |
clearTimeout(timer); | |
alreadyClicked = false; | |
chrome.action.setPopup({ | |
tabId: tab.id, | |
popup: "", | |
}); | |
} | |
timer = setTimeout(function() { | |
alreadyClicked = false; | |
chrome.action.setPopup({ | |
tabId: tab.id, | |
popup: "", | |
}); | |
}, 250); | |
if (wasClicked) { | |
return; | |
} | |
alreadyClicked = true; | |
chrome.action.setPopup({ | |
tabId: tab.id, | |
popup: "popup.html" | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Double click action demo", | |
"version": "0.1", | |
"manifest_version": 3, | |
"action": {}, | |
"background": { | |
"service_worker": "background.js" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
<style> | |
body { | |
margin: 0 | |
} | |
div { | |
padding: 2em; | |
white-space: pre; | |
background: salmon; | |
font-weight: bold; | |
} | |
</style> | |
</head> | |
<body> | |
<div> | |
Double click popup | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment