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-02-07 提交的版本,查看 最新版本

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