BC - Recent Activity Links - Open in new tab

Allows users to open Recent Activity links in a new tab

  1. // ==UserScript==
  2. // @name BC - Recent Activity Links - Open in new tab
  3. // @author Brad Mitchell
  4. // @homepage https://github.com/bairdley
  5. // @version 0.1
  6. // @namespace https://forum.bigcommerce.com
  7. // @description Allows users to open Recent Activity links in a new tab
  8. // @match https://forum.bigcommerce.com/*
  9. // @grant none
  10. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
  11. // ==/UserScript==
  12. (function () {
  13. var OS,
  14. urlExt = '/s/question/',
  15. dataID,
  16. newTabCount = 0,
  17. keyCodes,
  18. keyed = false,
  19. currentKey;
  20. (function () {
  21. if (navigator.appVersion.indexOf('Win') != - 1) {
  22. OS = 'win';
  23. keyCodes = {
  24. ctrl: 238
  25. };
  26. } else {
  27. OS = 'mac';
  28. keyCodes = {
  29. ctrl: 17,
  30. cmdL: 91,
  31. cmdR: 93,
  32. cmdFF: 224
  33. };
  34. }
  35. }());
  36. $(document).keydown(function (e) {
  37. for (var i in keyCodes) {
  38. if (e.which === keyCodes[i]) {
  39. currentKey = keyCodes[i];
  40. keyed = true;
  41. }
  42. }
  43. });
  44. $(document).keyup(function (e) {
  45. if (e.which === currentKey) {
  46. keyed = false;
  47. }
  48. });
  49. $('.compactFeedElement').live('mouseover', function () {
  50. $(this).mousedown(function (e) {
  51. var el = $(this).find('a').andSelf();
  52. if ($(this).attr('data-id')) {
  53. dataID = $(this).attr('data-id');
  54. if (e.which !== 1 && keyed === false) {
  55. clicks.right(el);
  56. } else if (OS === 'win') {
  57. if (keyed === true && currentKey === keyCodes.ctrl) {
  58. clicks.win.ctrlClick(el);
  59. }
  60. } else if (OS === 'mac') {
  61. if (keyed === true && currentKey === (keyCodes.cmdFF || keyCodes.cmdR || keyCodes.cmdL)) {
  62. clicks.mac.cmdClick(el);
  63. } else if (keyed === true && currentKey === keyCodes.ctrl) {
  64. setHref.url(el);
  65. }
  66. }
  67. }
  68. }).mouseleave(function () {
  69. setHref.void ($(this).find('a').andSelf());
  70. });
  71. });
  72. function newTab() {
  73. window.open(urlExt + dataID);
  74. var int = setInterval(function () {
  75. if (newTabCount > 0) {
  76. newTabCount = 0;
  77. window.clearInterval(int);
  78. }
  79. }, 500);
  80. }
  81. var setHref = {
  82. url: function (el) {
  83. $(el).attr('href', urlExt + dataID);
  84. },
  85. void : function (el) {
  86. $(el).attr('href', 'javascript:void(0)');
  87. keyed = false;
  88. }
  89. };
  90. var clicks = {
  91. mac: {
  92. cmdClick: function (el) {
  93. while (newTabCount < 1) {
  94. newTab();
  95. newTabCount += 1;
  96. }
  97. },
  98. ctrlClick: function (el) {
  99. }
  100. },
  101. win: {
  102. ctrlClick: function (el) {
  103. }
  104. },
  105. right: function (el) {
  106. setHref.url(el);
  107. }
  108. };
  109. }) ();