Always Set AI Studio Filters to None

Sets all safety settings to none whenever the page loads or model changes

当前为 2024-07-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @license it made me include this idk
  3. // @name Always Set AI Studio Filters to None
  4. // @description Sets all safety settings to none whenever the page loads or model changes
  5. // @namespace http://tampermonkey.net/
  6. // @version 1
  7. // @match *://aistudio.google.com/*
  8. // @grant none
  9. // @author HORSELOCKSPACEPIRATE/rayzorium
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to set sliders to lowest value (-4)
  16. function setSlidersToLowest() {
  17. const dialogContainer = document.querySelector('mat-dialog-container');
  18. if (dialogContainer) {
  19. const sliders = dialogContainer.querySelectorAll('mat-slider input[type="range"]');
  20. sliders.forEach(slider => {
  21. slider.value = -4;
  22. slider.dispatchEvent(new Event('input', { bubbles: true }));
  23. slider.dispatchEvent(new Event('change', { bubbles: true }));
  24. });
  25. // Close the dialog box
  26. const closeButton = dialogContainer.querySelector('button[aria-label="Close Run Safety Settings"]');
  27. if (closeButton) {
  28. closeButton.click();
  29. }
  30. }
  31. }
  32.  
  33. // Function to attempt setting sliders on page load or model change
  34. function setSliderOnLoadOrChange() {
  35. // Try to find and click the "Edit safety settings" button
  36. const editButton = document.querySelector('.edit-safety-button') || document.querySelector('.settings-item.safety-settings');
  37. if (editButton) {
  38. editButton.click();
  39. // Wait a bit for the dialog to open, then set sliders
  40. setTimeout(setSlidersToLowest, 500);
  41. } else {
  42. // If button not found, try again after a short delay
  43. setTimeout(setSliderOnLoadOrChange, 1000);
  44. }
  45. }
  46.  
  47. // Mutation observer to detect when the safety settings dialog appears
  48. const observer = new MutationObserver((mutations) => {
  49. mutations.forEach((mutation) => {
  50. if (mutation.addedNodes.length) {
  51. const addedNode = mutation.addedNodes[0];
  52. if (addedNode.nodeType === Node.ELEMENT_NODE && addedNode.matches('mat-dialog-container')) {
  53. setTimeout(setSlidersToLowest, 150); // Adding a slight delay to ensure sliders are loaded
  54. }
  55. }
  56. });
  57. });
  58.  
  59. // Start observing the body for additions of the dialog container
  60. observer.observe(document.body, { childList: true, subtree: true });
  61.  
  62. // Adding click event listener to the "Edit safety settings" button
  63. document.addEventListener('click', function(e) {
  64. if (e.target && (e.target.closest('.edit-safety-button') || e.target.closest('.settings-item.safety-settings'))) {
  65. // We wait for the dialog to be added to the DOM
  66. observer.observe(document.body, { childList: true, subtree: true });
  67. }
  68. });
  69.  
  70. // Function to handle model change
  71. function handleModelChange(mutationsList, observer) {
  72. for(let mutation of mutationsList) {
  73. if (mutation.type === 'characterData' || mutation.type === 'childList') {
  74. // Model has changed, trigger slider adjustment
  75. setSliderOnLoadOrChange();
  76. break;
  77. }
  78. }
  79. }
  80.  
  81. // Create an observer for the model selector
  82. const modelObserver = new MutationObserver(handleModelChange);
  83.  
  84. // Function to start observing the model selector
  85. function observeModelSelector() {
  86. const modelSelector = document.querySelector('#model-selector .mat-mdc-select-value-text');
  87. if (modelSelector) {
  88. modelObserver.observe(modelSelector, { childList: true, characterData: true, subtree: true });
  89. } else {
  90. // If not found, try again after a short delay
  91. setTimeout(observeModelSelector, 1000);
  92. }
  93. }
  94.  
  95. // Run the setSliderOnLoadOrChange function when the page is fully loaded
  96. if (document.readyState === 'complete') {
  97. setSliderOnLoadOrChange();
  98. observeModelSelector();
  99. } else {
  100. window.addEventListener('load', () => {
  101. setSliderOnLoadOrChange();
  102. observeModelSelector();
  103. });
  104. }
  105. })();