Block Opener on Targeted Links

Add rel attribute values on mouseup to block window.opener in the linked site, also blocks referer (2016-09-01)

  1. // ==UserScript==
  2. // @name Block Opener on Targeted Links
  3. // @namespace JeffersonScher
  4. // @description Add rel attribute values on mouseup to block window.opener in the linked site, also blocks referer (2016-09-01)
  5. // @author Jefferson "jscher2000" Scher
  6. // @copyright Copyright 2016 Jefferson Scher
  7. // @license BSD 3-clause
  8. // @include *
  9. // @version 0.5
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. // Check what was clicked and rel it up if needed
  14. function BOoTL_relfix(evt){
  15. // is it always a link? are there other cases?
  16. var tgt = evt.target;
  17. if (tgt.nodeName != "A") return;
  18. // did we already hack it?
  19. if (tgt.hasAttribute("bootl")) return;
  20. // is it different origin?
  21. if (tgt.hostname == location.hostname) return;
  22. // does it have a target not replacing the page?
  23. var tgtatt = tgt.getAttribute("target") || "_self";
  24. if ("_self|_parent|_top".indexOf(tgtatt) > -1) return;
  25. // OKAY THEN add rel values + mark as modified
  26. var oldrel = tgt.getAttribute("rel") || "";
  27. tgt.setAttribute("rel", "noopener noreferrer "+oldrel);
  28. tgt.setAttribute("bootl", tgt.getAttribute("rel"));
  29. }
  30. // Add click event listener to the body
  31. document.body.addEventListener("mouseup", BOoTL_relfix, false);