Prevent focus() call when loading book list

DiscussieHacking LibraryThing

Sluit je aan bij LibraryThing om te posten.

Prevent focus() call when loading book list

1Keeline
mrt 21, 2022, 3:44 pm

Even with a fast connection, I sometimes find myself clicking on the "Search your library" field, beginning to type, and having the content wiped out as the page finishes loading.

In looking for the code I see this:


<script type="text/javascript">var searchText = 'Search your library';


function init_searchBox() {
var f = document.getElementById('quickSearchForm');
var sb = document.getElementById('quickSearchbox');


if (sb.value == searchText) {
//sb.style.color = '#999';
}


sb.onfocus = function() {
if (sb.value == searchText) sb.value = '';
sb.style.color = '#222';
try {
$J('#catalog_quicksearch_button').addClass('ltbtn-activated');
}
catch(e) { mmlog('js error: 23sadfasdfsd77usf34234234ppddh'); mmlog(e, 'error'); }
}

sb.onblur = function() {

if (sb.value != '') return;
//sb.style.color = '#999';
sb.value = searchText;
try {
$J('#catalog_quicksearch_button').removeClass('ltbtn-activated');
}
catch(e) { mmlog('js error: 23sadfasf34234234ppddh'); mmlog(e, 'error'); }
}
}


It seems like it should be possible with some TamperMonkey script (Chrome) to disable this feature that clears the field and places the focus there.

I have other websites (like WorldCat) where the focus disrupts things like using the space bar for scrolling. So if I can see a copy working for LT, I might be able to adapt it for WorldCat.

Probably there are other websites where I do want the focus. It would be nice to let the system work for me instead of me fighting it or having to wait for the page to render if there are 100 items on the list.

James