Untarget _blank

Murderise target="_blank"

  1. // ==UserScript==
  2. // @name Untarget _blank
  3. // @namespace https://git.sr.ht/~remph
  4. // @include *
  5. // @grant none
  6. // @version 0.2
  7. // @author Remph
  8. // @description Murderise target="_blank"
  9. // @license GPL-3.0-or-later
  10. // ==/UserScript==
  11.  
  12. function unblank(root) {
  13. root.querySelectorAll(
  14. 'a[target="_blank"], base[target="_blank"]' // form[target="_blank"]
  15. ).forEach((a) => a.setAttribute('target', '_self')); // could also removeAttribute
  16. }
  17.  
  18. (function() {
  19. unblank(document.body); // run straight away to unblank static content
  20. // hang around in the background to keep interfering
  21. new MutationObserver(
  22. (muts) => muts.forEach((mut) => unblank(mut.target))
  23. ).observe(document.body, {
  24. subtree: true, childList: true, attributes: true
  25. });
  26. })();