GitHub Issue Highlighter

A userscript that highlights the linked-to comment

当前为 2016-05-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GitHub Issue Highlighter
  3. // @version 1.0.0
  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 */
  14. (function() {
  15. "use strict";
  16.  
  17. GM_addStyle([
  18. // !important needed to override styles added by
  19. // https://github.com/StylishThemes/GitHub-Dark
  20. ".timeline-comment.selected { border-color: #4183C4 !important; }",
  21. ".timeline-comment.selected:before { border-right-color: #4183C4 !important; }"
  22. ].join(""));
  23.  
  24. var init = function(event) {
  25. if (document.querySelector("#discussion_bucket")) {
  26. var target, indx,
  27. hash = window.location.hash;
  28. // remove "selected" class on hashchange
  29. if (event) {
  30. target = document.querySelectorAll(".timeline-comment");
  31. indx = target.length;
  32. while (indx--) {
  33. target[indx].classList.remove("selected");
  34. }
  35. }
  36. // add "selected" class
  37. if (/^#issue(comment)?-\d+/.test(hash)) {
  38. target = document.querySelector(hash);
  39. if (target) {
  40. target.classList.add("selected");
  41. }
  42. }
  43. }
  44. };
  45.  
  46. window.addEventListener("hashchange", init);
  47. init();
  48.  
  49. })();