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-05-04 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name StackExchange link newtaber
  3. // @namespace almaceleste
  4. // @version 0.4
  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 AGPL-3.0; http://www.gnu.org/licenses/agpl.txt
  9. // @icon https://cdn1.iconfinder.com/data/icons/simple-icons/32/stackexchange-32-black.png
  10. // @icon64 https://cdn1.iconfinder.com/data/icons/simple-icons/128/stackexchange-128-black.png
  11.  
  12. // @homepageURL https://greasyfork.org/en/users/174037-almaceleste
  13. // @homepageURL https://openuserjs.org/users/almaceleste
  14. // @homepageURL https://github.com/almaceleste/userscripts
  15. // @supportURL https://github.com/almaceleste/userscripts/issues
  16.  
  17. // @require https://openuserjs.org/src/libs/sizzle/GM_config.js
  18. // @grant GM_getValue
  19. // @grant GM_setValue
  20. // @grant GM_registerMenuCommand
  21.  
  22. // @match https://*.stackexchange.com/questions/*
  23. // @match https://*.stackoverflow.com/questions/*
  24. // @match https://askubuntu.com/questions/*
  25. // @match https://mathoverflow.net/questions/*
  26. // @match https://serverfault.com/questions/*
  27. // @match https://stackapps.com/questions/*
  28. // @match https://superuser.com/questions/*
  29. // ==/UserScript==
  30.  
  31. // ==OpenUserJS==
  32. // @author almaceleste
  33. // ==/OpenUserJS==
  34.  
  35. const postlink = '.post-text a';
  36. const commentlink = '.comment-copy a';
  37. const userdetailslink = '.user-details a';
  38.  
  39. const windowcss = '#newtaberCfg {background-color: lightblue;} #newtaberCfg .reset_holder {float: left; position: relative; bottom: -1em;} #newtaberCfg .saveclose_buttons {margin: .7em;}';
  40. const iframecss = 'height: 17.2em; width: 30em; border: 1px solid; border-radius: 3px; position: fixed; z-index: 999;';
  41.  
  42. GM_registerMenuCommand('StackExchange link newtaber Settings', opencfg);
  43.  
  44. function opencfg()
  45. {
  46. GM_config.open();
  47. newtaberCfg.style = iframecss;
  48. }
  49.  
  50. GM_config.init(
  51. {
  52. id: 'newtaberCfg',
  53. title: 'StackExchange link newtaber',
  54. fields:
  55. {
  56. postlink:
  57. {
  58. section: ['Link types', 'Choose link types to open in new tab'],
  59. label: 'post links',
  60. labelPos: 'right',
  61. type: 'checkbox',
  62. default: true,
  63. },
  64. commentlink:
  65. {
  66. label: 'comment links',
  67. labelPos: 'right',
  68. type: 'checkbox',
  69. default: true,
  70. },
  71. userdetailslink:
  72. {
  73. label: 'userdetails links',
  74. labelPos: 'right',
  75. type: 'checkbox',
  76. default: true,
  77. },
  78. },
  79. css: windowcss,
  80. events:
  81. {
  82. save: function() {
  83. GM_config.close();
  84. }
  85. },
  86. });
  87.  
  88. (function() {
  89. 'use strict';
  90.  
  91. var links = [];
  92.  
  93. if(GM_config.get('postlink')) links.push(postlink);
  94. if(GM_config.get('commentlink')) links.push(commentlink);
  95. if(GM_config.get('userdetailslink')) links.push(userdetailslink);
  96.  
  97. var pattern = links.join(', ');
  98.  
  99. // $(pattern).each(function() {
  100. // $(this).click(function(event) {
  101. // event.preventDefault();
  102. // event.stopPropagation();
  103. // window.open(this.href, '_blank');
  104. // });
  105. // });
  106. $(pattern).attr('target', '_blank');
  107. })();