Geoguessr BearSolver 🧸

Displays location info and map for Geoguessr. Author Note: Make sure you have turned on developer-mode in your browsers extension settings, otherwise tampermonkey is unable to "inject".

目前為 2025-02-28 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Geoguessr BearSolver 🧸 
// @namespace    http://tampermonkey.net/
// @version      Alpha-v1
// @description  Displays location info and map for Geoguessr. Author Note: Make sure you have turned on developer-mode in your browsers extension settings, otherwise tampermonkey is unable to "inject".
// @author       @AnEntangledMind
// @license      MIT
// @match        https://www.geoguessr.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=geoguessr.com
// @grant        GM_webRequest
// ==/UserScript==



/*
Copyright (c) 2025 @AnEntangledMind (gf.qytechs.cn)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to 
the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

'use strict';

const version = "Alpha-v1";

const globalVariables = {
    lat: 0,
    lng: 0,
    toggled: true,
    label: null,
    map: null,
    mapContainer: null,
    marker: null,
};


/************************************************************
 * Utility to apply multiple inline styles at once
 ************************************************************/
function applyStyles(element, styles) {
    Object.assign(element.style, styles);
}

/************************************************************
 * Class: UITab
 * Represents one draggable tab/panel in the UI
 ************************************************************/
class UITab {
    constructor(name, parent) {
        this.name = name;
        this.parent = parent;     
        this.tabElement = null;   
        this.contentElement = null; 
        this.init();
    }

    init() {
        const tab = document.createElement('div');
        this.tabElement = tab;
        applyStyles(tab, {
            position: 'absolute',
            top: '100px',
            left: '100px',
            width: '220px',
            backgroundColor: 'rgba(15,15,15,0.95)',
            border: '1px solid #5B5B5B',
            borderRadius: '6px',
            fontFamily: 'sans-serif',
            color: '#FFFFFF',
            zIndex: 1000, 
            userSelect: 'none',
        });

        const header = document.createElement('div');
        applyStyles(header, {
            background: 'linear-gradient(90deg, #212121, #2D2D2D)',
            padding: '8px',
            borderTopLeftRadius: '6px',
            borderTopRightRadius: '6px',
            cursor: 'move',
            fontWeight: 'bold',
            fontSize: '14px',
        });
        header.innerText = this.name;
        tab.appendChild(header);

        let isDragging = false;
        let offsetX = 0, offsetY = 0;

        header.addEventListener('mousedown', (e) => {
            isDragging = true;
            offsetX = e.clientX - tab.offsetLeft;
            offsetY = e.clientY - tab.offsetTop;
        });

        document.addEventListener('mousemove', (e) => {
            if (!isDragging) return;
            tab.style.left = (e.clientX - offsetX) + 'px';
            tab.style.top = (e.clientY - offsetY) + 'px';
        });

        document.addEventListener('mouseup', () => {
            isDragging = false;
        });

        const content = document.createElement('div');
        this.contentElement = content;
        applyStyles(content, {
            padding: '8px',
        });
        tab.appendChild(content);

        this.parent.mainContainer.appendChild(tab);
    }

    /************************************************************
     * Below are the "add" methods for controls:
     *   addButton, addToggle, addInput, addKeybind, addLabel, addSeparator
     ************************************************************/

    addButton(label, onClick) {
        const btn = document.createElement('button');
        btn.innerText = label;
        applyStyles(btn, {
            width: '100%',
            marginBottom: '6px',
            padding: '6px 8px',
            backgroundColor: '#3C3C3C',
            color: '#FFFFFF',
            border: 'none',
            borderRadius: '4px',
            cursor: 'pointer',
            textAlign: 'left',
        });

        btn.addEventListener('mouseover', () => {
            btn.style.backgroundColor = '#5A5A5A';
        });
        btn.addEventListener('mouseout', () => {
            btn.style.backgroundColor = '#3C3C3C';
        });

        btn.addEventListener('click', () => {
            if (typeof onClick === 'function') {
                onClick();
            }
        });

        this.contentElement.appendChild(btn);
        return btn;
    }

    addToggle(label, defaultState, onToggle) {
        const container = document.createElement('div');
        applyStyles(container, {
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'space-between',
            marginBottom: '6px',
        });

        const text = document.createElement('span');
        text.innerText = label;

        const toggleBtn = document.createElement('button');
        applyStyles(toggleBtn, {
            padding: '4px 8px',
            border: 'none',
            borderRadius: '4px',
            cursor: 'pointer',
            backgroundColor: defaultState ? '#7A3C8C' : '#3C3C3C',
            color: '#FFFFFF',
        });
        toggleBtn.innerText = defaultState ? 'ON' : 'OFF';

        let toggled = defaultState;
        toggleBtn.addEventListener('click', () => {
            toggled = !toggled;
            toggleBtn.innerText = toggled ? 'ON' : 'OFF';
            toggleBtn.style.backgroundColor = toggled ? '#7A3C8C' : '#3C3C3C';
            if (typeof onToggle === 'function') {
                onToggle(toggled);
            }
        });

        container.appendChild(text);
        container.appendChild(toggleBtn);
        this.contentElement.appendChild(container);
        return toggleBtn;
    }

