Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Insert Script into GIF comment
const fs = require("fs");
const scriptChunks = [
`\`;document.body.innerHTML='<div style="text-align: center;"><h1 style="margin-top: 45vh; transform: translate(0,-50%); font-family: monospace;">Click Button to play Snake! (Control with WASD)</h1></div>';`,
`document.querySelector('div').innerHTML += '<button id="play" style="font-size: 32px;">Start Game</button>';`,
`document.querySelector("#play").addEventListener("click",()=>{const e=document.querySelector("h1");document.querySelector("#play").style.display="none",e.textContent="3",e.style.fontSize="3em";const t=document.createElement("style");`,
`t.innerHTML=\`@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }\n @-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }\n @keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg);}}\`;`,
`document.head.appendChild(t),document.body.style.overflow="hidden",setTimeout(()=>{e.textContent="2",e.style.fontSize="4em"},1e3),setTimeout(()=>{e.textContent="1",e.style.fontSize="5em"},2e3);setTimeout(()=>{`,
`document.body.innerHTML=\`<iframe width="100%" height="100%" src="https://www.youtube.com/embed/dQw4w9WgXcQ?controls=0&autoplay=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"></iframe>\`;`,
`document.body.innerHTML+='<div id="lol-as-if-i-would-let-you-turn-it-off-blocker-div" style="position: absolute; top: 0; bottom:0; left: 0; right: 0;"></div>';},3e3);`,
`setTimeout(()=>{const e=document.createElement("div");e.textContent="I was too lazy to write a snake game.";`,
`e.setAttribute("style","position: absolute;top: 45%;color: white;text-align: center;width: 100%;font-size: 3vw;text-shadow: 2px 2px 2px black; animation:spin 6s linear infinite;"),document.body.appendChild(e)},4500)});`,
`alert("Script works! Press the Button to play a game of Snake!");`,
];
const chunks = scriptChunks.map((chunk, i) => {
if (i > 0) {
chunk = "*/" + chunk;
}
chunk += "/*";
return chunk;
});
const scriptContent = [];
for (let i = 0; i < chunks.length; i++) {
const chunk = chunks[i];
scriptContent.push(chunk.length);
for (let j = 0; j < chunk.length; j++) {
scriptContent.push(chunk.charCodeAt(j));
}
}
fs.writeFileSync("out.js", Buffer.from(scriptContent));
fs.readFile("image.gif", function (err, buffer) {
const data = [...buffer];
for (let i = 0; i < data.length; i++) {
if (data[i] === 33 && data[i + 1] === 254) {
// found comment section
const currentCommentLength = data[i + 2];
data.splice.apply(data, [
i + 2,
currentCommentLength + 1, // remove current comment
...scriptContent, // add script as new comment
]);
fs.writeFileSync("out.gif", Buffer.from(data));
break;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.