79569310

Date: 2025-04-11 16:26:40
Score: 0.5
Natty:
Report link

Here is my working example:

(function () {
  let lastUrl = location.href;

  function runCustomScript() {
document.querySelectorAll("p").forEach(node => {
            { node.style.backgroundColor = "Yellow"; }
        });
}

  function checkUrlChange() {
    const currentUrl = location.href;
    if (currentUrl !== lastUrl) {
      lastUrl = currentUrl;
      runCustomScript();
    }
  }

  const pushState = history.pushState;
  const replaceState = history.replaceState;

  history.pushState = function () {
    const result = pushState.apply(this, arguments);
    checkUrlChange();
    return result;
  };

  history.replaceState = function () {
    const result = replaceState.apply(this, arguments);
    checkUrlChange();
    return result;
  };

  window.addEventListener("popstate", checkUrlChange);

  setInterval(checkUrlChange, 1000);

  runCustomScript();
})();
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Doldrums