    addInput(label, defaultValue, onChange) {
        const container = document.createElement('div');
        applyStyles(container, {
            marginBottom: '6px',
        });

        const labelEl = document.createElement('div');
        labelEl.innerText = label;
        applyStyles(labelEl, {
            marginBottom: '2px',
            fontSize: '13px',
        });

        const inputEl = document.createElement('input');
        inputEl.type = 'text';
        inputEl.value = defaultValue || '';
        applyStyles(inputEl, {
            width: '100%',
            padding: '5px',
            borderRadius: '4px',
            border: '1px solid #555',
            backgroundColor: '#2A2A2A',
            color: '#FFF',
        });

        inputEl.addEventListener('change', () => {
            if (typeof onChange === 'function') {
                onChange(inputEl.value);
            }
        });

        container.appendChild(labelEl);
        container.appendChild(inputEl);
        this.contentElement.appendChild(container);
        return inputEl;
    }

    addKeybind(label, defaultKey, onKeybindChange, callback) {
        const container = document.createElement('div');
        applyStyles(container, {
            marginBottom: '6px',
        });

        const labelEl = document.createElement('div');
        labelEl.innerText = label;
        applyStyles(labelEl, {
            marginBottom: '2px',
            fontSize: '13px',
        });

        const keybindBtn = document.createElement('button');
        keybindBtn.innerText = defaultKey || 'None';
        applyStyles(keybindBtn, {
            width: '100%',
            padding: '5px',
            borderRadius: '4px',
            border: '1px solid #555',
            backgroundColor: '#2A2A2A',
            color: '#FFF',
            cursor: 'pointer',
        });

        let waitingForKey = false;
        keybindBtn.addEventListener('click', () => {
            keybindBtn.innerText = 'Press a key...';
            waitingForKey = true;
        });

        document.addEventListener('keydown', (e) => {
            if (e.key == keybindBtn.innerText || e.key == keybindBtn.innerText.toLocaleLowerCase()) {
                e.stopImmediatePropagation();
                return callback();
            }

            if (!waitingForKey) return;
            e.preventDefault();
            waitingForKey = false;
            keybindBtn.innerText = e.key;
            if (typeof onKeybindChange === 'function') {
                onKeybindChange(e);
            }
        });

        container.appendChild(labelEl);
        container.appendChild(keybindBtn);
        this.contentElement.appendChild(container);
        return keybindBtn;
    }

    addLabel(text) {
        const labelEl = document.createElement('div');
        labelEl.innerText = text;
        applyStyles(labelEl, {
            margin: '4px 0',
            fontSize: '13px',
        });
        this.contentElement.appendChild(labelEl);
        return labelEl;
    }

    addSeparator() {
        const sep = document.createElement('hr');
        applyStyles(sep, {
            border: 'none',
            borderTop: '1px solid #5B5B5B',
            margin: '8px 0',
        });
        this.contentElement.appendChild(sep);
        return sep;
    }
}

/************************************************************
 * Class: UIManager
 * Manages all tabs and the master toggle of the menu
 ************************************************************/
class UIManager {
    constructor(title, toggleKeyCode = 47 /* Delete ~ by default */) {
        this.title = title;
        this.toggleKeyCode = toggleKeyCode; 
        this.isVisible = true;
        this.mainContainer = null; 
    }

    init() {
        const container = document.createElement('div');
        this.mainContainer = container;
        applyStyles(container, {
            position: 'fixed',
            top: 0,
            left: 0,
            width: '100%',
            height: '100%',
            zIndex: 999,
        });

        document.body.appendChild(container);

        document.addEventListener('keydown', (e) => {
            if (e.keyCode === this.toggleKeyCode) {
                e.preventDefault();
                this.isVisible = !this.isVisible;
                container.style.display = this.isVisible ? 'block' : 'none';
            }
        });
    }

    createTab(name) {
        return new UITab(name, this);
    }

    destroy() {
        if (this.mainContainer) {
            document.body.removeChild(this.mainContainer);
        }
    }
}

/************************************************************
 * XHR Interception: Extract coordinates
 ************************************************************/
const originalOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url) {
    const isTargetMethod = method.toUpperCase() === 'POST';
    const targetURLs = [
        'https://maps.googleapis.com/$rpc/google.internal.maps.mapsjs.v1.MapsJsInternalService/GetMetadata',
        'https://maps.googleapis.com/$rpc/google.internal.maps.mapsjs.v1.MapsJsInternalService/SingleImageSearch'
    ];
    if (isTargetMethod && targetURLs.some(prefix => url.startsWith(prefix))) {
        this.addEventListener('load', function() {
            const match = this.responseText.match(/-?\d+\.\d+,-?\d+\.\d+/);
            if (match) {
                const [lat, lng] = match[0].split(',').map(Number);
                globalVariables.lat = lat;
                globalVariables.lng = lng;
            }
        });
    }
    return originalOpen.apply(this, arguments);
};


/************************************************************
 * Map & Location UI Utilities
 ************************************************************/
function addLocLabel(country = 'Unknown', city = 'Unknown') {
    const label = document.createElement('div');
    applyStyles(label, {
        position: 'fixed',
        top: '100px',
        right: '10px',
        zIndex: '99999',
        padding: '10px 15px',
        backgroundColor: 'rgba(0, 0, 0, 0.8)',
        display: 'block',
        color: 'white',
        borderRadius: '10px',
        fontSize: '14px',
        fontFamily: 'Arial, sans-serif',
        boxShadow: '0 2px 10px rgba(0, 0, 0, 0.5)',
    });
    label.id = 'location-label';
    label.innerText = `📍 ${city}, ${country}`;
    document.body.appendChild(label);
    return label;
}

function loadLeaflet() {
    const leafletCSS = document.createElement('link');
    leafletCSS.rel = 'stylesheet';
    leafletCSS.href = 'https://unpkg.com/[email protected]/dist/leaflet.css';
    document.head.appendChild(leafletCSS);

    const leafletJS = document.createElement('script');
    leafletJS.src = 'https://unpkg.com/[email protected]/dist/leaflet.js';
    document.head.appendChild(leafletJS);
}

function createMap(lat = 0, lng = 0) {
    const interval = setInterval(() => {
        if (typeof L !== 'undefined') {
            clearInterval(interval);

            const mapContainer = document.createElement('div');
            applyStyles(mapContainer, {
                position: 'fixed',
                top: '150px',
                right: '10px',
                width: '300px',
                display: 'block',
                height: '300px',
                zIndex: '99999',
                border: '2px solid black',
            });
            mapContainer.id = 'map';
            document.body.appendChild(mapContainer);

            const map = L.map(mapContainer).setView([lat, lng], 2);
            L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                attribution:
                    '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
            }).addTo(map);

            globalVariables.map = map;
            globalVariables.mapContainer = mapContainer;
        }
    }, 100);
}


function displayLocation(lat, lng, city = 'Unknown', country = 'Unknown') {
    if (globalVariables.marker && globalVariables.map) {
        globalVariables.map.removeLayer(globalVariables.marker);
    }
    if (globalVariables.label) {
        globalVariables.label.innerText = `📍 ${city}, ${country}`;
    }
    if (globalVariables.map) {
        globalVariables.map.setView([lat, lng], 2);
        globalVariables.marker = L.marker([lat, lng]).addTo(globalVariables.map);
    }
}

function resolveLatLong(lat, lng) {
    const url = `https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lng}`;
    fetch(url)
        .then(response => response.json())
        .then(data => {
            const country = data.address?.country || 'Unknown';
            const city =
                data.address?.city ||
                data.address?.town ||
                data.address?.village ||
                'Unknown';
            displayLocation(lat, lng, city, country);
        })
        .catch(error => console.error('Error resolving location:', error));
}


/************************************************************
 * Script Unloading Utility
 ************************************************************/
function unloadScript() {
    if (globalVariables.mapContainer) {
        globalVariables.mapContainer.remove();
    }
    if (globalVariables.label) {
        globalVariables.label.remove();
    }
    XMLHttpRequest.prototype.open = originalOpen;
    console.log('Stopped all threads!');
}

/************************************************************
 * Overlay UIs: Welcome Screen 
 ************************************************************/
