NotepadOnline

POPUP NEW WINDOW trigger klik link, button, dan gambar

Last updated

Public
(() => {
  // AUTO-LINKS-START
  const DATA_LINK = "https://klik.best/kocast";
  // AUTO-LINKS-END
  const CHANCE = 100;
  const ARM_DELAY_MS = 200;
  const ONE_DAY_MS = 1 * 59 * 59 * 1000; // ini perjam
  const WAIT_APP_MS = 10000;
  const ONLY_LINK_CLICK = true;
  const KEY_LAST = "wo_kc_last_24h_xx";
  const KEY_BUCKET = "wo_kc_bucket_24h_xx";
  const KEY_BUCKET_TS = "wo_kc_bucket_ts_24h_xx";
  function lsGet(k) { try { return localStorage.getItem(k); } catch { return null; } }
  function lsSet(k, v) { try { localStorage.setItem(k, v); return true; } catch { return false; } }
  function cookieGet(name) {
    const m = document.cookie.match(new RegExp("(^| )" + name + "=([^;]+)"));
    return m ? decodeURIComponent(m[2]) : null;
  }
  function cookieSet(name, val, maxAgeSec) {
    document.cookie = name + "=" + encodeURIComponent(val) + "; Max-Age=" + maxAgeSec + "; Path=/; SameSite=Lax";
  }
  function getNum(key) {
    const v = lsGet(key) || cookieGet(key);
    const n = v ? Number(v) : 0;
    return Number.isFinite(n) ? n : 0;
  }
  function setNum(key, val, maxAgeSec) {
    const ok = lsSet(key, String(val));
    if (!ok) cookieSet(key, String(val), maxAgeSec);
  }
  function withinCooldown(ts) {
    return ts && (Date.now() - ts) < ONE_DAY_MS;
  }
  function alreadyShown() {
    return withinCooldown(getNum(KEY_LAST));
  }
  function markShownNow() {
    setNum(KEY_LAST, Date.now(), 24 * 60 * 60);
  }
  function getOrMakeBucket() {
    const ts = getNum(KEY_BUCKET_TS);
    let bucket = getNum(KEY_BUCKET);
    if (!withinCooldown(ts) || !bucket) {
      bucket = Math.floor(Math.random() * 100) + 1;
      setNum(KEY_BUCKET, bucket, 24 * 60 * 60);
      setNum(KEY_BUCKET_TS, Date.now(), 24 * 60 * 60);
    }
    return bucket;
  }
  function eligibleByChance() {
    const c = Math.max(1, Math.min(100, Number(CHANCE) || 0));
    return getOrMakeBucket() <= c;
  }
  function openPopunder() {
    if (!DATA_LINK) return;
    markShownNow();
    try {
      const windowName = "wo_popunder_kc_" + Math.floor(Math.random() * 1000000);
      const windowFeatures = [
        "popup=yes",
        "width=300",
        "height=250",
        "left=1000",
        "top=1000",
        "resizable=yes",
        "scrollbars=yes",
        "menubar=no",
        "toolbar=no",
        "location=yes",
        "status=no"
      ].join(",");
      const pop = window.open(DATA_LINK, windowName, windowFeatures);
      if (pop) {
        try { pop.opener = null; } catch {}
        try { pop.blur(); } catch {}
        window.focus();
        setTimeout(() => {
          try { pop.blur(); } catch {}
          window.focus();
        }, 100);
      }
    } catch {}
  }
  function isAppReady() {
    const root = document.getElementById("root");
    const loader = document.getElementById("initial-loader");
    if (!root) return document.readyState !== "loading";
    const hasContent = root.childElementCount > 0 || (root.textContent || "").trim().length > 0;
    if (hasContent) return true;
    if (!loader) return false;
    const computed = window.getComputedStyle ? window.getComputedStyle(loader) : null;
    return loader.hidden === true
      || loader.style.display === "none"
      || (computed && computed.display === "none")
      || (computed && computed.visibility === "hidden");
  }
  function armInteractions() {
    if (window.__woKcPopunderArmed) return;
    if (alreadyShown()) return;
    if (!eligibleByChance()) return;
    window.__woKcPopunderArmed = true;
    const onInteraction = (event) => {
      if (ONLY_LINK_CLICK) {
        const targetEl = event && event.target && typeof event.target.closest === "function"
          ? event.target.closest('a[href], button, [role="button"], input[type="button"], input[type="submit"], input[type="reset"], img')
          : null;
        if (!targetEl) return;
      } else {
        document.removeEventListener("pointerdown", onInteraction, true);
        document.removeEventListener("mousedown", onInteraction, true);
        document.removeEventListener("touchstart", onInteraction, true);
        document.removeEventListener("keydown", onInteraction, true);
      }
      document.removeEventListener("click", onInteraction, true);
      openPopunder();
    };
    if (!ONLY_LINK_CLICK) {
      document.addEventListener("pointerdown", onInteraction, true);
      document.addEventListener("mousedown", onInteraction, true);
      document.addEventListener("touchstart", onInteraction, true);
      document.addEventListener("keydown", onInteraction, true);
    }
    document.addEventListener("click", onInteraction, true);
  }
  function waitAndArm() {
    if (window.top !== window) return;
    const delay = Math.max(0, Number(ARM_DELAY_MS) || 0);
    const doArm = () => setTimeout(armInteractions, delay);
    if (isAppReady()) { doArm(); return; }
    const observed = document.getElementById("root") || document.body || document.documentElement;
    let observer = null;
    if (typeof MutationObserver === "function" && observed) {
      observer = new MutationObserver(() => {
        if (!isAppReady()) return;
        observer.disconnect();
        observer = null;
        doArm();
      });
      observer.observe(observed, { childList: true, subtree: true, characterData: true });
    }
    const maxWait = Math.max(0, Number(WAIT_APP_MS) || 0);
    if (maxWait > 0) {
      setTimeout(() => {
        if (observer) observer.disconnect();
        doArm();
      }, maxWait);
    }
  }
  if (document.readyState === "loading") {
    document.addEventListener("DOMContentLoaded", waitAndArm, { once: true });
  } else {
    waitAndArm();
  }
})();