JIRA templates

Allows saving JIRA issue descriptions and comments for reuse.

  1. // ==UserScript==
  2. // @name JIRA templates
  3. // @namespace devsandbox.nfshost.com
  4. // @description Allows saving JIRA issue descriptions and comments for reuse.
  5. // @include *.atlassian.net/*
  6. // @version 1.1
  7. // @grant none
  8. // ==/UserScript==
  9. var modifyEditor = function(editor) {
  10. if (editor.classList.contains('templatized')) {return;}
  11. var textarea = editor.querySelector('textarea');
  12. var child = document.createElement('div');
  13. var templates_key = 'templates-'+editor.id;
  14. var select = document.createElement('select');
  15. child.appendChild(select);
  16. var templates = localStorage.getItem(templates_key) || '[]';
  17. templates = JSON.parse(templates);
  18. renderTemplates(select, templates);
  19. var apply = document.createElement('input');
  20. apply.type = 'button';
  21. apply.value = 'Apply';
  22. apply.addEventListener('click', function() {
  23. var name = select.value;
  24. var content = localStorage.getItem(templates_key+'-'+name);
  25. textarea.value = content;
  26. });
  27. child.appendChild(apply);
  28. var forget = document.createElement('input');
  29. forget.type = 'button';
  30. forget.value = 'Forget';
  31. forget.addEventListener('click', function() {
  32. var name = select.value;
  33. if (!name) {return;}
  34. if (!confirm('Are you sure you want to forget '+name+'?')) {return;}
  35. var index = templates.indexOf(name);
  36. templates.splice(index, 1);
  37. saveTemplates(templates_key, templates);
  38. renderTemplates(select, templates);
  39. });
  40. child.appendChild(forget);
  41. var create = document.createElement('input');
  42. create.type = 'button';
  43. create.value = 'Create';
  44. create.addEventListener('click', function() {
  45. var name = prompt('Template name:');
  46. var content = textarea.value;
  47. localStorage.setItem(templates_key+'-'+name, content);
  48. templates.push(name);
  49. saveTemplates(templates_key, templates);
  50. renderTemplates(select, templates);
  51. });
  52. child.appendChild(create);
  53. editor.appendChild(child);
  54. editor.classList.add('templatized');
  55. };
  56.  
  57. var renderTemplates = function(select, templates) {
  58. select.innerHTML = '';
  59. templates.forEach(function(name) {
  60. var option = document.createElement('option');
  61. option.value = name;
  62. option.textContent = name;
  63. select.appendChild(option);
  64. });
  65. };
  66.  
  67. var saveTemplates = function(templatesKey, templates) {
  68. localStorage.setItem(templatesKey, JSON.stringify(templates));
  69. };
  70.  
  71. var findEditors = function() {
  72. var editor;
  73. if (editor = document.getElementById('description-wiki-edit')) {
  74. modifyEditor(editor);
  75. }
  76. if (editor = document.getElementById('comment-wiki-edit')) {
  77. modifyEditor(editor);
  78. }
  79. };
  80.  
  81. setInterval(findEditors, 500);

QingJ © 2025

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