[ALL] Links Open ALL in NEW BACKGROUND Tab

Open ALL links in NEW BACKGROUND tab.

  1. // ==UserScript==
  2. // @name [ALL] Links Open ALL in NEW BACKGROUND Tab
  3. // @author
  4. // @description Open ALL links in NEW BACKGROUND tab.
  5. // @downloadURL
  6. // @grant GM_openInTab
  7. // @homepageURL https://bitbucket.org/INSMODSCUM/userscripts-scripts/src
  8. // @icon
  9. // @include http*://*
  10. // @namespace insmodscum
  11. // @require https://greasyfork.org/scripts/12228/code/setMutationHandler.js
  12. // @run-at document-start
  13. // @updateURL
  14. // @version 1.0
  15. // ==/UserScript==
  16.  
  17. // needs this in metadata:
  18. // @require https://greasyfork.org/scripts/12228/code/setMutationHandler.js
  19.  
  20. // source:
  21. // https://greasyfork.org/en/scripts/12367-open-links-in-new-tab/code
  22.  
  23. attachHandler([].slice.call(document.getElementsByTagName('a')));
  24.  
  25. setMutationHandler(document, 'a', function(nodes) {
  26. attachHandler(nodes);
  27. return true;
  28. });
  29.  
  30. function attachHandler(nodes) {
  31. nodes.forEach(function(node) {
  32. if (node.target != '_blank') {
  33. node.onclick = clickHandler;
  34. node.addEventListener('click', clickHandler);
  35. }
  36. });
  37. }
  38.  
  39. function clickHandler(e) {
  40. if (e.button > 1)
  41. return;
  42. e.preventDefault();
  43. e.stopPropagation();
  44. e.stopImmediatePropagation();
  45. // GM_openInTab(this.href, e.button || e.ctrlKey);
  46. GM_openInTab(this.href, true);
  47. }