Skip to content

Instantly share code, notes, and snippets.

@marvinlehmann
Last active August 11, 2021 21:22
Show Gist options
  • Select an option

  • Save marvinlehmann/ac16fea04d4363738e15151b492b1673 to your computer and use it in GitHub Desktop.

Select an option

Save marvinlehmann/ac16fea04d4363738e15151b492b1673 to your computer and use it in GitHub Desktop.
teyvat-marker-quick-hide.user.js
// ==UserScript==
// @name Teyvat Marker Quick Hide
// @namespace https://github.com/marvinlehmann
// @version 0.1
// @description Hide markers using right click
// @author Marvin Lehmann
// @match https://webstatic-sea.mihoyo.com/app/ys-map-sea/index.html*
// @icon https://www.google.com/s2/favicons?domain=mihoyo.com
// @grant none
// @run-at document-start
// ==/UserScript==
(function () {
'use strict';
let hooked = false;
window._L = 0;
Object.defineProperty(window, "L", {
get: function() { return window._L},
set: function(v) {
window._L = v;
if (!hooked) {
hooky();
}
}
});
function hooky() {
L.Map.addInitHook(function () {
setInterval(() => {
this.eachLayer(layer => {
if (layer instanceof L.Marker) {
if (!layer.listens("contextmenu")) {
layer.on("contextmenu", (e) => {
const pointId = layer.pointId;
const mapId = document.location.hash.match(/\#\/map\/(\d)/)[1];
if (layer.options.opacity < 1.0) {
fetch("https://api-os-takumi.mihoyo.com/common/map_user/ys_obc/v1/map/point/new_del_mark_map_point", {
"credentials": "include",
"headers": {
"Accept": "application/json, text/plain, */*",
"Accept-Language": "de,en-US;q=0.7,en;q=0.3",
"Content-Type": "application/json;charset=utf-8",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-site",
},
"referrer": "https://webstatic-sea.mihoyo.com/",
"body": JSON.stringify({"map_id":mapId,"point_id":pointId,"app_sn":"ys_obc","lang":"en-us"}),
"method": "POST",
"mode": "cors"
}).then(r => r.json()).then(j => {
if (j.message === "OK") {
layer.setOpacity(1.0);
}
});
} else {
fetch("https://api-os-takumi.mihoyo.com/common/map_user/ys_obc/v1/map/point/add_mark_map_point", {
"credentials": "include",
"headers": {
"Accept": "application/json, text/plain, */*",
"Accept-Language": "de,en-US;q=0.7,en;q=0.3",
"Content-Type": "application/json;charset=utf-8",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-site",
},
"referrer": "https://webstatic-sea.mihoyo.com/",
"body": JSON.stringify({"map_id":mapId,"point_id":pointId,"app_sn":"ys_obc","lang":"en-us"}),
"method": "POST",
"mode": "cors"
}).then(r => r.json()).then(j => {
if (j.message === "OK") {
layer.setOpacity(0.3);
}
});
}
});
}
}
});
}, 3000);
});
}
})();
@marvinlehmann
Copy link
Author

Quickly thrown together... Nobody needs error handling 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment