谷歌搜索:新建标签页打开链接

点击搜索结果中的链接时在新标签页中打开

目前为 2020-03-15 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Google-open-in-new-tab
  3. // @name:ZH-CN 谷歌搜索:新建标签页打开链接
  4. // @name:ZH-TW 谷歌搜尋:新建標籤頁打開鏈接
  5. // @namespace https://github.com/li-zyang/
  6. // @version 1.0.0
  7. // @description Open links in the google search results in a new tab
  8. // @description:ZH-CN 点击搜索结果中的链接时在新标签页中打开
  9. // @description:ZH-TW 點擊搜索結果中的連接時在新標籤頁中打開
  10. // @author 阿昭
  11. // @include https://www.google.com/*
  12. // @require https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js
  13. // @grant GM_setValue
  14. // @grant GM_getValue
  15. // @noframes
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20. $('#taw a').attr('target', '_blank').attr('rel', 'noopener');
  21. $('#taw div:nth-of-type(2) a').attr('target', '');
  22. $('#res a').attr('target', '_blank').attr('rel', 'noopener');
  23. $('#rhs a').attr('target', '_blank').attr('rel', 'noopener');
  24. $('#taw a').unbind().removeAttr('onmousedown').removeAttr('onclick');
  25. $('#taw a').off('click');
  26. $('#res a').unbind().removeAttr('onmousedown').removeAttr('onclick');
  27. $('#res a').off('click');
  28. $('#rhs a').unbind().removeAttr('onmousedown').removeAttr('onclick');
  29. $('#rhs a').off('click');
  30. let observer = new MutationObserver(function(mulist) {
  31. for (var mutation of mulist) {
  32. if (mutation.type == 'childList') {
  33. let jq_target = $(mutation.target);
  34. if ($('#taw') in jq_target.parents) {
  35. $('#taw a').attr('target', '_blank').attr('rel', 'noopener');
  36. $('#taw a').unbind().removeAttr('onmousedown').removeAttr('onclick');
  37. $('#taw a').off('click');
  38. $('#taw div:nth-of-type(2) a').attr('target', '');
  39. } else if ($('#res') in jq_target.parents) {
  40. $('#res a').attr('target', '_blank').attr('rel', 'noopener');
  41. $('#res a').unbind().removeAttr('onmousedown').removeAttr('onclick');
  42. $('#res a').off('click');
  43. } else if ($('#rhs') in jq_target.parents) {
  44. $('#rhs a').attr('target', '_blank').attr('rel', 'noopener');
  45. $('#rhs a').unbind().removeAttr('onmousedown').removeAttr('onclick');
  46. $('#rhs a').off('click');
  47. }
  48. }
  49. }
  50. });
  51. observer.observe($('#rcnt')[0], {
  52. childList: true,
  53. subtree: true
  54. });
  55. })();