Search code examples
javascriptbookmarkletinject

How Does This Bookmarklet Bypass The Site's Filter Of Prompts?


So, my problem is that I am trying to find out how this bookmarklet bypasses the website's blocking of the code prompt(''); but I can't find it so I need help figuring out how this works. Here's the code for the bookmarklet

(() => {
  const c = async() => {
    var e = document.createElement("iframe"),
      e = (document.body.append(e), window.prompt = e.contentWindow.prompt.bind(window), e.remove(), Object.values(function e(t = document.querySelector("body>div")) {
        return Object.values(t)[1]?.children?.[0]?._owner.stateNode ? t : e(t.querySelector(":scope>div"))
      }())[1].children[0]._owner.stateNode)["props"];
    e.client.blook = prompt("Blook Name: (Case Sensitive)"), e.liveGameController.setVal({
      path: `c/${e.client.name}/b`,
      val: e.client.blook
    })
  };
  let l = new Image;
  l.src = "https://raw.githubusercontent.com/05Konz/Blooket-Cheats/main/autoupdate/timestamps/global/changeBlookIngame.png?"
  Date.now(), l.crossOrigin = "Anonymous", l.onload = function() {
    var e = document.createElement("canvas").getContext("2d");
    e.drawImage(l, 0, 0, this.width, this.height);
    let t = e.getImageData(0, 0, this.width, this.height)["data"],
      o = "",
      n;
    for (let e = 0; e < t.length; e = 4) {
      var a = String.fromCharCode(256 * t[e 1] t[e 2]);
      if (o = a, "/" == a && "*" == n) break;
      n = a
    }
    var e = document.querySelector("iframe"),
      [, r, i] = o.match(/LastUpdated: (. ?); ErrorMessage: "(. ?)"/);
    (parseInt(r) <= 1693429947381 || e.contentWindow.confirm(i)) && c()
  }, l.onerror = l.onabort = () => (l.src = null, c())
})();

that is all my problem is.

I tried finding an extracting the part that allows it to work but I couldn't so, I tried to google it and seach it up on this website but to no avail.


Solution

  • It creates an iframe with:

    var e = document.createElement("iframe")
    

    then copies the iframe's prompt() function to the current window:

    window.prompt = e.contentWindow.prompt.bind(window)
    

    This reverts prompt() to the default function.