Make focus prevent loop more CPU friendly; uncouple from allowautofocus

This commit is contained in:
Oliver Blanthorn 2019-05-27 10:47:04 +01:00
parent fff155e142
commit db7eb12ca6
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
2 changed files with 7 additions and 2 deletions

View file

@ -73,7 +73,7 @@ document.addEventListener("readystatechange", _ =>
)
// Prevent pages from automatically focusing elements on load
config.getAsync("allowautofocus").then(allowautofocus => {
config.getAsync("preventautofocusjackhammer").then(allowautofocus => {
if (allowautofocus === "true") {
return
}
@ -90,7 +90,7 @@ config.getAsync("allowautofocus").then(allowautofocus => {
// On top of blur/focusout events, we need to periodically check the
// activeElement is the one we want because blur/focusout events aren't
// always triggered when document.activeElement changes
const interval = setInterval(() => { if (document.activeElement != elem) focusElem() }, 10)
const interval = setInterval(() => { if (document.activeElement != elem) focusElem() }, 200)
// When the user starts interacting with the page, stop resetting focus
function stopResettingFocus() {
elem.removeEventListener("blur", focusElem)

View file

@ -589,6 +589,11 @@ class default_config {
*/
allowautofocus: "true" | "false" = "true"
/**
* Uses a loop to prevent focus until you interact with a page. Only recommended for use via `seturl` for problematic sites as it can be a little heavy on CPU if running on all tabs. Should be used in conjuction with [[allowautofocus]]
*/
preventautofocusjackhammer: "true" | "false" = "true"
/**
* Controls whether the newtab focuses on tridactyl's newtab page or the firefox urlbar.
*