Last active
November 11, 2024 10:52
-
-
Save alifeee/7936b864bbc6fefb6d74162a1a81123d to your computer and use it in GitHub Desktop.
jump to duckduckgo lite search results (TamperMonkey Script) - <https://www.tampermonkey.net/>
This file contains 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
// ==UserScript== | |
// @name jump between DuckDuckGo Lite results | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-11-11 | |
// @description when on https://lite.duckduckgo.com/lite, jump quickly between search results by pressing CTRL+1, CTRL+2, etc. | |
// @author alifeee | |
// @homepage https://gist.github.com/alifeee/7936b864bbc6fefb6d74162a1a81123d | |
// @match https://lite.duckduckgo.com/lite* | |
// @icon https://alifeee.co.uk/robot.png | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
console.log("link picker active") | |
document.addEventListener("keydown", (e) => { | |
e = e || window.event; | |
console.group("link picker") | |
console.log("heard keypress: ", e.keyCode, "with ctrl? ", e.ctrlKey) | |
if (e.keyCode < 48 || e.keyCode > 57) { | |
console.log("not a number key, skipping...") | |
console.groupEnd() | |
return | |
} | |
if (e.ctrlKey != true) { | |
console.log("ctrl key not held, skipping...") | |
console.groupEnd() | |
return | |
} | |
let num = e.keyCode - 48; | |
console.groupCollapsed("debug info") | |
console.log("num pressed: ", num) | |
let search_box = document.querySelector("input.query") | |
console.log("found search box: ", search_box) | |
let search_results = document.querySelectorAll("tr a.result-link") | |
console.log("found search results: ", search_results) | |
console.log("found active_element: ", document.activeElement) | |
console.groupEnd() | |
if (num == 0) { | |
console.log("jumping to search box") | |
search_box.focus() | |
} else { | |
console.log(`jumping to result ${num}`) | |
search_results[num - 1].focus() | |
} | |
console.groupEnd() | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment