Skip to content
ZNZN Hub

$ run sticker-zip-downloader

working on it…

✓ all done

  • GIF, WebP, PNG, APNG and SVG
  • Prefers original download links
  • Removes duplicate stickers
  • Skips small icons automatically
Install

Up and running in a minute

  1. 01

    Open the sticker page in your browser.

  2. 02

    Open the console: F12 or Ctrl+Shift+J on Windows, Cmd+Option+J on Mac. Chrome may ask you to type allow pasting first.

  3. 03

    Copy the script below, paste it into the console and press Enter. Type a number or all, and the ZIP downloads when it is done.

Source

Read it, copy it, run it

The full script is below. Copy it in one click or download the file. Nothing is minified or hidden.

sticker-zip-downloader.jsJavaScript · 522 linesDownload
(async () => {
  const OPTIONS = {
    maxStickers: 100,
    askForCount: true,
    autoLoadMore: true,
    maxLoadRounds: 60,
    idleRoundsToStop: 3,
    waitAfterLoadMs: 1500,
    source: "auto",
    includeJpg: false,
    minImageSize: 48,
    urlMustInclude: "",
    concurrency: 4,
    zipName: `${location.hostname || "page"}-stickers.zip`,
  };

  const LOAD_MORE_TEXT = /^\s*(load|show|view|see)\s+more\b|^\s*more\s*$|aur\s+dekh|mazeed|next\s+page/i;
  const CLICKABLE_SELECTOR = "button, [role='button'], a, input[type='button'], input[type='submit']";
  const LAZY_ATTRS = ["src", "data-src", "data-original", "data-lazy-src", "data-url", "poster"];
  const MEDIA_TAGS = new Set(["img", "source", "video"]);
  const EXTENSIONS = OPTIONS.includeJpg ? "gif|webp|png|apng|svg|jpe?g" : "gif|webp|png|apng|svg";
  const STICKER_URL = new RegExp(`\\.(?:${EXTENSIONS})(?:$|[?#])|[?&](?:format|fm|ext|type)=(?:${EXTENSIONS})\\b`, "i");
  const STICKER_DATA_URL = new RegExp(`^data:image/(?:${EXTENSIONS}|svg\\+xml)`, "i");

  const log = (...args) => {
    console.log("%c[STICKER-ZIP]", "color:#a3f;font-weight:bold", ...args);
  };

  const originals = new Map();
  const images = new Map();

  const looksLikeSticker = (url) => {
    return STICKER_DATA_URL.test(url) || STICKER_URL.test(url);
  };

  const passesFilter = (url) => {
    return !OPTIONS.urlMustInclude || url.toLowerCase().includes(OPTIONS.urlMustInclude.toLowerCase());
  };

  const toAbsoluteUrl = (raw) => {
    if (!raw || typeof raw !== "string") {
      return null;
    }
    const value = raw.trim();
    if (!value || value.startsWith("blob:") || value.startsWith("javascript:") || value.startsWith("#")) {
      return null;
    }
    if (value.startsWith("data:")) {
      return value;
    }
    try {
      return new URL(value, location.href).href;
    } catch {
      return null;
    }
  };

  const addImage = (raw) => {
    const url = toAbsoluteUrl(raw);
    if (url && looksLikeSticker(url) && passesFilter(url) && !images.has(url)) {
      images.set(url, null);
    }
  };

  const addOriginal = (raw, suggestedName) => {
    const url = toAbsoluteUrl(raw);
    if (url && passesFilter(url) && !originals.has(url)) {
      originals.set(url, suggestedName || null);
    }
  };

  const addSrcset = (srcset) => {
    if (!srcset) {
      return;
    }
    srcset.split(/,\s+(?=\S)/).forEach((part) => {
      addImage(part.trim().split(/\s+/)[0]);
    });
  };

  const addCssUrls = (cssValue) => {
    if (!cssValue || cssValue === "none") {
      return;
    }
    for (const match of cssValue.matchAll(/url\(\s*(['"]?)(.*?)\1\s*\)/g)) {
      addImage(match[2]);
    }
  };

  const collectElements = (root, bucket) => {
    root.querySelectorAll("*").forEach((el) => {
      bucket.push(el);
      if (el.shadowRoot) {
        collectElements(el.shadowRoot, bucket);
      }
    });
    return bucket;
  };

  const isBigEnough = (el) => {
    const rect = el.getBoundingClientRect();
    const natural = Math.max(el.naturalWidth || 0, el.naturalHeight || 0);
    const rendered = Math.max(rect.width, rect.height);
    const unknown = !natural && !rendered;
    return unknown || natural >= OPTIONS.minImageSize || rendered >= OPTIONS.minImageSize;
  };

  const scanMediaElement = (el) => {
    if (el.tagName.toLowerCase() === "img" && !isBigEnough(el)) {
      return;
    }
    if (el.currentSrc) {
      addImage(el.currentSrc);
    }
    LAZY_ATTRS.forEach((attr) => {
      addImage(el.getAttribute(attr));
    });
    addSrcset(el.getAttribute("srcset"));
    addSrcset(el.getAttribute("data-srcset"));
  };

  const scanLink = (el) => {
    const href = el.getAttribute("href");
    if (el.hasAttribute("download")) {
      addOriginal(href, el.getAttribute("download"));
    } else if (href && looksLikeSticker(toAbsoluteUrl(href) || "")) {
      addOriginal(href, null);
    }
  };

  const scanBackground = (el) => {
    const inline = el.getAttribute("style");
    const computed = getComputedStyle(el).backgroundImage;
    const hasImage = (inline && inline.includes("url(")) || (computed && computed !== "none");
    if (hasImage && isBigEnough(el)) {
      addCssUrls(inline);
      addCssUrls(computed);
    }
  };

  const scanElement = (el) => {
    const tag = el.tagName.toLowerCase();
    if (MEDIA_TAGS.has(tag)) {
      scanMediaElement(el);
    } else if (tag === "a") {
      scanLink(el);
    } else if (tag === "image") {
      addImage(el.getAttribute("href") || el.getAttribute("xlink:href"));
    }
    scanBackground(el);
  };

  const scanPage = () => {
    collectElements(document, []).forEach(scanElement);
  };

  const pickCandidates = () => {
    if (OPTIONS.source === "links") {
      return [...originals];
    }
    if (OPTIONS.source === "images") {
      return [...images];
    }
    if (OPTIONS.source === "both") {
      return [...originals, ...images];
    }
    return originals.size ? [...originals] : [...images];
  };

  const sleep = (ms) => {
    return new Promise((resolve) => setTimeout(resolve, ms));
  };

  const isVisible = (el) => {
    const rect = el.getBoundingClientRect();
    return rect.width > 0 && rect.height > 0 && !el.disabled;
  };

  const staysOnPage = (el) => {
    if (el.tagName.toLowerCase() !== "a") {
      return true;
    }
    const href = (el.getAttribute("href") || "").trim();
    return !href || href.startsWith("#") || href.startsWith("javascript:");
  };

  const findLoadMoreButton = () => {
    return [...document.querySelectorAll(CLICKABLE_SELECTOR)].find((el) => {
      const label = el.innerText || el.value || el.getAttribute("aria-label") || "";
      return LOAD_MORE_TEXT.test(label) && isVisible(el) && staysOnPage(el);
    });
  };

  const scrollEverythingDown = () => {
    window.scrollTo(0, document.documentElement.scrollHeight);
    document.querySelectorAll("*").forEach((el) => {
      const style = getComputedStyle(el);
      const scrollable = /(auto|scroll)/.test(style.overflowY) && el.scrollHeight > el.clientHeight + 50;
      if (scrollable) {
        el.scrollTop = el.scrollHeight;
      }
    });
  };

  const pageSnapshot = () => {
    return `${originals.size}|${images.size}|${document.documentElement.scrollHeight}|${document.images.length}`;
  };

  const autoLoad = async () => {
    const enough = OPTIONS.maxStickers + 10;
    let idleRounds = 0;

    for (let round = 1; round <= OPTIONS.maxLoadRounds; round++) {
      const before = pageSnapshot();
      const button = findLoadMoreButton();
      if (button) {
        button.scrollIntoView({ block: "center" });
        button.click();
      }
      scrollEverythingDown();
      await sleep(OPTIONS.waitAfterLoadMs);
      scanPage();

      const found = pickCandidates().length;
      log(`Load more round ${round}: ${found} sticker ab tak${button ? " (button click kiya)" : ""}`);
      if (found >= enough) {
        break;
      }
      idleRounds = pageSnapshot() === before ? idleRounds + 1 : 0;
      if (idleRounds >= OPTIONS.idleRoundsToStop) {
        log("Page par mazeed content nahi aa raha, load more band.");
        break;
      }
    }
    window.scrollTo(0, 0);
  };

  const startsWith = (bytes, signature, at = 0) => {
    return signature.every((value, i) => bytes[at + i] === value);
  };

  const looksLikeSvg = (bytes) => {
    const head = new TextDecoder().decode(bytes.subarray(0, 512)).trimStart().toLowerCase();
    return (head.startsWith("<svg") || head.startsWith("<?xml")) && head.includes("<svg");
  };

  const detectFormat = (bytes) => {
    if (startsWith(bytes, [0x47, 0x49, 0x46, 0x38])) {
      return "gif";
    }
    if (startsWith(bytes, [0x52, 0x49, 0x46, 0x46]) && startsWith(bytes, [0x57, 0x45, 0x42, 0x50], 8)) {
      return "webp";
    }
    if (startsWith(bytes, [0x89, 0x50, 0x4e, 0x47])) {
      return "png";
    }
    if (OPTIONS.includeJpg && startsWith(bytes, [0xff, 0xd8, 0xff])) {
      return "jpg";
    }
    return looksLikeSvg(bytes) ? "svg" : null;
  };

  const fetchBytes = async (url) => {
    const sameOrigin = url.startsWith("data:") || new URL(url).origin === location.origin;
    const response = await fetch(url, {
      credentials: sameOrigin ? "include" : "omit",
      mode: "cors",
      cache: "force-cache",
    });
    if (!response.ok) {
      throw new Error(`HTTP ${response.status}`);
    }
    return new Uint8Array(await response.arrayBuffer());
  };

  const usedNames = new Map();
  let inlineCount = 0;

  const safeDecode = (text) => {
    try {
      return decodeURIComponent(text);
    } catch {
      return text;
    }
  };

  const baseNameFor = (url, suggestedName) => {
    if (suggestedName) {
      return suggestedName;
    }
    if (url.startsWith("data:")) {
      inlineCount += 1;
      return `sticker-${inlineCount}`;
    }
    return safeDecode(new URL(url).pathname.split("/").filter(Boolean).pop() || "sticker");
  };

  const fileNameFor = (url, suggestedName, ext) => {
    const withoutExt = baseNameFor(url, suggestedName).replace(/\.[a-z0-9]{2,5}$/i, "");
    const safe = withoutExt.replace(/[\\/:*?"<>|\x00-\x1f]/g, "_").slice(0, 120) || "sticker";
    const key = `${safe.toLowerCase()}.${ext}`;
    const seen = usedNames.get(key) || 0;
    usedNames.set(key, seen + 1);
    return seen ? `${safe}-${seen}.${ext}` : `${safe}.${ext}`;
  };

  const buildCrcTable = () => {
    const table = new Uint32Array(256);
    for (let i = 0; i < 256; i++) {
      let c = i;
      for (let k = 0; k < 8; k++) {
        c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
      }
      table[i] = c >>> 0;
    }
    return table;
  };

  const CRC_TABLE = buildCrcTable();

  const crc32 = (bytes) => {
    let c = 0xffffffff;
    for (let i = 0; i < bytes.length; i++) {
      c = CRC_TABLE[(c ^ bytes[i]) & 0xff] ^ (c >>> 8);
    }
    return (c ^ 0xffffffff) >>> 0;
  };

  const downloadAll = async (candidates) => {
    const files = [];
    const failed = [];
    const seenContent = new Set();
    const queue = [...candidates];
    let done = 0;
    let duplicates = 0;

    const handleOne = async ([url, suggestedName]) => {
      try {
        const bytes = await fetchBytes(url);
        const ext = detectFormat(bytes);
        const crc = ext ? crc32(bytes) : 0;
        const contentKey = `${crc}:${bytes.length}`;
        if (!ext) {
          failed.push({ url, reason: "sticker format (gif/webp/png/svg) nahi hai" });
        } else if (seenContent.has(contentKey)) {
          duplicates += 1;
        } else if (files.length < OPTIONS.maxStickers) {
          seenContent.add(contentKey);
          files.push({ name: fileNameFor(url, suggestedName, ext), data: bytes, crc });
        }
      } catch (err) {
        failed.push({ url, reason: err.message || String(err) });
      }
      done += 1;
      if (done % 5 === 0 || done === candidates.length) {
        log(`${done}/${candidates.length} check ho gaye`);
      }
    };

    const worker = async () => {
      while (queue.length && files.length < OPTIONS.maxStickers) {
        await handleOne(queue.shift());
      }
    };

    await Promise.all(Array.from({ length: OPTIONS.concurrency }, worker));
    return { files, failed, duplicates };
  };

  const dosDateTime = (date) => {
    const time = (date.getHours() << 11) | (date.getMinutes() << 5) | Math.floor(date.getSeconds() / 2);
    const day = ((date.getFullYear() - 1980) << 9) | ((date.getMonth() + 1) << 5) | date.getDate();
    return { time, day };
  };

  const ZIP_VERSION = 20;
  const UTF8_FLAG = 0x0800;
  const STORE_METHOD = 0;

  const localHeader = (entry, stamp) => {
    const view = new DataView(new ArrayBuffer(30));
    view.setUint32(0, 0x04034b50, true);
    view.setUint16(4, ZIP_VERSION, true);
    view.setUint16(6, UTF8_FLAG, true);
    view.setUint16(8, STORE_METHOD, true);
    view.setUint16(10, stamp.time, true);
    view.setUint16(12, stamp.day, true);
    view.setUint32(14, entry.crc, true);
    view.setUint32(18, entry.data.length, true);
    view.setUint32(22, entry.data.length, true);
    view.setUint16(26, entry.nameBytes.length, true);
    return new Uint8Array(view.buffer);
  };

  const centralHeader = (entry, stamp) => {
    const view = new DataView(new ArrayBuffer(46));
    view.setUint32(0, 0x02014b50, true);
    view.setUint16(4, ZIP_VERSION, true);
    view.setUint16(6, ZIP_VERSION, true);
    view.setUint16(8, UTF8_FLAG, true);
    view.setUint16(10, STORE_METHOD, true);
    view.setUint16(12, stamp.time, true);
    view.setUint16(14, stamp.day, true);
    view.setUint32(16, entry.crc, true);
    view.setUint32(20, entry.data.length, true);
    view.setUint32(24, entry.data.length, true);
    view.setUint16(28, entry.nameBytes.length, true);
    view.setUint32(42, entry.offset, true);
    return new Uint8Array(view.buffer);
  };

  const endRecord = (count, centralSize, centralOffset) => {
    const view = new DataView(new ArrayBuffer(22));
    view.setUint32(0, 0x06054b50, true);
    view.setUint16(8, count, true);
    view.setUint16(10, count, true);
    view.setUint32(12, centralSize, true);
    view.setUint32(16, centralOffset, true);
    return new Uint8Array(view.buffer);
  };

  const buildZip = (files) => {
    const stamp = dosDateTime(new Date());
    const encoder = new TextEncoder();
    const localParts = [];
    const centralParts = [];
    let offset = 0;

    for (const file of files) {
      const entry = { data: file.data, nameBytes: encoder.encode(file.name), crc: file.crc, offset };
      localParts.push(localHeader(entry, stamp), entry.nameBytes, entry.data);
      centralParts.push(centralHeader(entry, stamp), entry.nameBytes);
      offset += 30 + entry.nameBytes.length + entry.data.length;
    }

    const centralSize = centralParts.reduce((sum, part) => sum + part.length, 0);
    return [...localParts, ...centralParts, endRecord(files.length, centralSize, offset)];
  };

  const saveBlob = (blob, fileName) => {
    const link = document.createElement("a");
    link.href = URL.createObjectURL(blob);
    link.download = fileName;
    document.body.appendChild(link);
    link.click();
    link.remove();
    setTimeout(() => URL.revokeObjectURL(link.href), 60_000);
  };

  const countByFormat = (files) => {
    const counts = {};
    files.forEach((file) => {
      const ext = file.name.split(".").pop();
      counts[ext] = (counts[ext] || 0) + 1;
    });
    return Object.entries(counts).map(([ext, n]) => `${n} ${ext}`).join(", ");
  };

  const askCount = (thing, fallback) => {
    const answer = window.prompt(`Kitne ${thing} chahiye? Number likho, ya "all" likho sab ke liye.`, String(fallback));
    if (answer === null) {
      return null;
    }
    const text = answer.trim().toLowerCase();
    if (["all", "sab", "sare", "saare", "0"].includes(text)) {
      return Infinity;
    }
    const count = Number.parseInt(text, 10);
    return Number.isFinite(count) && count > 0 ? count : NaN;
  };

  const requested = OPTIONS.askForCount ? askCount("stickers", OPTIONS.maxStickers) : OPTIONS.maxStickers;
  if (requested === null) {
    log("Cancel kar diya.");
    return;
  }
  if (Number.isNaN(requested)) {
    log("Sahi number nahi likha, script dobara chalao.");
    return;
  }
  OPTIONS.maxStickers = requested;
  const limitLabel = requested === Infinity ? "saare" : `max ${requested}`;

  scanPage();
  if (OPTIONS.autoLoadMore) {
    log(`Page ko load more kar raha hoon (${limitLabel} stickers)...`);
    await autoLoad();
  }

  const candidates = pickCandidates();
  if (!candidates.length) {
    log("Is page par koi sticker nahi mila. OPTIONS.source = \"images\" ya minImageSize kam kar ke dobara chalao.");
    return;
  }

  const fromLinks = OPTIONS.source === "links" || (OPTIONS.source === "auto" && originals.size > 0);
  log(`${candidates.length} sticker mile (${fromLinks ? "download links se, asli files" : "page ki images se"}). Download shuru...`);

  const { files, failed, duplicates } = await downloadAll(candidates);
  if (!files.length) {
    log("Koi sticker download nahi ho saka.");
    console.table(failed);
    return;
  }

  const totalBytes = files.reduce((sum, file) => sum + file.data.length, 0);
  if (totalBytes > 0xfffffff0 || files.length > 0xffff) {
    log("Data 4 GB ya 65535 files se zyada hai, maxStickers kam karo.");
    return;
  }

  saveBlob(new Blob(buildZip(files), { type: "application/zip" }), OPTIONS.zipName);
  log(`Ho gaya: ${files.length} stickers (${countByFormat(files)}), ${(totalBytes / 1024 / 1024).toFixed(2)} MB -> ${OPTIONS.zipName}`);

  if (duplicates) {
    log(`${duplicates} duplicate sticker chhor diye (same file do baar thi).`);
  }
  if (failed.length) {
    log(`${failed.length} file(s) nahi aa sakin (aksar doosre domain ka CORS block):`);
    console.table(failed);
  }
})();
Overview

What Sticker ZIP Downloader does

A console snippet for sticker sites. It prefers the real files behind download links, falls back to the images shown on the page, skips tiny icons, detects each file's true format from its bytes (GIF, animated WebP, PNG, APNG, SVG and optionally JPG) and drops exact duplicates before zipping. Like the GIF downloader it asks how many you want, keeps clicking Load more and scrolling until it has them, and builds the ZIP in the browser. The OPTIONS block lets you pick the source (links, images, both or auto), include JPGs, change the minimum size or only keep URLs that contain a word.

Release history

  1. v1.0.0

    Sticker ZIP Downloader added to the hub

    Grab every sticker on a page (GIF, WebP, PNG, SVG) into one ZIP from the browser console.