Skip to content

Instantly share code, notes, and snippets.

@SilverEzhik
Last active August 29, 2019 14:59
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 SilverEzhik/27ef59d8fda89f9f460a5aeaab05d6dd to your computer and use it in GitHub Desktop.
Save SilverEzhik/27ef59d8fda89f9f460a5aeaab05d6dd to your computer and use it in GitHub Desktop.
Fix DuckDuckGo middle click. What the heck is that JavaScript madness?
// ==UserScript==
// @name Fix DuckDuckGo middle click
// @description What the heck is that JavaScript madness?
// @include https://*duckduckgo.com/*
// @version 1
// @grant none
// @run-at document-idle
// ==/UserScript==
function undoClicky() {
//console.log("awoo");
//console.log(document.getElementsByClassName("result"));
for (let result of document.getElementsByClassName("result")) {
//console.log(result);
if (result.classList.contains("result--more")) {
result.addEventListener("click", undoClicky);
result.addEventListener("click", function(){setTimeout(undoClicky, 1000)});
result.addEventListener("click", function(){setTimeout(undoClicky, 5000)});
} else if (!result.classList.contains("middle-click-fixed")) {
result.classList.add("middle-click-fixed");
result.outerHTML = result.outerHTML; // this is the best way to get rid of event listeners. no, really.
}
}
}
undoClicky();
setTimeout(undoClicky, 500);
setTimeout(undoClicky, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment