Skip to content

Instantly share code, notes, and snippets.

@motebaya
Created November 4, 2025 17:10
Show Gist options
  • Select an option

  • Save motebaya/df8ba9d2427c458f3a6269f1a98916c8 to your computer and use it in GitHub Desktop.

Select an option

Save motebaya/df8ba9d2427c458f3a6269f1a98916c8 to your computer and use it in GitHub Desktop.
fu*ck youuu puppeterrrrrr
// credit: github.com/motebaya
// tiktok auto collect media id
(async () => {
const SELECTOR =
'[class*="DivVideoFeedV2"] > [class*="DivItemContainerV2"] div[class*="DivWrapper"] > a:not([data-grabbed])';
let unstop = true;
var pt = [];
var pv = [];
var total = 0;
var retry = 0;
while (unstop) {
var urls = document.querySelectorAll(SELECTOR);
if (urls.length !== 0) {
for (var e of urls) {
total++;
var href = e.getAttribute("href");
var vid = href.split("/").slice(-1)[0];
e.dataset.grabbed = "1";
if (href.includes("/video/")) {
pv.push(vid);
console.log(`[${total}/video] ${vid}`);
} else {
pt.push(vid);
console.log(`[${total}/photo] ${vid}`);
}
}
/**
* scroll top little then scroll down and remove
*/
window.scrollBy(0, -500);
window.scrollBy(0, document.body.scrollHeight);
urls.forEach((el) => {
el?.parentElement?.parentElement?.parentElement?.parentElement?.remove();
});
} else {
if (retry < 15) {
console.log(`[waiting] element still not ready!!`);
await new Promise((resolve) => setTimeout(resolve, 3000));
/**
* scroll again after waiting
*/
window.scrollBy(0, document.body.scrollHeight);
await new Promise((resolve) => setTimeout(resolve, 3000));
retry++;
continue;
} else {
console.log(`[done] EXCEEDED RETRYING!!!`);
unstop = false;
}
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
console.log(`[video] ${pv.length}`);
console.log(`[photo] ${pt.length}`);
const raw = JSON.stringify(
{
videos: pv,
photos: pt,
},
null,
2
);
console.log(raw.length);
const blob = new Blob([raw], { type: "text/plain" });
const url = URL.createObjectURL(blob);
console.log(`✅ ${url}`);
window.open(url, "_blank");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment