Greasy Fork

Greasy Fork is available in English.

Geoguessr spacebar shortcut

Use spacebar to automatically click any big green button on geoguessr.com

当前为 2022-12-24 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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();
        }
    }
}