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.1
  7. // @match *://aistudio.google.com/*
  8. // @grant none
  9. // @author HORSELOCKSPACEPIRATE/rayzorium
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const delay = 300; //millis to wait for sliders to appear, increase this is your shit's not working
  16.  
  17. // Function to set sliders to lowest value (-4)
  18. function setSlidersToLowest(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. dialogContainer.querySelector('button[aria-label="Close Run Safety Settings"]').click();
  27. }
  28.  
  29. // Function to attempt setting sliders on page load or model change
  30. function setSliderOnLoadOrChange() {
  31. // Try to find and click the "Edit safety settings" button
  32. const editButton = document.querySelector('.edit-safety-button') || document.querySelector('.settings-item.safety-settings');
  33. if (editButton) {
  34. editButton.click();
  35. } else {
  36. // If button not found, try again after a short delay
  37. setTimeout(setSliderOnLoadOrChange, 100);
  38. }
  39. }
  40.  
  41. // Mutation observer to detect when the safety settings dialog appears
  42. const observer = new MutationObserver((mutations) => {
  43. mutations.forEach((mutation) => {
  44. if (mutation.addedNodes.length) {
  45. const addedNode = mutation.addedNodes[0];
  46. if (addedNode.nodeType === Node.ELEMENT_NODE && addedNode.matches('mat-dialog-container')) {
  47. setTimeout(() => setSlidersToLowest(addedNode), delay); // Adding a slight delay to ensure sliders are loaded
  48. }
  49. }
  50. });
  51. });
  52.  
  53. // Start observing the body for additions of the dialog container
  54. observer.observe(document.body, { childList: true, subtree: true });
  55.  
  56. // Adding click event listener to the "Edit safety settings" button
  57. document.addEventListener('click', function(e) {
  58. if (e.target && (e.target.closest('.edit-safety-button') || e.target.closest('.settings-item.safety-settings'))) {
  59. // We wait for the dialog to be added to the DOM
  60. observer.observe(document.body, { childList: true, subtree: true });
  61. }
  62. });
  63.  
  64. // Function to handle model change
  65. function handleModelChange(mutationsList, observer) {
  66. for(let mutation of mutationsList) {
  67. if (mutation.type === 'characterData' || mutation.type === 'childList') {
  68. // Model has changed, trigger slider adjustment
  69. setSliderOnLoadOrChange();
  70. break;
  71. }
  72. }
  73. }
  74.  
  75. // Create an observer for the model selector
  76. const modelObserver = new MutationObserver(handleModelChange);
  77.  
  78. // Function to start observing the model selector
  79. function observeModelSelector() {
  80. const modelSelector = document.querySelector('#model-selector .mat-mdc-select-value-text');
  81. if (modelSelector) {
  82. modelObserver.observe(modelSelector, { childList: true, characterData: true, subtree: true });
  83. } else {
  84. // If not found, try again after a short delay
  85. setTimeout(observeModelSelector, 1000);
  86. }
  87. }
  88.  
  89. // Run the setSliderOnLoadOrChange function when the page is fully loaded
  90. if (document.readyState === 'complete') {
  91. setSliderOnLoadOrChange();
  92. observeModelSelector();
  93. } else {
  94. window.addEventListener('load', () => {
  95. setSliderOnLoadOrChange();
  96. observeModelSelector();
  97. });
  98. }
  99. })();