Greasy Fork is available in English.
Use spacebar to automatically click any big green button on geoguessr.com
当前为
// ==UserScript==
// @name Geoguessr spacebar shortcut
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Use spacebar to automatically click any big green button on geoguessr.com
// @author You
// @license MIT
// @match https://www.geoguessr.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=geoguessr.com
// @grant none
// @require https://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==
// prevent space from scrolling down
window.addEventListener('keydown', function(e) {
if(e.keyCode == 32 && e.target == document.body) {
e.preventDefault();
}
});
document.body.onkeyup = function(e) {
// if space is pressed and text input isn't focused
var el = document.activeElement;
var input_selected = (el && (el.tagName.toLowerCase() == 'input' && el.type == 'text' ||
el.tagName.toLowerCase() == 'textarea'))
var text_elem = $("span").filter( function() { return ($(this).text() ==='Guess')} );
if ((e.key == " " ||
e.code == "Space" ||
e.keyCode == 32)
&& !input_selected
&& text_elem.length == 0
) {
// get all elements with the prefix for the primary button class
var elems = $("[class*='button_variantPrimary_']");
if (elems.length){
// click the first one
elems[0].click();
}
}
}