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

当前为 2018-05-20 提交的版本,查看 最新版本

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