Firefox for desktop - list modified bugs in Mercurial as sortable table

It generates a sortable table list of bugs related to Firefox for desktop for which patches have landed in Mozilla Mercurial pushlogs

目前為 2017-11-12 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Firefox for desktop - list modified bugs in Mercurial as sortable table
  3. // @namespace darkred
  4. // @authors darkred, johnp
  5. // @license MIT
  6. // @description It generates a sortable table list of bugs related to Firefox for desktop for which patches have landed in Mozilla Mercurial pushlogs
  7. // @version 5.5.4
  8. // @date 2017.3.25
  9. // @include /^https?:\/\/hg\.mozilla\.org.*pushloghtml.*/
  10. // @grant GM_addStyle
  11. // @grant GM_getResourceText
  12. // @require https://code.jquery.com/jquery-2.1.4.min.js
  13. // @require https://code.jquery.com/ui/1.11.4/jquery-ui.min.js
  14. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.24.3/js/jquery.tablesorter.min.js
  15. // @require https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment-with-locales.min.js
  16. // @require https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.4.1/moment-timezone-with-data.min.js
  17. // @require https://cdnjs.cloudflare.com/ajax/libs/jstimezonedetect/1.0.6/jstz.min.js
  18. // @require https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js
  19. // @require https://cdnjs.cloudflare.com/ajax/libs/keypress/2.1.3/keypress.min.js
  20. // @resource customCSS http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.min.css
  21. // ==/UserScript==
  22.  
  23.  
  24.  
  25.  
  26. // CSS rules in order to show 'up' and 'down' arrows in each table header
  27. var stylesheet = ' \
  28. <style> \
  29. thead th { \
  30. background-repeat: no-repeat; \
  31. background-position: right center; \
  32. } \
  33. thead th.up { \
  34. padding-right: 20px; \
  35. background-image: url(data:image/gif;base64,R0lGODlhFQAEAIAAACMtMP///yH5BAEAAAEALAAAAAAVAAQAAAINjI8Bya2wnINUMopZAQA7); \
  36. } \
  37. thead th.down { \
  38. padding-right: 20px; \
  39. background-image: url(data:image/gif;base64,R0lGODlhFQAEAIAAACMtMP///yH5BAEAAAEALAAAAAAVAAQAAAINjB+gC+jP2ptn0WskLQA7); \
  40. } \
  41. } \
  42. </style>';
  43.  
  44. $('head').append(stylesheet);
  45.  
  46.  
  47.  
  48. // in order to highlight hovered table row
  49. GM_addStyle('#tbl tr:hover{ background:#F6E6C6 !important;}');
  50.  
  51. // in order the table headers to be larger and bold
  52. GM_addStyle('#tbl th {text-align: -moz-center !important; font-size: larger; font-weight: bold; }');
  53.  
  54. // in order to remove unnecessairy space between rows
  55. GM_addStyle('#dialog > div > table > tbody {line-height: 14px;}');
  56.  
  57.  
  58. GM_addStyle('#tbl > thead > tr > th {border-bottom: solid 1px};}');
  59.  
  60.  
  61. GM_addStyle('#tbl td:nth-child(1) {text-align: -moz-right;}');
  62.  
  63. // in order the 'product/component' to be aligned to the right
  64. GM_addStyle('#tbl td:nth-child(2) {text-align: -moz-right;}');
  65.  
  66.  
  67.  
  68.  
  69. // in order the bug list to have width 1500px // it was 1500 and then 1600
  70. GM_addStyle('.ui-dialog {\
  71. width:1700px !important;\
  72. }');
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. var silent = false;
  81. var debug = false;
  82.  
  83. time('MozillaMercurial');
  84.  
  85. String.prototype.escapeHTML = function() {
  86. var tagsToReplace = {
  87. '&': '&amp;',
  88. '<': '&lt;',
  89. '>': '&gt;'
  90. };
  91. return this.replace(/[&<>]/g, function(tag) {
  92. return tagsToReplace[tag] || tag;
  93. });
  94. };
  95.  
  96. // theme for the jQuery dialog
  97. // $('head').append(
  98. // '<link ' +
  99. // 'href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.min.css" ' +
  100. // // 'href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.min.css" ' + // uncomment this line (and comment line 89) in order to change theme
  101. // 'rel="stylesheet" type="text/css">'
  102. // );
  103. var newCSS = GM_getResourceText ('customCSS');
  104. GM_addStyle (newCSS);
  105.  
  106.  
  107. var regex = /^https:\/\/bugzilla\.mozilla\.org\/show_bug\.cgi\?id=(.*)$/;
  108. var base_url = 'https://bugzilla.mozilla.org/rest/bug?include_fields=id,summary,status,resolution,product,component,op_sys,platform,whiteboard,last_change_time&id=';
  109. var bugIds = [];
  110. var bugsComplete = [];
  111.  
  112. var table = document.getElementsByTagName('table')[0];
  113. var links = table.getElementsByTagName('a');
  114. var len = links.length;
  115. for (let i = 0; i < len; i++) {
  116. let n = links[i].href.match(regex);
  117. if (n !== null && n.length > 0) {
  118. let id = parseInt(n[1]);
  119. if (bugIds.indexOf(id) === -1) {
  120. bugIds.push(id);
  121. }
  122. }
  123. }
  124.  
  125. var numBugs = bugIds.length;
  126. var counter = 0;
  127.  
  128. var rest_url = base_url + bugIds.join();
  129. time('MozillaMercurial-REST');
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. $.getJSON(rest_url, function(data) {
  138. timeEnd('MozillaMercurial-REST');
  139. $.each(data.bugs, function(index) {
  140. let bug = data.bugs[index];
  141. // process bug (let "shorthands" just to simplify things during refactoring)
  142. let status = bug.status;
  143. if (bug.resolution !== '') {status += ' ' + bug.resolution;}
  144. let product = bug.product;
  145. let component = bug.component;
  146. let platform = bug.platform;
  147. if (platform == 'Unspecified') {
  148. platform = 'Uns';
  149. }
  150. if (bug.op_sys !== '' && bug.op_sys !== 'Unspecified') {
  151. platform += '/' + bug.op_sys;
  152. }
  153. let whiteboard = bug.whiteboard === '' ? '[]' : bug.whiteboard;
  154. // todo: message???
  155.  
  156.  
  157.  
  158.  
  159.  
  160. // 2015-11-09T14:40:41Z
  161. function toRelativeTime(time, zone) {
  162. var format2 = ('YYYY-MM-DD HH:mm:ss Z');
  163. return moment(time, format2).tz(zone).fromNow();
  164. }
  165.  
  166.  
  167. function getLocalTimezone(){
  168. var tz = jstz.determine(); // Determines the time zone of the browser client
  169. return tz.name(); // Returns the name of the time zone eg "Europe/Berlin"
  170. }
  171.  
  172.  
  173.  
  174.  
  175. var changetime;
  176. var localTimezone = getLocalTimezone();
  177.  
  178. if (bug.last_change_time !== '') {
  179. var temp = toRelativeTime(bug.last_change_time, localTimezone);
  180. if (temp.match(/(an?)\ .*/)) {
  181. changetime = temp.replace(/an?/, 1);
  182. } else {
  183. changetime = temp;
  184. }
  185. // changetime
  186. } else {
  187. changetime = '';
  188. }
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197. log('----------------------------------------------------------------------------------------------------------------------------------');
  198. log((index + 1) + '/' + numBugs); // Progression counter
  199. log('BugNo: ' + bug.id + '\nTitle: ' + bug.summary + '\nStatus: ' + status + '\nProduct: ' + product + '\nComponent: ' + component + '\nPlatform: ' + platform + '\nWhiteboard: ' + whiteboard);
  200.  
  201. if (isRelevant(bug)) {
  202. // add html code for this bug
  203. bugsComplete.push('<tr><td><a href="'
  204. + 'https://bugzilla.mozilla.org/show_bug.cgi?id='+ bug.id + '">'
  205. + bug.id
  206. + '</a></td>'
  207. + '<td nowrap>(' + product + ': ' + component + ') </td>'
  208. + '<td>'+bug.summary.escapeHTML() + ' [' + platform + ']' + whiteboard.escapeHTML() + '</td>'
  209. + '<td>' + changetime + '</td>'
  210. + '<td>' + status + '</td></tr>'); // previously had a <br> at the end;
  211. }
  212. counter++; // increase counter
  213. // remove processed bug from bugIds
  214. let i = bugIds.indexOf(bug.id);
  215. if (i !== -1) {bugIds[i] = null;}
  216. });
  217. log('==============\nReceived ' + counter + ' of ' + numBugs + ' bugs.');
  218.  
  219.  
  220.  
  221.  
  222. // process remaining bugs one-by-one
  223. var requests = [];
  224. time('MozillaMercurial-missing');
  225. $.each(bugIds, function(index) {
  226. let id = bugIds[index];
  227. if (id !== null) {
  228. time('Requesting missing bug ' + id);
  229. let promise = $.getJSON('https://bugzilla.mozilla.org/rest/bug/' + id,
  230. function(json) {
  231. // I've not end up here yet, so cry if we do
  232. console.error('Request succeeded unexpectedly!');
  233. console.error('Please submit this information to the script authors:');
  234. timeEnd('Requesting missing bug ' + id);
  235. console.log(json);
  236. let bug = json.bugs[0];
  237. console.log(bug);
  238. // TODO: display as much information as possible
  239. });
  240. // Actually, we usually get an error
  241. promise.error(function(req, status, error) {
  242. timeEnd('Requesting missing bug ' + id);
  243. if (error == 'Authorization Required') {
  244. // log("Bug " + id + " requires authorization!");
  245. log('https://bugzilla.mozilla.org/show_bug.cgi?id=' + id + ' requires authorization!');
  246. let text = ' requires authorization!<br>';
  247.  
  248. bugsComplete.push('<a href="'
  249. + 'https://bugzilla.mozilla.org/show_bug.cgi?id='+ id + '">#'
  250. + id + '</a>' + text);
  251. } else {
  252. console.error('Unexpected error encountered (Bug' + id + '): ' + status + ' ' + error);
  253. }
  254. });
  255. requests.push(promise);
  256. }
  257. });
  258. // wait for all requests to be settled, then join them together
  259. // Source: https://stackoverflow.com/questions/19177087/deferred-how-to-detect-when-every-promise-has-been-executed
  260. $.when.apply($, $.map(requests, function(p) {
  261. return p.then(null, function() {
  262. return $.Deferred().resolveWith(this, arguments);
  263. });
  264. })).always(function() {
  265. timeEnd('MozillaMercurial-missing');
  266. // Variable that will contain all values of the bugsComplete array, and will be displayed in the 'dialog' below
  267. var docu = '';
  268. docu = bugsComplete.join('');
  269. docu = ' <table id="tbl" style="width:100%">' +
  270. '<thead>' +
  271. '<tr><th>BugNo</th>' +
  272. '<th>Product/Component</th>' +
  273. '<th>Summary</th>' +
  274. '<th>Modified___</th>' +
  275. '<th>Status____________</th></tr>' +
  276. '</thead>' +
  277. '<tbody>' + docu + '</tbody></table>';
  278.  
  279.  
  280.  
  281.  
  282. var div = document.createElement('div');
  283. $('div.page_footer').append(div);
  284. div.id = 'dialog';
  285. docu = '<div id="dialog_content" title="Relevant Bugs">' + docu + '</div>';
  286. div.innerHTML = docu;
  287. $('#dialog').hide();
  288.  
  289. $(function() {
  290. $('#dialog').dialog({
  291. title: 'List of modified bugs of Firefox for desktop (' + bugsComplete.length + ')',
  292. width: '1350px'
  293. });
  294. });
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301. // THE CUSTOM PARSER MUST BE PUT BEFORE '$('#tbl').tablesorter ( {'' or else it wont work !!!!
  302. // add parser through the tablesorter addParser method (for the "Last modified" column)
  303. $.tablesorter.addParser({
  304. // set a unique id
  305. id: 'dates',
  306. is: function(s) {
  307. return false; // return false so this parser is not auto detected
  308. },
  309. format: function(s) {
  310. // format your data for normalization
  311. if (s !== ''){
  312. var number1, number2;
  313.  
  314. // format your data for normalization
  315. number1 = Number((/(.{1,2})\ .*/).exec(s)[1]);
  316.  
  317.  
  318. if (s.match(/A few seconds ago/)) { number2 = 0;}
  319. else if (s.match(/(.*)seconds?.*/)) { number2 = 1;}
  320. else if (s.match(/(.*)minutes?.*/)) {number2 = 60;}
  321. else if (s.match(/(.*)hours?.*/)) { number2 = 3600;}
  322. else if (s.match(/(.*)days?.*/)) { number2 = 86400;}
  323. else if (s.match(/(.*)months?.*/)) { number2 = 30 * 86400;}
  324. else if (s.match(/(.*)years?.*/)) {number2 = 365 * 30 * 86400;}
  325. return number1 * number2;
  326.  
  327. }
  328. },
  329. // set type, either numeric or text
  330. type: 'numeric'
  331. });
  332.  
  333.  
  334.  
  335. // make table sortable
  336. $('#tbl').tablesorter({
  337. cssAsc: 'up',
  338. cssDesc: 'down',
  339. sortList: [[3, 0],[1, 0],[2, 0]], // in order the table to be sorted by default by column 3 'Modified', then by column 1 'Product/Component' and then by column 2 'Summary'
  340. headers: {3: {sorter: 'dates'}},
  341. initialized: function() {
  342. var mytable = document.getElementById('tbl');
  343. for (var i = 2, j = mytable.rows.length + 1; i < j; i++) {
  344. if (mytable.rows[i].cells[3].innerHTML != mytable.rows[i - 1].cells[3].innerHTML) {
  345. for (var k = 0; k < 5; k++) {
  346. mytable.rows[i - 1].cells[k].style.borderBottom = '1px black dotted';
  347. }
  348. }
  349. }
  350. }
  351. });
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358. log('ALL IS DONE');
  359. timeEnd('MozillaMercurial');
  360.  
  361.  
  362.  
  363.  
  364.  
  365. });
  366.  
  367. });
  368.  
  369.  
  370. var flag = 1;
  371.  
  372. // bind keypress of ` so that when pressed, the separators between groups of the same timestamps to be removed, in order to sort manually
  373. var listener = new window.keypress.Listener();
  374. listener.simple_combo('`', function() {
  375. // console.log('You pressed `');
  376. if (flag === 1) {
  377. flag = 0;
  378. // remove seperators
  379. var mytable = document.getElementById('tbl');
  380. for (var i = 2, j = mytable.rows.length + 1; i < j; i++) {
  381. for (var k = 0; k < 5; k++) {
  382. mytable.rows[i - 1].cells[k].style.borderBottom = 'none';
  383. }
  384. }
  385. var sorting = [[1, 0], [2, 0]]; // sort by column 1 'Product/Component' and then by column 2 'Summary'
  386. $('#tbl').trigger('sorton', [sorting]);
  387. } else {
  388. if (flag === 0) {
  389. flag = 1;
  390. // console.log('You pressed ~');
  391. var sorting = [[3, 0], [1, 0], [2, 0]]; // sort by column 3 'Modified Date, then by '1 'Product/Component' and then by column 2 'Summary'
  392. $('#tbl').trigger('sorton', [sorting]);
  393. var mytable = document.getElementById('tbl');
  394. for (var i = 2, j = mytable.rows.length + 1; i < j; i++) {
  395. if (mytable.rows[i].cells[3].innerHTML != mytable.rows[i - 1].cells[3].innerHTML) {
  396. for (var k = 0; k < 5; k++) {
  397. mytable.rows[i - 1].cells[k].style.borderBottom = '1px black dotted';
  398. }
  399. }
  400. }
  401. }
  402. }
  403. });
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410. function isRelevant(bug) {
  411. if (!bug.id) {return false;}
  412. // if (bug.status && bug.status != 'RESOLVED' && bug.status != 'VERIFIED') {
  413. // log(' IRRELEVANT because of it\'s Status --> ' + bug.status);
  414. // return false;
  415. // }
  416. if (bug.component && bug.product && bug.component == 'Build Config' && (bug.product == 'Toolkit' || bug.product == 'Firefox')) {
  417. log(' IRRELEVANT because of it\'s Product --> ' + bug.product + 'having component --> ' + bug.component);
  418. return false;
  419. }
  420. if (bug.product && bug.product != 'Add-on SDK' &&
  421. bug.product != 'Cloud Services' &&
  422. bug.product != 'Core' &&
  423. bug.product != 'Firefox' &&
  424. bug.product != 'Hello (Loop)' &&
  425. bug.product != 'Toolkit') {
  426. log(' IRRELEVANT because of it\'s Product --> ' + bug.product);
  427. return false;
  428. }
  429. if (bug.component && bug.component == 'AutoConfig' ||
  430. bug.component == 'Build Config' ||
  431. bug.component == 'DMD' ||
  432. bug.component == 'Embedding: GRE Core' ||
  433. bug.component == 'Embedding: Mac' ||
  434. bug.component == 'Embedding: MFC Embed' ||
  435. bug.component == 'Embedding: Packaging' ||
  436. bug.component == 'Hardware Abstraction Layer' ||
  437. bug.component == 'mach' ||
  438. bug.component == 'Nanojit' ||
  439. bug.component == 'QuickLaunch' ||
  440. bug.component == 'Widget: Gonk') {
  441. log(' IRRELEVANT because of it\'s Component --> ' + bug.component);
  442. return false;
  443. }
  444.  
  445. log(' OK ' + 'https://bugzilla.mozilla.org/show_bug.cgi?id=' + bug.id);
  446. return true;
  447. }
  448.  
  449.  
  450.  
  451.  
  452. function log(str) {
  453. if (!silent) {
  454. console.log(str);
  455. }
  456. }
  457.  
  458. function time(str) {
  459. if (debug) {
  460. console.time(str);
  461. }
  462. }
  463.  
  464. function timeEnd(str) {
  465. if (debug) {
  466. console.timeEnd(str);
  467. }
  468. }
  469.  
  470. // $(function() {
  471. $('#dialog').dialog({
  472. modal: false,
  473. title: 'Draggable, sizeable dialog',
  474. position: {
  475. my: 'top',
  476. at: 'top',
  477. of: document,
  478. collision: 'none'
  479. },
  480. // width: 1500, // not working
  481. zIndex: 3666
  482. })
  483. .dialog('widget').draggable('option', 'containment', 'none');
  484.  
  485. //-- Fix crazy bug in FF! ...
  486. $('#dialog').parent().css({
  487. position: 'fixed',
  488. top: 0,
  489. left: '4em',
  490. width: '75ex'
  491. });