JombY / Gitlab JIRA link

// ==UserScript==
// @name         Gitlab JIRA link
// @namespace    http://tampermonkey.net/
// @version      0.1
// @author       JombY
// @license      Apache-2.0
// @include      /^https:\/\/gitlab.*\//
// @icon         https://www.google.com/s2/favicons?domain=gitlab.com
// @grant        none
// ==/UserScript==

/* jshint esversion: 8 */

(async function () {
  const pattern = /[A-Z0-9]+DEV[- ][0-9]+/i; // switch to own
  const jiraUrl = "https://corporate.atlassian.net/browse/"; // switch to own

  const walk = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
  let node;
  while ((node = walk.nextNode())) {
    let text = node.textContent;
    const matches = text.match(pattern);
    if (matches) {
      for (let i = 0; i < matches.length; i++) {
        const jiraKey = matches[i];
        const jiraLink = `<a href="${jiraUrl}${jiraKey.replace(' ', '-')}">${jiraKey}</a>`;
        text = text.replace(new RegExp(matches[i], 'g'), jiraLink);
      }
      const template = document.createElement('template');
      template.innerHTML = text;
      node.parentNode.replaceChild(template.content, node);
    }
  }
})();