Skip to content

Instantly share code, notes, and snippets.

@acenturyandabit
Created September 3, 2020 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acenturyandabit/026d0d7c2035a34956af2c43f7269f7b to your computer and use it in GitHub Desktop.
Save acenturyandabit/026d0d7c2035a34956af2c43f7269f7b to your computer and use it in GitHub Desktop.
in case double click doesnt work for some reason
(() => {
Element.prototype.pre_doubleclick_addEventListener = Element.prototype.addEventListener;
Element.prototype.addEventListener = function (ename, fn) {
let clickCount = 0;
let singleClickTimer = 0;
if (ename == "dblclick") {
this.pre_doubleclick_addEventListener("click", (e) => {
clickCount++;
if (clickCount == 1) {
singleClickTimer = setTimeout(function () {
clickCount = 0;
}, 400);
} else if (clickCount == 2) {
clearTimeout(singleClickTimer);
clickCount = 0;
fn(e);
}
})
} else {
this.pre_doubleclick_addEventListener(...arguments);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment