GitHub Issue Highlighter

A userscript that highlights the linked-to comment

目前為 2017-05-16 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name GitHub Issue Highlighter
  3. // @version 1.0.4
  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. function init(event) {
  30. if (document.querySelector("#discussion_bucket")) {
  31. let target, indx,
  32. hash = window.location.hash;
  33. // remove "selected" class on hashchange
  34. if (event) {
  35. target = document.querySelectorAll(".timeline-comment");
  36. indx = target.length;
  37. while (indx--) {
  38. target[indx].classList.remove("selected");
  39. }
  40. }
  41. // add "selected" class
  42. if (/^#issue(comment)?-\d+/.test(hash)) {
  43. target = document.querySelector(hash);
  44. if (target) {
  45. target.classList.add("selected");
  46. }
  47. }
  48. }
  49. }
  50.  
  51. window.addEventListener("hashchange", init);
  52. init();
  53.  
  54. })();