Open Links in Gmail

Open all matching links in Gmail using "i".

  1. // ==UserScript==
  2. // @name Open Links in Gmail
  3. // @namespace https://wiki.gslin.org/wiki/Open_Links_in_Gmail
  4. // @version 0.20210910.0
  5. // @description Open all matching links in Gmail using "i".
  6. // @author Gea-Suan Lin <darkkiller@gmail.com>
  7. // @match https://mail.google.com/*
  8. // @grant GM_addStyle
  9. // @grant GM_getValue
  10. // @grant GM_openInTab
  11. // @grant GM_registerMenuCommand
  12. // @grant GM_setValue
  13. // @require https://greasyfork.org/scripts/38445-monkeyconfig/code/MonkeyConfig.js?version=251319
  14. // @license MIT
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. let cfg = new MonkeyConfig({
  21. menuCommand: true,
  22. params: {
  23. match_regex: {
  24. type: 'text',
  25. default: '^https://github\.com/[^/]+/[^/]+/commit/',
  26. },
  27. },
  28. title: 'Open Links in Gmail',
  29. });
  30.  
  31. let match_regex = new RegExp(cfg.get('match_regex'));
  32. window.addEventListener('keydown', ev => {
  33. if ('i' === ev.key) {
  34. for (let el of document.querySelectorAll('div[role="listitem"]:first-child a')) {
  35. let href = el.getAttribute('href');
  36. if (href.match(match_regex)) {
  37. GM_openInTab(href, true);
  38. }
  39. }
  40. }
  41. });
  42. })();