StackExchange link newtaber

this code opens links from posts, answers, comments and user signatures in the new tab instead of the annoying in-place opening

当前为 2018-04-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name StackExchange link newtaber
  3. // @namespace almaceleste
  4. // @version 0.3.7
  5. // @description this code opens links from posts, answers, comments and user signatures in the new tab instead of the annoying in-place opening
  6. // @description:ru этот код открывает ссылки из постов, ответов, комментариев и подписей пользователей в новой вкладке вместо надоедливого открытия в текущей
  7. // @author (ɔ) Paola Captanovska
  8. // @license GPL-3.0+; http://www.gnu.org/licenses/gpl-3.0.txt
  9. // @icon https://cdn1.iconfinder.com/data/icons/feather-2/24/external-link-128.png
  10.  
  11. // @homepageURL https://greasyfork.org/en/users/174037-almaceleste
  12. // @homepageURL https://openuserjs.org/users/almaceleste
  13. // @homepageURL https://github.com/almaceleste/userscripts
  14. // @supportURL https://github.com/almaceleste/userscripts/issues
  15.  
  16. // @require https://openuserjs.org/src/libs/sizzle/GM_config.js
  17. // @grant GM_getValue
  18. // @grant GM_setValue
  19. // @grant GM_registerMenuCommand
  20.  
  21. // @match https://*.stackexchange.com/questions/*
  22. // @match https://*.stackoverflow.com/questions/*
  23. // @match https://askubuntu.com/questions/*
  24. // @match https://mathoverflow.net/questions/*
  25. // @match https://serverfault.com/questions/*
  26. // @match https://stackapps.com/questions/*
  27. // @match https://superuser.com/questions/*
  28. // ==/UserScript==
  29.  
  30. // ==OpenUserJS==
  31. // @author almaceleste
  32. // ==/OpenUserJS==
  33.  
  34. const postlink = '.post-text a';
  35. const commentlink = '.comment-copy a';
  36. const userdetailslink = '.user-details a';
  37.  
  38. const windowcss = '#newtaberCfg {background-color: lightblue;} #newtaberCfg .reset_holder {float: left; position: relative; bottom: -1em;} #newtaberCfg .saveclose_buttons {margin: .7em;}';
  39. const iframecss = 'height: 19.2em; width: 30em; border: 1px solid; border-radius: 3px; position: fixed; z-index: 999;';
  40.  
  41. GM_registerMenuCommand('StackExchange link newtaber Settings', opencfg);
  42.  
  43. function opencfg()
  44. {
  45. GM_config.open();
  46. newtaberCfg.style = iframecss;
  47. }
  48.  
  49. GM_config.init(
  50. {
  51. id: 'newtaberCfg',
  52. title: 'StackExchange link newtaber Settings',
  53. fields:
  54. {
  55. postlink:
  56. {
  57. section: ['Link types', 'Choose link types to open in new tab'],
  58. label: 'post links',
  59. labelPos: 'right',
  60. type: 'checkbox',
  61. default: true,
  62. },
  63. commentlink:
  64. {
  65. label: 'comment links',
  66. labelPos: 'right',
  67. type: 'checkbox',
  68. default: true,
  69. },
  70. userdetailslink:
  71. {
  72. label: 'userdetails links',
  73. labelPos: 'right',
  74. type: 'checkbox',
  75. default: true,
  76. },
  77. },
  78. css: windowcss,
  79. events:
  80. {
  81. save: function() {
  82. GM_config.close();
  83. }
  84. },
  85. });
  86.  
  87. (function() {
  88. 'use strict';
  89.  
  90. var links = [];
  91.  
  92. if(GM_config.get('postlink')) links.push(postlink);
  93. if(GM_config.get('commentlink')) links.push(commentlink);
  94. if(GM_config.get('userdetailslink')) links.push(userdetailslink);
  95.  
  96. var pattern = links.join(', ');
  97.  
  98. $(pattern).each(function() {
  99. $(this).click(function(event) {
  100. event.preventDefault();
  101. event.stopPropagation();
  102. window.open(this.href, '_blank');
  103. });
  104. });
  105. })();