Google 谷歌搜索结果以新标签页打开

将谷歌搜索结果的链接修改为以新标签页打开

当前为 2021-04-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Open Google Search Results in New Tab
  3. // @name:zh-CN Google 谷歌搜索结果以新标签页打开
  4. // @namespace https://github.com/zkqiang
  5. // @version 1.1
  6. // @description Modify the Google search results link to open in a new tab
  7. // @description:zh-CN 将谷歌搜索结果的链接修改为以新标签页打开
  8. // @author zkqiang
  9. // @match *://www.google.com/search?*
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16.  
  17. function modify(selectors) {
  18. try {
  19. var nodes = document.querySelectorAll(selectors);
  20. for (var m = 0; m < nodes.length; m++) {
  21. var links = nodes[m].getElementsByTagName('a');
  22. for (var n = 0; n < links.length; n++) {
  23. links[n].target = '_blank';
  24. }
  25. }
  26. } catch (err) {
  27. console.error('[tampermonkey-google-newtab] error: ' + err.toString())
  28. }
  29. }
  30.  
  31. modify('#res');
  32. modify('#bottomads');
  33. modify('#rhs');
  34. modify('#fsl');
  35. })();