Launchpad bug tags helper

LP bugs tags helper

目前为 2017-08-24 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Launchpad bug tags helper
  3. // @namespace https://launchpad.net/~julian-liu
  4. // @version 0.2
  5. // @description LP bugs tags helper
  6. // @author Julian Liu
  7. // @match https://bugs.launchpad.net/*/+filebug
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. function interceptorSetup() {
  12. // override submit handling
  13. HTMLFormElement.prototype.real_submit = HTMLFormElement.prototype.submit;
  14. HTMLFormElement.prototype.submit = interceptor;
  15.  
  16. document.getElementById('filebug-form').addEventListener('submit', function(e) {
  17. // stop the form from submitting
  18. e.preventDefault();
  19.  
  20. interceptor(e);
  21. }, true);
  22. }
  23.  
  24. function interceptor(e) {
  25. var frm = e ? e.target : this;
  26.  
  27. tagNode = frm.elements['field.tags'];
  28.  
  29. if (tagNode.value.length === 0) {
  30. var check = confirm('No tags entered. Are you sure to submit this bug without any tag?');
  31. if (!check) {
  32. return;
  33. }
  34. }
  35. // submit default is prevented, so we add new submit node instead
  36. submitNode = document.createElement('input');
  37. submitNode.name = 'field.actions.submit_bug';
  38. submitNode.type = 'text';
  39. submitNode.value = 'Submit Bug Report';
  40. frm.appendChild(submitNode);
  41. HTMLFormElement.prototype.real_submit.apply(frm);
  42. }
  43.  
  44. function addTagStyle() {
  45. var menuStyle = `
  46. #wrap {
  47. width: 100px;
  48. height: 50px;
  49. padding-bottom: 10px;
  50. margin: 0; /* Ensures there is no space between sides of the screen and the menu */
  51. z-index: 1; /* Makes sure that your menu remains on top of other page elements */
  52. background-color: GhostWhite;
  53. }
  54. .navbar {
  55. height: 50px;
  56. padding: 0;
  57. padding-bottom: 10px;
  58. margin: 0;
  59. border-right: 1px solid #fafaff;
  60. z-index: 12;
  61. }
  62. .navbar li {
  63. padding-bottom: 10px;
  64. height: auto;
  65. width: 100px; /* Each menu item is 100px wide */
  66. /*float: left; This lines up the menu items horizontally */
  67. object-position: top;
  68. text-align: center; /* All text is placed in the center of the box */
  69. list-style: none; /* Removes the default styling (bullets) for the list */
  70. font: normal bold 12px/1.2em Arial, Verdana, Helvetica;
  71. padding: 0;
  72. margin: 0;
  73. background-color: GhostWhite;
  74. }
  75. .navbar a {
  76. padding: 18px 0; /* Adds a padding on the top and bottom so the text appears centered vertically */
  77. border-left: 1px solid #fafaff; /* Creates a border in a slightly lighter shade of blue than the background. Combined with the right border, this creates a nice effect. */
  78. border-right: 1px solid #fafaff; /* Creates a border in a slightly darker shade of blue than the background. Combined with the left border, this creates a nice effect. */
  79. text-decoration: none; /* Removes the default hyperlink styling. */
  80. color: #000; /* Text color is black */
  81. display: block;
  82. }
  83. .navbar li:hover, a:hover {
  84. background-color: #e5f3ff;
  85. }
  86. .navbar li ul {
  87. display: none; /* Hides the drop-down menu */
  88. margin: 0; /* Aligns drop-down box underneath the menu item */
  89. padding: 0; /* Aligns drop-down box underneath the menu item */
  90. margin-left: 100px;
  91. float:left;
  92. margin-top: -45px;
  93. height: 0;
  94. }
  95. .navbar li:hover ul {
  96. display: block; /* Displays the drop-down box when the menu item is hovered over */
  97. z-index: 12;
  98. padding-left: 1px;
  99. }
  100. .navbar li ul li {
  101. background-color: #e1e1e7;
  102. width: 150px;
  103. font: normal 12px/1.2em Arial, Verdana, Helvetica;
  104. }
  105. .navbar li ul li a {
  106. border-left: 1px solid #0026ff;
  107. border-right: 1px solid #0026ff;
  108. border-top: 1px solid #0026ff;
  109. z-index: 1001;
  110. }
  111. .navbar li ul li:hover {
  112. background-color: #d1d7e8;
  113. z-index: 1000;
  114. }
  115. .checkedmark:before {
  116. content: '✓';
  117. }
  118. `;
  119.  
  120. var css = document.createElement("style");
  121. css.type = "text/css";
  122. css.innerHTML = menuStyle;
  123. document.body.appendChild(css);
  124. }
  125.  
  126. function toggleTagValue(tag) {
  127. var tagNode = document.getElementById('filebug-form').elements['field.tags'];
  128. var liNode = document.getElementById('taglist.' + tag);
  129.  
  130. if (tagNode.value.indexOf(tag) !== -1) {
  131. tagNode.value = tagNode.value.replace(' ' + tag, '');
  132. tagNode.value = tagNode.value.replace(tag, '');
  133. liNode.className = '';
  134. }
  135. else {
  136. tagNode.value = tagNode.value + ' ' + tag;
  137. liNode.className = 'checkedmark';
  138. }
  139. }
  140.  
  141. function insertAfter(newNode, referenceNode) {
  142. referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
  143. }
  144.  
  145. function tagList() {
  146. var allTags = {
  147. function: ['wifi', 'bluetooth', 'wwan', 'hibernate', 'battery', 'graphic', 'audio', 'hotkey', 'backlight'],
  148. platform: ['armani-kbl-15', 'astro-mlk-14-15', 'breckenridge-mlk-kbl', 'loki-kblr', 'steamboat-mlk', 'turis-mlk-glk', 'vegas-mlk-glk'],
  149. hwe: ['hwe-audio', 'hwe-bluetooth', 'hwe-cert-risk', 'hwe-firmware', 'hwe-fwts-error', 'hwe-graphics', 'hwe-hotkeys', 'hwe-needs-public-bug', 'hwe-suspend-resume'],
  150. ihv: ['ihv-amd', 'ihv-intel', 'ihv-nvidia', 'ihv-realtek', 'ihv-related'],
  151. status: ['task', 'staging', 'waiting', 'cqa-verified']
  152. };
  153. var tagDiv = document.createElement('div');
  154. tagDiv.id = 'wrap';
  155. var ulLevel1 = document.createElement('ul');
  156. ulLevel1.className = 'navbar';
  157. tagDiv.appendChild(ulLevel1);
  158.  
  159. Object.keys(allTags).forEach(function(key, index) {
  160. var liCategory = document.createElement('li');
  161. ulLevel1.appendChild(liCategory);
  162. liCategory.innerHTML = liCategory.innerHTML + key + ' →';
  163.  
  164. var ulLevel2 = document.createElement('ul');
  165. for (var i = 0; i < allTags[key].length; i++) {
  166. var liItem = document.createElement('li');
  167. ulLevel2.appendChild(liItem);
  168. liItem.innerHTML = liItem.innerHTML + allTags[key][i];
  169. liItem.id = 'taglist.' + allTags[key][i];
  170. (function(value){
  171. liItem.addEventListener("click", function() {
  172. toggleTagValue(value);
  173. }, false);})(allTags[key][i]);
  174. }
  175. liCategory.appendChild(ulLevel2);
  176. });
  177. document.getElementById('filebug-form').elements['field.tags'].size = '40';
  178.  
  179. var targetNode = document.getElementById('filebug-form').elements['field.tags'].parentNode.parentNode.parentNode;
  180. insertAfter(tagDiv, targetNode);
  181. addTagStyle();
  182. }
  183.  
  184. (function() {
  185. 'use strict';
  186.  
  187. //debugger;
  188. tagList();
  189. interceptorSetup();
  190. })();