GitHub Issue Highlighter

A userscript that highlights the linked-to comment

Fra 25.03.2017. Se den seneste versjonen.

  1. // ==UserScript==
  2. // @name GitHub Issue Highlighter
  3. // @version 1.0.3
  4. // @description A userscript that highlights the linked-to comment
  5. // @license https://creativecommons.org/licenses/by-sa/4.0/
  6. // @namespace https://github.com/Mottie
  7. // @include https://github.com/*
  8. // @run-at document-idle
  9. // @grant GM_addStyle
  10. // @author Rob Garrison
  11. // ==/UserScript==
  12. (() => {
  13. "use strict";
  14.  
  15. // !important needed to override styles added by
  16. // https://github.com/StylishThemes/GitHub-Dark
  17. GM_addStyle(`
  18. .timeline-comment.selected,
  19. .timeline-comment.current-user.selected {
  20. border-color: #4183C4 !important;
  21. }
  22. .timeline-comment.selected:before,
  23. .timeline-comment.current-user.selected:before {
  24. border-right-color: #4183C4 !important;
  25. }
  26. `);
  27.  
  28. function init(event) {
  29. if (document.querySelector("#discussion_bucket")) {
  30. let target, indx,
  31. hash = window.location.hash;
  32. // remove "selected" class on hashchange
  33. if (event) {
  34. target = document.querySelectorAll(".timeline-comment");
  35. indx = target.length;
  36. while (indx--) {
  37. target[indx].classList.remove("selected");
  38. }
  39. }
  40. // add "selected" class
  41. if (/^#issue(comment)?-\d+/.test(hash)) {
  42. target = document.querySelector(hash);
  43. if (target) {
  44. target.classList.add("selected");
  45. }
  46. }
  47. }
  48. }
  49.  
  50. window.addEventListener("hashchange", init);
  51. init();
  52.  
  53. })();