Unofficial Coverge Resolver

get unofficial coverage on map-making page

目前為 2024-07-09 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Unofficial Coverge Resolver
// @namespace    https://greasyfork.org/users/1179204
// @version      1.0.1
// @description  get unofficial coverage on map-making page
// @author       KaKa
// @match        *://map-making.app/maps/
// @require      https://cdn.jsdelivr.net/npm/sweetalert2@11
// @license      MIT
// @grant        unsafeWindow
// @icon         https://www.google.com/s2/favicons?domain=geoguessr.com
// ==/UserScript==

(function() {
    let preference;

    function showAlert(preference) {
        Swal.fire({
            title: 'Preference',
            text: `The default coverage has been set to "${preference}"`,
            icon: 'info',
            timer: 2000,
            showConfirmButton: false,
        });
    }
    const THE_WINDOW = unsafeWindow || window;

    THE_WINDOW.fetch = function(originalFetch) {
        return function (...args) {
            const url = args[0].toString();
            if (url.includes('SingleImageSearch')||url.includes('GetMetadata')) {
                if (args[1] && args[1].method === 'POST') {
                    if (preference=='Unofficial'){
                        var requestData = JSON.parse(args[1].body);
                        if (url.includes('SingleImageSearch')) requestData[2][10][0][0][0]=3
                        if (url.includes('GetMetadata')) requestData[2][0][0][0]=10
                        args[1].body=JSON.stringify(requestData)
                    }
                }
                try {
                    const response = originalFetch.apply(THE_WINDOW, args);
                    return response
                } catch (error) {
                    console.error('Fetch error:', error);
                    throw error;
                }
            }

            return originalFetch.apply(THE_WINDOW, args);
        };
    }(THE_WINDOW.fetch);

    let onKeyDown = (e) => {
        if (e.key === 'q' || e.key === 'Q') {
            e.stopImmediatePropagation();
            if(preference!='Unofficial')preference='Unofficial'
            else preference='Official'
            showAlert(preference)
        };
    }
    document.addEventListener("keydown", onKeyDown);
})();