From 661c3d9b928219e7e3f76fddd623f64bfdbe822d Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Sun, 8 Sep 2024 15:23:21 +0800 Subject: [PATCH] Prevent crashes from incorrect metafunction use --- postinit.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/postinit.js b/postinit.js index 3e4c7b1..15dcefd 100644 --- a/postinit.js +++ b/postinit.js @@ -27,7 +27,7 @@ } } ModAPI.meta.title = function (title) { - if (document.currentScript.getAttribute("data-isMod") !== "true") { + if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") { return console.log("[ModAPIMeta] Cannot set meta for non-mod script."); } if (!document.currentScript.hasAttribute("data-hash")) { @@ -36,7 +36,7 @@ ModAPI.meta._titleMap[document.currentScript.getAttribute("data-hash")] = limitSize(title, 14); } ModAPI.meta.icon = function (iconSrc) { - if (document.currentScript.getAttribute("data-isMod") !== "true") { + if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") { return console.log("[ModAPIMeta] Cannot set meta for non-mod script."); } if (!document.currentScript.hasAttribute("data-hash")) { @@ -45,7 +45,7 @@ ModAPI.meta._iconMap[document.currentScript.getAttribute("data-hash")] = iconSrc; } ModAPI.meta.credits = function (cd) { - if (document.currentScript.getAttribute("data-isMod") !== "true") { + if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") { return console.log("[ModAPIMeta] Cannot set meta for non-mod script."); } if (!document.currentScript.hasAttribute("data-hash")) { @@ -54,7 +54,7 @@ ModAPI.meta._developerMap[document.currentScript.getAttribute("data-hash")] = limitSize(cd, 16); } ModAPI.meta.description = function (desc) { - if (document.currentScript.getAttribute("data-isMod") !== "true") { + if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") { return console.log("[ModAPIMeta] Cannot set meta for non-mod script."); } if (!document.currentScript.hasAttribute("data-hash")) {