GI AppSample Map - More Markable Markers

Gets the markers_all json file and change user defined markers to be markable. By default, the only markers changed to markable are Ember Mora Chests.

目前為 2024-12-18 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GI AppSample Map - More Markable Markers
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Gets the markers_all json file and change user defined markers to be markable. By default, the only markers changed to markable are Ember Mora Chests.
// @author       2KRN4U
// @match        https://genshin-impact-map.appsample.com/
// @icon         https://genshin-impact-map.appsample.com/favicon.ico
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    // List of markers to change
    const list = "o596"; // EDIT THIS LINE ONLY, seperate by comma. Example "o596, o317";

    const targetFilenameStart = "markers_all"; // Replace with the start of the filename to match

    const keys = list.split(",").map(key => key.trim()); // Convert list to an array of trimmed keys

    const matchA = 2; // Value to match (1st number)
    const replaceA = 2; // Replacement value (1st number)
    const replaceB = 5; // Replacement value (2nd number)

    // Save references to the original XHR methods
    const originalOpen = XMLHttpRequest.prototype.open;
    const originalSend = XMLHttpRequest.prototype.send;

    // Override the open method
    XMLHttpRequest.prototype.open = function (method, url, async, user, password) {
        this._filename = url.split('/').pop(); // Extract the filename from the URL
        this._url = url; // Store the URL for later use
        originalOpen.apply(this, arguments); // Call the original open method
    };

    // Override the send method
    XMLHttpRequest.prototype.send = function (body) {
        this.addEventListener('readystatechange', function () {
            // Only process requests if the filename matches the target prefix
            if (
                this.readyState === 4 &&
                this.status === 200 &&
                this._filename.startsWith(targetFilenameStart) // Check if filename starts with the target string
            ) {
                try {
                    let modifiedResponseText = this.responseText;

                    // Apply replacements for each key in the list
                    keys.forEach(key => {
                        const searchPattern = new RegExp(`"${key}",${matchA},\\d,`, 'g'); // Match any digit for matchB
                        const replacePattern = `"${key}",${replaceA},${replaceB},`;
                        modifiedResponseText = modifiedResponseText.replace(searchPattern, replacePattern);
                    });

                    // Overwrite the responseText property with the modified content
                    Object.defineProperty(this, 'responseText', {
                        value: modifiedResponseText,
                        configurable: true,
                    });

                    // Optional: Overwrite response (useful if response is accessed differently)
                    Object.defineProperty(this, 'response', {
                        value: modifiedResponseText,
                        configurable: true,
                    });
                } catch (e) {
                    console.error('Error modifying JSON response:', e);
                }
            }
        });

        // Call the original send method
        originalSend.apply(this, arguments);
    };
})();