JIRA Links

Link JIRA issues by patterns. Change variables below to match your issue pattern and JIRA URL

  1. // ==UserScript==
  2. // @name JIRA Links
  3. // @namespace http://github.com/
  4. // @description Link JIRA issues by patterns. Change variables below to match your issue pattern and JIRA URL
  5. // @include https://url_where_you_want_the_script_to_work.com/*
  6. // @include https://*.also_works_with_wildcard.com/*
  7. // @version 1
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
  9. // ==/UserScript==
  10.  
  11. localStorage['issue-patterns'] = "ABCD-\\d+";
  12. localStorage['jira-url'] = "https://jira.yoursite.com/jira/";
  13.  
  14. function replaceInElement(element, find, replace) {
  15. for (var i= element.childNodes.length; i-->0;) {
  16. var child= element.childNodes[i];
  17. if (child.nodeType==1) {
  18. var tag= child.nodeName.toLowerCase();
  19. if (tag!='style' && tag!='script')
  20. replaceInElement(child, find, replace);
  21. } else if (child.nodeType==3) { // TEXT_NODE
  22. replaceInText(child, find, replace);
  23. }
  24. }
  25. }
  26.  
  27. function replaceInText(text, find, replace) {
  28. var match;
  29. var matches= [];
  30. while (match= find.exec(text.data))
  31. matches.push(match);
  32. for (var i= matches.length; i-->0;) {
  33. match= matches[i];
  34. text.splitText(match.index);
  35. text.nextSibling.splitText(match[0].length);
  36. text.parentNode.replaceChild(replace(match), text.nextSibling);
  37. }
  38. }
  39.  
  40. setTimeout(function() {
  41. var find = new RegExp('\\b\(' + localStorage['issue-patterns'] + '\)\\b', 'gi');
  42.  
  43. replaceInElement(document.body, find, function(match) {
  44. var link= document.createElement('a');
  45. link.href= localStorage['jira-url'] + 'browse/' + match[0].replace(/([A-Z]+)(\d+)/,'\$1-\$2');
  46. link.appendChild(document.createTextNode(match[0]));
  47. return link;
  48. });
  49. }, 1000);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址