I don’t have a problem exactly, but I’m curious as to why my code works. Basically, I was making a function that is only mean’t to be run once and if run again it will throw an error. I had trouble with this at first because I made a boolean variable (emDone) to store whether or not the code has been run yet, and an if-else block around all my code inside the function that will check if emDone == null and if true, then the code will run, and if not, it won’t. This didn’t work, because the variable emDone was unreliable (I think due to the scope of the function or something?) and the function was still able to run. I then remember how Eaglercraft, when you view its source has some sort of variable called window.EaglercraftXopts or something like that, (which I believe is like session data?) so I used it for my code and now my code works.
So I just don’t know why this works, how it works, and if there are any drawbacks or cons to using this method. Here is my code for better understanding:
function emojimagizer() {
if(window.emojimagizerDone==true){throw new Error();}
const emojis = [
{ name: "????", url: "grinning-face_1f600.png" },
{ name: "????", url: "grinning-face-with-big-eyes_1f603.png" },
{ name: "????", url: "grinning-face-with-smiling-eyes_1f604.png" },
{ name: "????", url: "beaming-face-with-smiling-eyes_1f601.png" },
{ name: "????", url: "grinning-squinting-face_1f606.png"},
{ name: "????", url: "grinning-face-with-sweat_1f605.png"},
{ name: "????", url: "rolling-on-the-floor-laughing_1f923.png"},
{ name: "????", url: "face-with-tears-of-joy_1f602.png"},
{ name: "????", url: "slightly-smiling-face_1f642.png"},
{ name: "????", url: "upside-down-face_1f643.png"},
{ name: "????", url: "melting-face_1fae0.png"},
{ name: "????", url: "winking-face_1f609.png"},
{ name: "????", url: "smiling-face-with-smiling-eyes_1f60a.png"},
{ name: "????", url: "smiling-face-with-halo_1f607.png"},
{ name: "????", url: "smiling-face-with-hearts_1f970.png"},
{ name: "????", url: "smiling-face-with-heart-eyes_1f60d.png"},
{ name: "????", url: "star-struck_1f929.png"},
{ name: "????", url: "face-blowing-a-kiss_1f618.png"},
{ name: "????", url: "kissing-face_1f617.png"},
{ name: "☺️", url: "smiling-face_263a-fe0f.png"},
{ name: "????", url: "kissing-face-with-closed-eyes_1f61a.png"},
{ name: "????", url: "kissing-face-with-smiling-eyes_1f619.png"},
{ name: "????", url: "smiling-face-with-tear_1f972.png"},
{ name: "????", url: "face-savoring-food_1f60b.png"},
{ name: "????", url: "face-with-tongue_1f61b.png"},
{ name: "????", url: "winking-face-with-tongue_1f61c.png"},
{ name: "????", url: "zany-face_1f92a.png"},
{ name: "????", url: "squinting-face-with-tongue_1f61d.png"},
{ name: "????", url: "money-mouth-face_1f911.png"},
{ name: "????", url: "hugging-face_1f917.png"},
{ name: "????", url: "face-with-hand-over-mouth_1f92d.png"},
{ name: "????", url: "face-with-open-eyes-and-hand-over-mouth_1fae2.png"},
{ name: "????", url: "face-with-peeking-eye_1fae3.png"},
{ name: "????", url: "shushing-face_1f92b.png"},
];
emojis.forEach((emoji) => {
document.body.innerHTML = document.body.innerHTML.replaceAll(emoji.name,'<img src="https://em-content.zobj.net/source/apple/391/' + emoji.url + '" alt="' + emoji.name + '" title="' + emoji.name + '" style="width:1.15em;height:auto" class="emEmoji"/>');
window.emojimagizerDone=true;
});
}
<button onclick="emojimagizer()">click</button>
<p>????????????????????????????????????☺️????????????????????</p>