GitHub Issue Highlighter

A userscript that highlights the linked-to comment

当前为 2016-07-28 提交的版本,查看 最新版本

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