Show local time in Launchpad bug history

Appends local time after GMT timestamps on Launchpad bug history page

  1. // ==UserScript==
  2. // @name Show local time in Launchpad bug history
  3. // @namespace http://anthonywong.net/
  4. // @version 1.0
  5. // @description Appends local time after GMT timestamps on Launchpad bug history page
  6. // @match https://bugs.launchpad.net/*/+bug/*/+activity
  7. // @grant none
  8. // @author Anthony Wong <yp@anthonywong.net>
  9. // @license GPLv2
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function convertToLocalTime(gmtTime) {
  16. // Parse the GMT time string into a Date object
  17. const date = new Date(gmtTime + ' GMT+0');
  18. if (isNaN(date.getTime())) {
  19. return ''; // Return empty if date parsing fails
  20. }
  21.  
  22. // Format to local date and time
  23. return date.toLocaleString();
  24. }
  25.  
  26. // Loop through each row in the table
  27. document.querySelectorAll('table.listing tbody tr').forEach(row => {
  28. const timestampCell = row.cells[0]; // First column (Timestamp)
  29.  
  30. if (timestampCell) {
  31. const gmtTime = timestampCell.innerText.trim();
  32. const localTime = convertToLocalTime(gmtTime);
  33.  
  34. if (localTime) {
  35. // Append the local time in parentheses
  36. timestampCell.innerText += ` (local time: ${localTime})`;
  37. }
  38. }
  39. });
  40. })();