GitHub Issue Highlighter

A userscript that highlights the linked-to comment

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址