Open in New Tab

Always open a new tab

  1. // ==UserScript==
  2. // @name Open in New Tab
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.0
  5. // @description Always open a new tab
  6. // @author JackCodeTW
  7. // @license MIT
  8. // @match https://*/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict'
  15.  
  16. function externalize() {
  17. document.querySelectorAll('a')
  18. .forEach((r) => {
  19. if (!r.hasAttribute('target')) {
  20. r.setAttribute('target', '_blank')
  21. }
  22. })
  23. }
  24.  
  25. ////////////////////////////////////////
  26.  
  27. function run() {
  28. externalize()
  29. }
  30.  
  31. run()
  32. })()