Skip to content

Instantly share code, notes, and snippets.

@dotproto
Created April 12, 2022 20:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotproto/bd0fb6050bcd3a8aea0e797bf84646b6 to your computer and use it in GitHub Desktop.
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.
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"
});
});
{
"name": "Double click action demo",
"version": "0.1",
"manifest_version": 3,
"action": {},
"background": {
"service_worker": "background.js"
}
}
<!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