Unofficial Coverge Resolver

get unofficial coverage on map-making page

当前为 2024-07-09 提交的版本,查看 最新版本

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 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);
})();