GitHub Issue Highlighter

A userscript that highlights the linked-to comment

目前為 2023-07-01 提交的版本,檢視 最新版本

  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. "use strict";
  18.  
  19. // !important needed to override styles added by
  20. // https://github.com/StylishThemes/GitHub-Dark
  21. GM.addStyle(`
  22. .timeline-comment.selected,
  23. .timeline-comment.current-user.selected {
  24. border-color: #4183C4 !important;
  25. }
  26. .timeline-comment.selected .comment:before,
  27. .timeline-comment.current-user.selected:before {
  28. border-right-color: #4183C4 !important;
  29. }
  30. `);
  31.  
  32. const regex = /^#issue(comment)?-\d+/;
  33.  
  34. function init(event) {
  35. if (document.querySelector("#discussion_bucket")) {
  36. let target, indx,
  37. hash = window.location.hash;
  38. // remove "selected" class on hashchange
  39. if (event) {
  40. target = document.querySelectorAll(".timeline-comment");
  41. indx = target.length;
  42. while (indx--) {
  43. target[indx].classList.remove("selected");
  44. }
  45. }
  46. // add "selected" class
  47. if (regex.test(hash)) {
  48. target = document.querySelector(hash.match(regex)[0]);
  49. if (target) {
  50. target.querySelector(".timeline-comment").classList.add("selected");
  51. }
  52. }
  53. }
  54. }
  55.  
  56. window.addEventListener("hashchange", init);
  57. document.addEventListener("pjax:end", init);
  58. init();
  59.  
  60. })();