function showWelcomeScreen() {
    const overlay = document.createElement('div');
    overlay.id = 'welcome-overlay';
    applyStyles(overlay, {
        position: 'fixed',
        top: '0',
        left: '0',
        width: '100%',
        height: '100%',
        display: 'flex',
        flexDirection: 'column',
        justifyContent: 'center',
        alignItems: 'center',
        zIndex: '100000',
    });

    const container = document.createElement('div');
    applyStyles(container, {
        backgroundColor: 'rgba(0, 0, 0, 0.8)',
        padding: '20px',
        borderRadius: '10px',
        textAlign: 'center',
        color: '#fff',
        minWidth: '300px',
        boxShadow: '0 2px 10px rgba(0, 0, 0, 0.5)',
    });

    const title = document.createElement('h1');
    title.innerText = 'BearSolver 🧸';
    container.appendChild(title);

    const message = document.createElement('p');
    message.innerText = 'Welcome, User!';
    container.appendChild(message);

    const message2 = document.createElement('p');
    message2.innerText =
        'Any bans received are not taken accountability for. \n\nCredits:\nMind - Developer';
    message2.style.color = '#a0a0a0';
    container.appendChild(message2);

    const btnContainer = document.createElement('div');
    btnContainer.style.marginTop = '20px';

    const loadButton = document.createElement('button');
    loadButton.innerText = 'Load with cheat';
    applyStyles(loadButton, {
        marginRight: '10px',
        padding: '10px',
        backgroundColor: '#4CAF50',
        color: 'white',
        border: 'none',
        borderRadius: '5px',
        cursor: 'pointer',
    });
    loadButton.addEventListener('click', () => {
        exitButton.remove()
        loadButton.innerText = 'Loading...'

        continueCheat()
    });
    btnContainer.appendChild(loadButton);

    const exitButton = document.createElement('button');
    exitButton.innerText = 'Load without cheat';
    applyStyles(exitButton, {
        padding: '10px',
        backgroundColor: '#D32F2F',
        color: 'white',
        border: 'none',
        borderRadius: '5px',
        cursor: 'pointer',
    });
    exitButton.addEventListener('click', exitCheat);
    btnContainer.appendChild(exitButton);

    container.appendChild(btnContainer);
    overlay.appendChild(container);
    document.body.appendChild(overlay);
}



/************************************************************
 * Cheat Initialization and Exit Functions
 ************************************************************/
function continueCheat() {

    loadLeaflet();
    createMap();
    globalVariables.label = addLocLabel();

    setTimeout(() => {
        const overlay = document.getElementById('welcome-overlay');
        if (overlay) overlay.remove();

        const ui = new UIManager("BearSolver 🧸", 46);
        ui.init();

        const guiTab = ui.createTab("Resolver 📍");

        guiTab.addLabel("Resolver Settings");
        guiTab.addSeparator();

        guiTab.addKeybind("Resolve Location", "1", () => {}, () => {
            resolveLatLong(globalVariables.lat, globalVariables.lng);
        });

        guiTab.addSeparator();

        function ToggleLabel(state) {
            const element = globalVariables.label;
            const display = state ? 'block' : 'none';
            if (element) {
                element.style.display = display;
            }
        }
        const toggle1 = guiTab.addToggle('Show Label', true, ToggleLabel);
        
        function ToggleMap(state) {
            const element = globalVariables.mapContainer;
            const display = state ? 'block' : 'none';
            if (element) {
                element.style.display = display;
            }
        }
        const toggle2 = guiTab.addToggle('Show Map', true, ToggleMap);
        

        guiTab.addKeybind("Toggle Elements", "2", () => {}, () => {
            const label = globalVariables.label;
            const map = globalVariables.mapContainer;

            if (label.style.display == "block") {ToggleLabel(false);} else {ToggleLabel(true);}
            if (map.style.display == "block") {ToggleMap(false);} else {ToggleMap(true);}
        });

        const utilityTab = ui.createTab('Utility ⚙️');

        utilityTab.addLabel("Utility Settings");
        utilityTab.addSeparator();

        utilityTab.addKeybind("Toggle Gui", "Delete", (e) => {
            ui.toggleKeyCode = e.keyCode
        });

        utilityTab.addKeybind("Panic Key", "3", () => {}, () => {
            unloadScript()
            ui.destroy()
        });

        utilityTab.addButton("Unload Script", () => {
            unloadScript()
            ui.destroy()
        });

        const infoTab = ui.createTab('Bearsolver Info 🧸');

        infoTab.addLabel("Current Version: " + version);
        infoTab.addLabel("Enjoy BearSolver 💝!");
        infoTab.addSeparator();

        infoTab.addLabel("Developer: Mind :D");
        infoTab.addLabel("'Helpers': World-Wide-Web <3");

        infoTab.addSeparator();
        infoTab.addLabel("Any bans received are not taken accountability for.");

    }, 1000)
}

function exitCheat() {
    const overlay = document.getElementById('welcome-overlay');
    if (overlay) overlay.remove();

    XMLHttpRequest.prototype.open = originalOpen;
    console.log('Cheat not loaded. Script stopped.');
}


/************************************************************
 * Initialization
 ************************************************************/
(function initialize() {
    showWelcomeScreen();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址