Guest User

ChatGPT/Claude Privacy Tampermonkey Script

a guest
Aug 21st, 2025
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.69 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Claude & ChatGPT Sidebar Privacy Toggle
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Add privacy controls to blur chat names in Claude and ChatGPT sidebars
  6. // @author Will Ness (https://x.com/N3sOnline, https://willness.dev)
  7. // @match https://claude.ai/*
  8. // @match https://chatgpt.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // CSS styles for the privacy toggle and blur effects
  16. const styles = `
  17. /* Hide Claude sidebar initially to prevent flash of unblurred content */
  18. .flex.flex-col.align-center.h-full.overflow-hidden {
  19. visibility: hidden;
  20. }
  21.  
  22. /* Hide ChatGPT sidebar initially */
  23. #history {
  24. visibility: hidden;
  25. }
  26.  
  27. /* Show sidebars once privacy is applied */
  28. .flex.flex-col.align-center.h-full.overflow-hidden.privacy-ready,
  29. #history.privacy-ready {
  30. visibility: visible;
  31. }
  32.  
  33. .privacy-toggle-container {
  34. padding: 8px 16px;
  35. border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  36. margin-bottom: 8px;
  37. }
  38.  
  39. .privacy-toggle {
  40. display: flex;
  41. align-items: center;
  42. gap: 8px;
  43. font-size: 12px;
  44. color: rgb(var(--text-300));
  45. }
  46.  
  47. .privacy-switch {
  48. position: relative;
  49. display: inline-block;
  50. width: 40px;
  51. height: 20px;
  52. }
  53.  
  54. .privacy-switch input {
  55. opacity: 0;
  56. width: 0;
  57. height: 0;
  58. }
  59.  
  60. .privacy-slider {
  61. position: absolute;
  62. cursor: pointer;
  63. top: 0;
  64. left: 0;
  65. right: 0;
  66. bottom: 0;
  67. background-color: #ccc;
  68. border-radius: 20px;
  69. transition: .4s;
  70. }
  71.  
  72. .privacy-slider:before {
  73. position: absolute;
  74. content: "";
  75. height: 16px;
  76. width: 16px;
  77. left: 2px;
  78. bottom: 2px;
  79. background-color: white;
  80. border-radius: 50%;
  81. transition: .4s;
  82. }
  83.  
  84. input:checked + .privacy-slider {
  85. background-color: #2196F3;
  86. }
  87.  
  88. input:checked + .privacy-slider:before {
  89. transform: translateX(20px);
  90. }
  91.  
  92. .chat-name-blur {
  93. position: absolute;
  94. top: 0;
  95. left: 0;
  96. right: 0;
  97. bottom: 0;
  98. background: rgba(128, 128, 128, 0.3);
  99. backdrop-filter: blur(4px);
  100. border-radius: inherit;
  101. pointer-events: none;
  102. z-index: 10;
  103. }
  104.  
  105. .chat-item-container {
  106. position: relative;
  107. }
  108. `;
  109.  
  110. // Add styles to the page
  111. function addStyles() {
  112. const styleSheet = document.createElement('style');
  113. styleSheet.textContent = styles;
  114. document.head.appendChild(styleSheet);
  115. }
  116.  
  117. // Create the privacy toggle UI
  118. function createPrivacyToggle() {
  119. const toggleContainer = document.createElement('div');
  120. toggleContainer.className = 'privacy-toggle-container';
  121.  
  122. toggleContainer.innerHTML = `
  123. <div class="privacy-toggle">
  124. <span>Privacy Mode</span>
  125. <label class="privacy-switch">
  126. <input type="checkbox" id="privacy-toggle-input" checked>
  127. <span class="privacy-slider"></span>
  128. </label>
  129. </div>
  130. `;
  131.  
  132. return toggleContainer;
  133. }
  134.  
  135. // Detect which platform we're on
  136. function getPlatform() {
  137. return window.location.hostname.includes('claude.ai') ? 'claude' : 'chatgpt';
  138. }
  139.  
  140. // Apply blur overlay to chat names
  141. function applyBlurToChatNames(shouldBlur) {
  142. const platform = getPlatform();
  143.  
  144. // First, completely remove all existing blur overlays and reset classes
  145. document.querySelectorAll('.chat-name-blur').forEach(el => el.remove());
  146. document.querySelectorAll('.chat-item-container').forEach(el => {
  147. el.classList.remove('chat-item-container');
  148. });
  149.  
  150. if (!shouldBlur) return;
  151.  
  152. if (platform === 'claude') {
  153. // Claude-specific logic
  154. const chatLinks = document.querySelectorAll('a[href^="/chat/"], a[href^="/project/"]');
  155.  
  156. chatLinks.forEach(linkEl => {
  157. const chatNameSpan = linkEl.querySelector('span.truncate.text-sm.whitespace-nowrap.w-full');
  158. if (!chatNameSpan) return;
  159.  
  160. // Skip user account info
  161. if (chatNameSpan.textContent.includes('n3s') || chatNameSpan.textContent.includes('Pro plan')) {
  162. return;
  163. }
  164.  
  165. linkEl.classList.add('chat-item-container');
  166.  
  167. const blurOverlay = document.createElement('div');
  168. blurOverlay.className = 'chat-name-blur';
  169. linkEl.appendChild(blurOverlay);
  170. });
  171. } else if (platform === 'chatgpt') {
  172. // ChatGPT-specific logic
  173. const chatLinks = document.querySelectorAll('a[href^="/c/"]');
  174.  
  175. chatLinks.forEach(linkEl => {
  176. const chatNameSpan = linkEl.querySelector('span[dir="auto"]');
  177. if (!chatNameSpan) return;
  178.  
  179. linkEl.classList.add('chat-item-container');
  180.  
  181. const blurOverlay = document.createElement('div');
  182. blurOverlay.className = 'chat-name-blur';
  183. linkEl.appendChild(blurOverlay);
  184. });
  185. }
  186. }
  187.  
  188. // Initialize the privacy toggle
  189. function initPrivacyToggle() {
  190. const platform = getPlatform();
  191.  
  192. // Apply early blur if privacy should be enabled by default
  193. const savedPreference = localStorage.getItem('claude-privacy-mode');
  194. const shouldEnablePrivacy = savedPreference !== null ? savedPreference === 'true' : true;
  195.  
  196. if (shouldEnablePrivacy) {
  197. // Apply blur immediately to any chat links that already exist
  198. applyBlurToChatNames(true);
  199. }
  200.  
  201. let sidebar, insertionPoint;
  202.  
  203. if (platform === 'claude') {
  204. // Claude-specific selectors
  205. sidebar = document.querySelector('.flex.flex-col.align-center.h-full.overflow-hidden');
  206. if (!sidebar) {
  207. console.log('Claude sidebar not found, retrying...');
  208. setTimeout(initPrivacyToggle, 500);
  209. return;
  210. }
  211. insertionPoint = sidebar.querySelector('.flex.flex-col.px-2.pt-1.gap-px.mb-6');
  212. } else if (platform === 'chatgpt') {
  213. // ChatGPT-specific selectors
  214. sidebar = document.querySelector('#history');
  215. if (!sidebar) {
  216. console.log('ChatGPT sidebar not found, retrying...');
  217. setTimeout(initPrivacyToggle, 500);
  218. return;
  219. }
  220. // For ChatGPT, insert at the beginning of the history div
  221. insertionPoint = sidebar.firstElementChild;
  222. }
  223.  
  224. // Check if toggle already exists
  225. if (document.querySelector('.privacy-toggle-container')) {
  226. return;
  227. }
  228.  
  229. if (!insertionPoint && platform === 'claude') {
  230. console.log('Claude insertion point not found, retrying...');
  231. setTimeout(initPrivacyToggle, 500);
  232. return;
  233. }
  234.  
  235. // Create and insert the privacy toggle
  236. const privacyToggle = createPrivacyToggle();
  237.  
  238. if (platform === 'claude') {
  239. insertionPoint.parentNode.insertBefore(privacyToggle, insertionPoint.nextSibling);
  240. } else if (platform === 'chatgpt') {
  241. sidebar.insertBefore(privacyToggle, insertionPoint);
  242. }
  243.  
  244. // Add event listener for toggle
  245. const toggleInput = document.getElementById('privacy-toggle-input');
  246. if (toggleInput) {
  247. toggleInput.addEventListener('change', function() {
  248. // Set flag to prevent observer interference
  249. window.privacyToggling = true;
  250.  
  251. applyBlurToChatNames(this.checked);
  252.  
  253. // Store preference in localStorage
  254. localStorage.setItem('claude-privacy-mode', this.checked);
  255.  
  256. // Clear flag after a delay
  257. setTimeout(() => {
  258. window.privacyToggling = false;
  259. }, 500);
  260. });
  261.  
  262. // Load saved preference or default to true (privacy on)
  263. const savedPreference = localStorage.getItem('claude-privacy-mode');
  264. const defaultPrivacyMode = savedPreference !== null ? savedPreference === 'true' : true;
  265. toggleInput.checked = defaultPrivacyMode;
  266.  
  267. // Apply initial blur state immediately
  268. applyBlurToChatNames(defaultPrivacyMode);
  269.  
  270. // Show the sidebar now that privacy controls are applied
  271. sidebar.classList.add('privacy-ready');
  272. }
  273. }
  274.  
  275. // Observer to handle dynamic content changes
  276. function setupObserver() {
  277. const platform = getPlatform();
  278.  
  279. const observer = new MutationObserver(function(mutations) {
  280. mutations.forEach(function(mutation) {
  281. if (mutation.type === 'childList') {
  282. // Only re-apply blur when new chat items are added AND we're not currently toggling
  283. const toggleInput = document.getElementById('privacy-toggle-input');
  284. if (toggleInput && toggleInput.checked && !window.privacyToggling) {
  285. // Check if new chat links were actually added
  286. const addedChatLinks = Array.from(mutation.addedNodes).some(node => {
  287. if (node.nodeType === Node.ELEMENT_NODE) {
  288. if (platform === 'claude') {
  289. return node.querySelector && node.querySelector('a[href^="/chat/"], a[href^="/project/"]');
  290. } else if (platform === 'chatgpt') {
  291. return node.querySelector && node.querySelector('a[href^="/c/"]');
  292. }
  293. }
  294. return false;
  295. });
  296.  
  297. if (addedChatLinks) {
  298. setTimeout(() => applyBlurToChatNames(true), 100);
  299. }
  300. }
  301. }
  302. });
  303. });
  304.  
  305. // Observe changes in the appropriate container
  306. let chatContainer;
  307. if (platform === 'claude') {
  308. chatContainer = document.querySelector('.flex.flex-grow.flex-col.overflow-y-auto');
  309. } else if (platform === 'chatgpt') {
  310. chatContainer = document.querySelector('#history');
  311. }
  312.  
  313. if (chatContainer) {
  314. observer.observe(chatContainer, { childList: true, subtree: true });
  315. }
  316. }
  317.  
  318. // Initialize when page loads
  319. function init() {
  320. addStyles();
  321.  
  322. // Wait for the page to load
  323. if (document.readyState === 'loading') {
  324. document.addEventListener('DOMContentLoaded', function() {
  325. setTimeout(initPrivacyToggle, 1000);
  326. setTimeout(setupObserver, 2000);
  327. });
  328. } else {
  329. setTimeout(initPrivacyToggle, 1000);
  330. setTimeout(setupObserver, 2000);
  331. }
  332. }
  333.  
  334. // Start the script
  335. init();
  336.  
  337. })();
Advertisement
Add Comment
Please, Sign In to add comment