JanitorAI CSS Toggle

Toggles JanitorAI custom CSS

  1. // ==UserScript==
  2. // @name JanitorAI CSS Toggle
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.1
  5. // @description Toggles JanitorAI custom CSS
  6. // @author IWasTheSyntaxError
  7. // @match https://janitorai.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. let alreadyReloaded = true;
  16. let alreadyReloadedContrast = true;
  17. let isMenuVisible = false;
  18. let isCustomCssDisabled = localStorage.getItem('janitorAICustomCssDisabled') === 'true';
  19. let isHighTextContrast = localStorage.getItem('janitorAIHighContrast') === 'true';
  20.  
  21. let controlPanel = null;
  22. let controlsContainer = null;
  23.  
  24. const isAllowedPage = () => {
  25. const path = window.location.pathname;
  26. return path.startsWith('/characters') || path === '/my_characters' || path.startsWith('/profiles/');
  27. };
  28.  
  29. const isChatsPage = () => window.location.pathname.startsWith('/chats');
  30.  
  31. const toggleMenu = () => {
  32. isMenuVisible = !isMenuVisible;
  33. updateElementsVisibility();
  34. updateControlText();
  35. };
  36.  
  37. const toggleCustomCss = () => {
  38. isCustomCssDisabled = !isCustomCssDisabled;
  39. localStorage.setItem('janitorAICustomCssDisabled', isCustomCssDisabled);
  40. applyCustomCssToggle();
  41. updateControlText();
  42. };
  43.  
  44. const toggleCustomContrast = () => {
  45. isHighTextContrast = !isHighTextContrast;
  46. localStorage.setItem('janitorAIHighContrast', isHighTextContrast);
  47. applyHighContrastText();
  48. updateControlText();
  49. };
  50.  
  51. const applyHighContrastText = () => {
  52. if (isHighTextContrast){
  53. alreadyReloadedContrast = false;
  54. const elements = document.querySelectorAll('p, h1, h2, h3, h4, h5');
  55.  
  56. elements.forEach(element => {
  57. element.style.color = 'white';
  58. element.style.backgroundColor = 'black';
  59. });
  60.  
  61. const allElements = document.querySelectorAll('*');
  62.  
  63. allElements.forEach(element => {
  64. if (element.childNodes.length > 0) {
  65. element.childNodes.forEach(node => {
  66. if (node.nodeType === Node.TEXT_NODE && node.nodeValue.trim() !== "") {
  67. node.parentNode.style.color = 'white';
  68. node.parentNode.style.backgroundColor = 'black';
  69. }
  70. });
  71. }
  72. });
  73. } else {
  74. if(!alreadyReloadedContrast){
  75. location.reload();
  76. alreadyReloadedContrast = true;
  77. }
  78. }
  79. }
  80.  
  81. const applyCustomCssToggle = () => {
  82. if (isCustomCssDisabled) {
  83. alreadyReloaded = false;
  84. removeCustomStyles();
  85. const parentElement = document.querySelector('.css-1bn1yyx');
  86. if(parentElement){
  87. const childElements = parentElement.querySelectorAll('*');
  88. for (let i = 0; i < childElements.length; i++) {
  89. if (childElements[i].nodeName === "STYLE") {
  90. childElements[i].parentNode.removeChild(childElements[i]);
  91. }
  92. }
  93. const background = document.querySelector(".css-14l6kwv").firstChild;background.style.background = "none";
  94. }const char = document.querySelector(".css-fu9q4m");
  95. if(!char){
  96. const main = document.querySelector(".css-lo240v");
  97. const elementsWithStyle = main.querySelectorAll('[style]');elementsWithStyle.forEach(element => {
  98. element.removeAttribute('style');
  99. });
  100. } else {
  101. const elementsWithStyle = char.querySelectorAll('[style]');elementsWithStyle.forEach(element => {
  102. element.removeAttribute('style');
  103. });
  104. };
  105. } else {
  106. if(!alreadyReloaded){
  107. location.reload();
  108. alreadyReloaded = true;
  109. }
  110. }
  111. };
  112.  
  113. const removeCustomStyles = () => {
  114. const styles = document.querySelectorAll('body style');
  115. styles.forEach(style => style.remove());
  116. };
  117.  
  118. const updateControlText = () => {
  119. const cssToggleText = document.getElementById('css-toggle-text');
  120. const cssToggleContrast = document.getElementById('css-toggle-contrast');
  121. if (cssToggleText) {
  122. cssToggleText.textContent = `Custom CSS: ${isCustomCssDisabled ? 'OFF' : 'ON'}`;
  123. cssToggleText.style.color = isCustomCssDisabled ? '#ccc' : '#fff';
  124. }
  125. if (cssToggleContrast) {
  126. cssToggleContrast.textContent = `High Contrast Text: ${isHighTextContrast ? 'ON' : 'OFF'}`;
  127. cssToggleContrast.style.color = isHighTextContrast ? '#fff' : '#ccc';
  128. }
  129. };
  130.  
  131. const createControlPanel = () => {
  132. if (controlPanel) return;
  133.  
  134. controlPanel = document.createElement('div');
  135. controlPanel.id = 'janitor-control-panel';
  136. Object.assign(controlPanel.style, {
  137. position: 'fixed',
  138. top: '75px',
  139. left: '10px',
  140. zIndex: '100000',
  141. display: 'flex',
  142. flexDirection: 'column',
  143. gap: '5px',
  144. alignItems: 'flex-start'
  145. });
  146.  
  147. const settingsButton = document.createElement('button');
  148. settingsButton.id = 'token-filter-toggle';
  149. settingsButton.textContent = '⚙️';
  150. Object.assign(settingsButton.style, {
  151. width: '30px',
  152. height: '30px',
  153. padding: '0',
  154. backgroundColor: 'rgba(74, 74, 74, 0.7)',
  155. color: '#fff',
  156. border: 'none',
  157. borderRadius: '5px',
  158. cursor: 'pointer',
  159. display: 'flex',
  160. alignItems: 'center',
  161. justifyContent: 'center',
  162. fontSize: '16px',
  163. transition: 'background-color 0.2s'
  164. });
  165. settingsButton.addEventListener('click', toggleMenu);
  166.  
  167. controlsContainer = document.createElement('div');
  168. controlsContainer.id = 'controls-container';
  169. Object.assign(controlsContainer.style, {
  170. display: 'none',
  171. flexDirection: 'column',
  172. gap: '5px',
  173. backgroundColor: 'rgba(74, 74, 74, 0.7)',
  174. padding: '5px',
  175. borderRadius: '5px',
  176. zIndex: '100001'
  177. });
  178.  
  179. const cssToggleContrast = document.createElement('span');
  180. cssToggleContrast.id = 'css-toggle-contrast';
  181. cssToggleContrast.style.cursor = 'pointer';
  182. cssToggleContrast.style.fontSize = '12px';
  183. cssToggleContrast.addEventListener('click', toggleCustomContrast);
  184.  
  185. const cssToggleText = document.createElement('span');
  186. cssToggleText.id = 'css-toggle-text';
  187. cssToggleText.style.cursor = 'pointer';
  188. cssToggleText.style.fontSize = '12px';
  189. cssToggleText.addEventListener('click', toggleCustomCss);
  190.  
  191. controlsContainer.appendChild(cssToggleContrast);
  192. controlsContainer.appendChild(cssToggleText);
  193. controlPanel.appendChild(settingsButton);
  194. controlPanel.appendChild(controlsContainer);
  195. document.body.appendChild(controlPanel);
  196. updateControlText();
  197. };
  198.  
  199. const updateElementsVisibility = () => {
  200. const shouldShow = isAllowedPage() && !isChatsPage();
  201. if (controlPanel) controlPanel.style.display = shouldShow ? 'flex' : 'none';
  202. if (controlsContainer) controlsContainer.style.display = shouldShow && isMenuVisible ? 'flex' : 'none';
  203. };
  204.  
  205. const initialize = () => {
  206. createControlPanel();
  207. updateElementsVisibility();
  208.  
  209. if (isAllowedPage() && !isChatsPage()) {
  210. applyCustomCssToggle();
  211.  
  212. new MutationObserver(() => {
  213. applyCustomCssToggle();
  214. }).observe(document.body, { childList: true, subtree: true });
  215.  
  216. const originalAppendChild = Element.prototype.appendChild;
  217. Element.prototype.appendChild = function(node) {
  218. if (isCustomCssDisabled && node.tagName === 'STYLE' && this.tagName === 'HEAD') {
  219. return node;
  220. }
  221. return originalAppendChild.call(this, node);
  222. };
  223. }
  224. };
  225.  
  226. const tryInitialize = () => {
  227. if (document.body) {
  228. initialize();
  229. let lastPath = window.location.pathname;
  230. setInterval(() => {
  231. if (lastPath !== window.location.pathname) {
  232. lastPath = window.location.pathname;
  233. updateElementsVisibility();
  234. if (isAllowedPage() && !isChatsPage()) {
  235. applyCustomCssToggle();
  236. }
  237. }
  238. }, 500);
  239. } else {
  240. setTimeout(tryInitialize, 1000);
  241. }
  242. };
  243.  
  244. tryInitialize();
  245. })();