Remove Private Profile Notice for github.com

This userscript removes the "Only you can see your full profile [...]" infobox on your Github profile page.

  1. // ==UserScript==
  2. // @name Remove Private Profile Notice for github.com
  3. // @description This userscript removes the "Only you can see your full profile [...]" infobox on your Github profile page.
  4. // @author ths197
  5. // @license BSD-3-Clause
  6. // @namespace https://gist.github.com/ths197
  7. // @include https://github.com
  8. // @include https://github.com/*
  9. // @noframes
  10. // @run-at document-start
  11. // @version 0.0.1.20250509081337
  12. // ==/UserScript==
  13.  
  14. "use strict";
  15.  
  16. // conditions
  17.  
  18. const isOnLoginUsersHomePage = () => document.body.classList.contains("mine");
  19.  
  20. var state = undefined;
  21.  
  22. const isChanged = () => !state?.isConnected;
  23.  
  24. // getting and removing
  25.  
  26. const getUserProfileFrame = () => document.getElementById("user-profile-frame"); //contents do change on some navigations
  27.  
  28. const findAndRemoveNotice = function (node) {
  29. const links = Array.from(node.getElementsByTagName("a"));
  30. const anyPreviewLink = links.find(function (node) {
  31. const url = new URL(node.href);
  32. return (
  33. url.pathname === window.location.pathname &&
  34. new URLSearchParams(url.search).has("preview", "true")
  35. );
  36. });
  37. anyPreviewLink?.parentElement.parentElement.remove();
  38. };
  39.  
  40. const getControlElement = (userProfileFrame) => userProfileFrame.childNodes[1]; // div, gets replaced on navigation by the webapp
  41.  
  42. // applying
  43.  
  44. const applyChanges = function () {
  45. if (isOnLoginUsersHomePage()) {
  46. const userProfileFrame = getUserProfileFrame();
  47. if (userProfileFrame != null) {
  48. state = getControlElement(userProfileFrame);
  49. if (state != null) {
  50. findAndRemoveNotice(state);
  51. }
  52. }
  53. }
  54. };
  55.  
  56. // setting stuff up (boring)
  57.  
  58. const innerObserver = new MutationObserver(function () {
  59. if (isChanged()) {
  60. applyChanges();
  61. }
  62. });
  63.  
  64. const outerObserver = new MutationObserver(function () {
  65. if (isChanged()) {
  66. applyChanges();
  67. attachInnerObserver();
  68. }
  69. });
  70.  
  71. const attachInnerObserver = function () {
  72. const userProfileFrame = getUserProfileFrame();
  73. if (userProfileFrame != null) {
  74. innerObserver.observe(userProfileFrame, {
  75. subtree: false,
  76. childList: true,
  77. });
  78. }
  79. };
  80.  
  81. const attachOuterObserver = () =>
  82. outerObserver.observe(document.body, { subtree: false, childList: true });
  83.  
  84. const init = function () {
  85. applyChanges();
  86. attachOuterObserver();
  87. attachInnerObserver();
  88. };
  89.  
  90. if (document.readyState === "loading") {
  91. document.addEventListener("DOMContentLoaded", init);
  92. } else {
  93. init();
  94. }