GitHub Issue Highlighter

A userscript that highlights the linked-to comment

当前为 2017-06-12 提交的版本,查看 最新版本

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