Greasy Fork 还支持 简体中文。

Remove Social Media for gist.github.com

This userscript removes the "x followers", "y following" and "Set Status" fields on your own gist.github.com profile page. This is just visual.

目前為 2025-05-09 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Remove Social Media for gist.github.com
  3. // @description This userscript removes the "x followers", "y following" and "Set Status" fields on your own gist.github.com profile page. This is just visual.
  4. // @author ths197
  5. // @license BSD-3-Clause
  6. // @namespace https://gist.github.com/ths197
  7. // @include https://gist.github.com
  8. // @include https://gist.github.com/*
  9. // @noframes
  10. // @run-at document-start
  11. // @version 0.0.1.20250509081738
  12. // ==/UserScript==
  13.  
  14. "use strict";
  15.  
  16. // conditions
  17.  
  18. const isOnLoginUsersHomePage = function () {
  19. const user_login_name = document.querySelector(
  20. "meta[name='user-login']"
  21. ).content;
  22. const page_user_name = window.location.pathname.split("/")[1];
  23. return user_login_name === page_user_name;
  24. };
  25.  
  26. var state = undefined;
  27.  
  28. const isDocumentChanged = () => !state?.isConnected;
  29.  
  30. // getting and removing
  31.  
  32. const getControlElement = () => document.getElementById("gist-pjax-container"); // div, gets replaced on navigation by the webapp
  33.  
  34. const getSidebar = () =>
  35. document.getElementsByClassName("js-profile-editable-replace")[0]; // div
  36.  
  37. const socialMediaUrlOptions = ["followers", "following"];
  38.  
  39. const removeSocialMediaButtons = function (node) {
  40. const links = Array.from(node.getElementsByTagName("a"));
  41. const anySocialMediaLink = links.find((node) =>
  42. socialMediaUrlOptions.some((option) =>
  43. new URLSearchParams(new URL(node.href).search).has("tab", option)
  44. )
  45. );
  46. anySocialMediaLink?.parentElement.remove();
  47. Array.from(node.getElementsByClassName("user-status-container")).forEach(
  48. (statusContainer) => statusContainer.remove()
  49. );
  50. };
  51.  
  52. // applying
  53.  
  54. const applyChanges = function () {
  55. if (isOnLoginUsersHomePage() && isDocumentChanged()) {
  56. state = getControlElement();
  57. if (state != null) {
  58. const sidebar = getSidebar(); // js-profile-editable-replace is in the subtree of div#gist-pjax-container
  59. if (sidebar != null) {
  60. removeSocialMediaButtons(sidebar);
  61. }
  62. }
  63. }
  64. };
  65.  
  66. // setting stuff up (boring)
  67.  
  68. const mutationObserver = new MutationObserver(() => applyChanges());
  69.  
  70. const attachMutationObserver = () =>
  71. mutationObserver.observe(document.body, { subtree: false, childList: true });
  72.  
  73. const init = function () {
  74. applyChanges();
  75. attachMutationObserver();
  76. };
  77.  
  78. if (document.readyState === "loading") {
  79. document.addEventListener("DOMContentLoaded", init);
  80. } else {
  81. init();
  82. }