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 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name GI AppSample Map - More Markable Markers
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @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.
  6. // @author 2KRN4U
  7. // @match https://genshin-impact-map.appsample.com/
  8. // @icon https://genshin-impact-map.appsample.com/favicon.ico
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. // List of markers to change
  17. const list = "o596"; // EDIT THIS LINE ONLY, seperate by comma. Example "o596, o317";
  18.  
  19. const targetFilenameStart = "markers_all"; // Replace with the start of the filename to match
  20.  
  21. const keys = list.split(",").map(key => key.trim()); // Convert list to an array of trimmed keys
  22.  
  23. const matchA = 2; // Value to match (1st number)
  24. const replaceA = 2; // Replacement value (1st number)
  25. const replaceB = 5; // Replacement value (2nd number)
  26.  
  27. // Save references to the original XHR methods
  28. const originalOpen = XMLHttpRequest.prototype.open;
  29. const originalSend = XMLHttpRequest.prototype.send;
  30.  
  31. // Override the open method
  32. XMLHttpRequest.prototype.open = function (method, url, async, user, password) {
  33. this._filename = url.split('/').pop(); // Extract the filename from the URL
  34. this._url = url; // Store the URL for later use
  35. originalOpen.apply(this, arguments); // Call the original open method
  36. };
  37.  
  38. // Override the send method
  39. XMLHttpRequest.prototype.send = function (body) {
  40. this.addEventListener('readystatechange', function () {
  41. // Only process requests if the filename matches the target prefix
  42. if (
  43. this.readyState === 4 &&
  44. this.status === 200 &&
  45. this._filename.startsWith(targetFilenameStart) // Check if filename starts with the target string
  46. ) {
  47. try {
  48. let modifiedResponseText = this.responseText;
  49.  
  50. // Apply replacements for each key in the list
  51. keys.forEach(key => {
  52. const searchPattern = new RegExp(`"${key}",${matchA},\\d,`, 'g'); // Match any digit for matchB
  53. const replacePattern = `"${key}",${replaceA},${replaceB},`;
  54. modifiedResponseText = modifiedResponseText.replace(searchPattern, replacePattern);
  55. });
  56.  
  57. // Overwrite the responseText property with the modified content
  58. Object.defineProperty(this, 'responseText', {
  59. value: modifiedResponseText,
  60. configurable: true,
  61. });
  62.  
  63. // Optional: Overwrite response (useful if response is accessed differently)
  64. Object.defineProperty(this, 'response', {
  65. value: modifiedResponseText,
  66. configurable: true,
  67. });
  68. } catch (e) {
  69. console.error('Error modifying JSON response:', e);
  70. }
  71. }
  72. });
  73.  
  74. // Call the original send method
  75. originalSend.apply(this, arguments);
  76. };
  77. })();