GI AppSample Map Userscript

Created Diff never expires
39 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
105 lines
21 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
90 lines
// ==UserScript==
// ==UserScript==
// @name GI AppSample Map - More Markable Markers
// @name GI AppSample Map - More Markable Markers (v4 fix)
// @namespace http://tampermonkey.net/
// @namespace http://tampermonkey.net/
// @version 1.2
// @version 1.3
// @description Gets the markers_all json file and change user defined markers to be markable.
// @description Modifies markers on the Genshin map to be markable and commentable. Also supports new v4.json files.
// @author 2KRN4U
// @author 2KRN4U + FIX
// @match https://genshin-impact-map.appsample.com/*
// @match https://genshin-impact-map.appsample.com/*
// @icon https://genshin-impact-map.appsample.com/favicon.ico
// @icon https://genshin-impact-map.appsample.com/favicon.ico
// @grant none
// @grant none
// @license MIT
// @downloadURL https://update.greasyfork.org/scripts/520365/GI%20AppSample%20Map%20-%20More%20Markable%20Markers.user.js
// @updateURL https://update.greasyfork.org/scripts/520365/GI%20AppSample%20Map%20-%20More%20Markable%20Markers.meta.js
// ==/UserScript==
// ==/UserScript==


(function () {
(function () {
'use strict';
'use strict';


// List of markers to change
// Comma-separated list of marker IDs to modify – you can change this
const list = "o596, o601, o602, o639, o641, o647, o128"; // EDIT THIS LINE ONLY, seperate by comma. Example "o596, o317";
const list = "o596, o601, o666, o602, o639, o641, o647, o409, o128, o416 ,o415";

const keys = list.split(",").map(key => key.trim());
const targetFilenameStart = "markers_all"; // Filename of the markers file

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


const allowMarkComment = 5; // Value to allow marking and commenting
// Value that enables marking and commenting – usually 5
const allowMarkComment = 5;


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


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


// Override the send method
// Intercept the response and modify it if it's the marker file
XMLHttpRequest.prototype.send = function (body) {
XMLHttpRequest.prototype.send = function (body) {
this.addEventListener('readystatechange', function () {
this.addEventListener('readystatechange', function () {
// Only process requests if the filename matches the target prefix
if (
if (
this.readyState === 4 &&
this.readyState === 4 &&
this.status === 200 &&
this.status === 200 &&
this._filename.startsWith(targetFilenameStart) // Check if filename starts with the target string
this._filename &&
this._filename.startsWith("markers_all") // Also catches markers_all.v4.json
) {
) {
try {
try {
let modifiedResponseText = this.responseText;
let modifiedResponseText = this.responseText;


// Apply replacements for each key in the list
// Modify the values for specified marker IDs
keys.forEach(key => {
keys.forEach(key => {
const searchPattern = new RegExp(`("${key}",\\d+,)(\\d+)(,)`, 'g'); // Search pattern for markers
const searchPattern = new RegExp(`("${key}",\\d+,)(\\d+)(,)`, 'g');
modifiedResponseText = modifiedResponseText.replace(
modifiedResponseText = modifiedResponseText.replace(
searchPattern,
searchPattern,
(_, prefix, lastDigits, suffix) => `${prefix}${allowMarkComment}${suffix}`
(_, prefix, lastDigits, suffix) => `${prefix}${allowMarkComment}${suffix}`
); // Replace to allow marking and commenting
);
});
});


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


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


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


// Wait for the DOM to fully load
// After the page loads, modify button tooltips to include data-testid
window.addEventListener('load', function () {
window.addEventListener('load', function () {
// Function to modify the title
const modifyTitle = (originalTitle, dataTestId) => {
const modifyTitle = (originalTitle, dataTestId) => {
// Trim the first 4 characters of data-testid
const trimmedData = dataTestId ? dataTestId.slice(4) : 'Unknown';
const trimmedData = dataTestId ? dataTestId.slice(4) : 'Unknown';
// Combine the original title with the trimmed data-testid
return `${originalTitle}: ${trimmedData}`;
return `${originalTitle}: ${trimmedData}`;
};
};


// Select all buttons with the class "MuiButtonBase-root"
const buttons = document.querySelectorAll('.MuiButtonBase-root');
const buttons = document.querySelectorAll('.MuiButtonBase-root');

// Iterate over each button
buttons.forEach(button => {
buttons.forEach(button => {
const originalTitle = button.getAttribute('title');
const originalTitle = button.getAttribute('title');
const dataTestId = button.getAttribute('data-testid');
const dataTestId = button.getAttribute('data-testid');


// Only proceed if both title and data-testid exist
if (originalTitle && dataTestId) {
if (originalTitle && dataTestId) {
const newTitle = modifyTitle(originalTitle, dataTestId);
const newTitle = modifyTitle(originalTitle, dataTestId);
button.setAttribute('title', newTitle);
button.setAttribute('title', newTitle);
}
}
});
});
});
});
})();
})();