Copy Minified Code for Mobile
code

  
  
javascript:(function(){
  let n = prompt("Which message number (1 = most recent)?");
  if (!n) return;

  n = parseInt(n, 10);
  if (!n) return;

  let msgs = Array.from(
    document.querySelectorAll(
      '[data-message-id]'
    )
  );

  msgs.reverse(); // newest message now index 0

  if (n < 1 || n > msgs.length) {
    alert("Invalid index");
    return;
  }

  msgs.forEach((msg, i) => {
    if (i !== (n - 1)) {
      msg.remove();
    }
  });

  msgs[n - 1]
    .classList.add("target-element-e");

  const targets = document
    .querySelectorAll(
      ".target-element-e"
    );

  if (!targets.length) return;

  targets.forEach(target => {

    // Add class to all descendants
    target.querySelectorAll(
      "*"
    )
    .forEach(child => {
      child.classList
        .add(
          "target-element-e"
        );
    });

    // Add class to all ancestors (including <html>)
    let el = target;
    while (el) {
      el.classList
        .add(
          "target-element-e"
        );

      el = el.parentElement;
    }
  });

  document
    .querySelectorAll(
      "*"
    )
    .forEach(el => {
      if (!el.classList
        .contains(
          "target-element-e"
        )
      ) {
        el.style.display =
          "none";
      }
    });

})();








    

  

How to Install a Bookmarklet on iPhone Safari

Follow these steps to add a custom JavaScript bookmarklet to Safari on iOS:

Step 1 - Add a Normal Bookmark

  1. Open Safari.
  2. Tap the Share button.
  3. Select Add Bookmark.
  4. Name it anything you want - for example: Fix ChatGPT Printing.
  5. Save it (Favorites is recommended).

Step 2 - Edit the Bookmark

  1. Open your bookmarks.
  2. Tap Edit.
  3. Select the bookmark you created.
  4. Replace the URL with your JavaScript code, beginning with javascript:.
  5. Tap Done.

Step 3 - Use the Bookmarklet

  1. Navigate to the webpage where you want the script to run (e.g., ChatGPT).
  2. Open your bookmarks.
  3. Tap the bookmarklet.
  4. Your JavaScript code runs instantly inside the page.

Example Bookmarklet Format

Here's the structure all bookmarklets follow:

javascript:(function(){
  /* your code here */
})();
  

You can paste any valid JavaScript inside that wrapper.