GitHub Distractionless

Userscript that makes sure that GitHub stays a work tool and doesn't turn into a social media website

  1. // ==UserScript==
  2. // @name GitHub Distractionless
  3. // @namespace Violentmonkey Scripts
  4. // @match https://github.com/*
  5. // @grant none
  6. // @version 0.1.1
  7. // @author turtlebasket
  8. // @website https://github.com/turtlebasket/userscripts/tree/master/github-distractionless
  9. // @license MIT
  10. // @description Userscript that makes sure that GitHub stays a work tool and doesn't turn into a social media website
  11. // @run-at document-end
  12. // ==/UserScript==
  13.  
  14. let hideEls = [];
  15. let focusing = false;
  16.  
  17. // title bar links - custom behavior for now
  18. const titleBarExclude = ["Explore", "Marketplace", "Codespaces"];
  19. let titleBarEls = document.getElementsByClassName("js-selected-navigation-item")
  20. for (let i = 0; i < titleBarEls.length; i++) {
  21. let el = titleBarEls[i];
  22. if (titleBarExclude.includes(el.innerHTML.trim())) {
  23. hideEls.push(el);
  24. }
  25. }
  26.  
  27. // general exclusion list
  28.  
  29. [
  30. ["mail-status unread", [0], /.*/],
  31. ["UnderlineNav-item", [1], /^\/$/],
  32. ]
  33. .forEach(([className, hideIndices, pageRegex]) => {
  34. hideIndices.forEach(i => {
  35. let el = document.getElementsByClassName(className)[i];
  36. if (typeof el === 'undefined') {
  37. console.log(`focus mode: unable to find element ${className} [ ${i} ]`)
  38. }
  39. else {
  40. hideEls.push(el);
  41. }
  42. });
  43. })
  44.  
  45. // hide all els in els
  46. function toggleFocus() {
  47. focusing = !focusing;
  48. for (let el of hideEls) {
  49. el.setAttribute(
  50. "style",
  51. focusing ? "display: none;" : "display: auto;");
  52. }
  53. }
  54.  
  55. // initial state
  56. toggleFocus();
  57.  
  58. // toggle switch coming later, currently bugged due to github content policy

QingJ © 2025

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