Improved safe search

09/11/2025, 09:34:21

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Improved safe search
// @namespace   Violentmonkey Scripts
// @match       https://www.google.com/search*
// @grant       none
// @version     1.0
// @author      SHA
// @license     GNU GPLv3
// @description 09/11/2025, 09:34:21
// ==/UserScript==

window.addEventListener("load", async (event) => {
//  const wordList = ["ok1", "test2"];
//  const searchInput = await waitForElement('#APjFqb');
//  console.log(searchInput);
//  const didYouMean = await waitForElement('#oFNiHe a[href^="/search?"]');
//  console.log(didYouMean);

if (document.querySelector('[data-notice="SAFESEARCH_LOCKED"]')) {
  console.log('found')
  const searchInput = document.getElementById('APjFqb');
  history.replaceState(null, null, "q");
  document.querySelector("[jsname=pkjasb]").click();
  document.querySelector("title").innerHTML = "Quote";
  document.body.click();
  document.getElementById('main').innerHTML = `
   <iframe src="https://www.nodi.so/widgets/embed/public/quotes" style="margin: auto; display: block; width: 500px; height: 300px"></iframe>
  `;
}
});

function waitForElement(selector) {
    return new Promise(resolve => {
        if (document.querySelector(selector)) {
            return resolve(document.querySelector(selector));
        }
        const observer = new MutationObserver(mutations => {
            const element = document.querySelector(selector);
            console.log('performed querey selection');
            if (element) {
                observer.disconnect();
                resolve(element);
            }
        });
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    });
}