Skip to content

Instantly share code, notes, and snippets.

@dwisiswant0
Last active October 30, 2024 00:32
Show Gist options
  • Save dwisiswant0/b2d3f768cebe30d279e641ab9ad1042b to your computer and use it in GitHub Desktop.
Save dwisiswant0/b2d3f768cebe30d279e641ab9ad1042b to your computer and use it in GitHub Desktop.
Auto view & like Instagram stories
/**
* Tutor running script:
* 1. Buka beranda IG & login
* 2. Buka console browser
* 3. Paste script ini
* 4. Enter
* 5. Udah :P
*/
var utils = {
isValidURL: (u) => {
if (u.host !== "www.instagram.com") {
alert("Buka www.instagram.com lah, pekok.");
return !1;
}
if (!u.pathname.startsWith("/stories/")) {
alert("Jangan diinterrupt, blok.");
return !1;
}
return !0;
},
emulateClick: (el) => {
const clickEvent = new MouseEvent("click", {
view: window,
bubbles: true,
cancelable: true,
});
el.dispatchEvent(clickEvent);
},
emulateNext: () => {
const arrowRightEvent = new KeyboardEvent("keydown", {
key: "ArrowRight",
keyCode: 39,
code: "ArrowRight",
which: 39,
bubbles: true,
cancelable: true,
});
document.dispatchEvent(arrowRightEvent);
},
getKuki: (k) => {
const cookies = document.cookie.split(";");
for (const cookie of cookies) {
const [key, value] = cookie.trim().split("=");
if (key === k) return decodeURIComponent(value);
}
return null;
},
sleep: (ms) => new Promise(r => setTimeout(r, ms)),
fatalError: (e) => {
console.error("Failed to like the story.", e);
alert("Waduh! Refresh gan.");
window.location.replace("/");
}
}
var aing = {
token: utils.getKuki("csrftoken"),
kirimLike: async (mediaId) => {
const likeStoryEndpoint = "/api/v1/story_interactions/send_story_like";
const response = await fetch(likeStoryEndpoint, {
method: "POST",
mode: "cors",
credentials: "include",
headers: {
"content-type": "application/x-www-form-urlencoded",
"viewport-width": "852",
"x-csrftoken": aing.token,
"x-ig-app-id": "936619743392459",
"x-requested-with": "XMLHttpRequest"
},
body: `media_id=${mediaId}`,
});
if (response.ok) {
try {
const data = await response.json();
if (data.status !== "ok") {
console.error("Failed to like the story.", data, window.location.href);
} else {
console.log("Ok, ngab!", window.location.href);
}
utils.emulateNext();
await utils.sleep(500);
aing.hajar();
} catch(e) {
utils.fatalError(e);
}
} else if (response.status == 400) {
utils.emulateNext();
} else {
utils.fatalError(e);
}
},
hajar: () => {
const url = new URL(window.location.href);
if (!utils.isValidURL(url)) return;
const id = url.pathname.split("/")[3];
aing.kirimLike(id);
},
init: async () => {
const el = document.querySelector('button[tabindex="0"]');
utils.emulateClick(el);
await utils.sleep(3000);
aing.hajar();
}
}
await aing.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment