GoogleNoRedir

Bypasses Google's redirect warnings and replaces search result links with direct URLs.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name:ja         GoogleNoRedir
// @description:ja  Googleのリダイレクト警告を回避し、検索結果のリンクを直リンクに置き換えます。
// @author:ja       甘瀬ここあ

// @name         GoogleNoRedir
// @description  Bypasses Google's redirect warnings and replaces search result links with direct URLs.
// @author       AmaseCocoa
// @namespace    https://ns.amase.cc#GoogleNoRedir
// @version      1.1
// @license MIT
// @match        *://www.google.com/url?*
// @match        *://www.google.co.jp/url?*
// @match        *://www.google.com/search*
// @match        *://www.google.co.jp/search*
// @grant        none
// @run-at       document-start
// ==/UserScript==

/* jshint esversion: 11 */
(function () {
  "use strict";

  // ==========================================
  // SETTINGS (Change true to false to disable)
  // ==========================================
  const CONFIG = {
    AUTO_REDIRECT: true,
    REWRITE_LINKS: true,
  };

  const currentUrl = window.location.href;

  if (CONFIG.AUTO_REDIRECT && currentUrl.includes("/url?")) {
    try {
      const params = new URLSearchParams(window.location.search);
      const targetUrl = params.get("url");
      if (targetUrl) {
        window.location.replace(decodeURIComponent(targetUrl));
        return;
      }
    } catch (e) {}
  }

  if (CONFIG.REWRITE_LINKS && currentUrl.includes("/search")) {
    const cleanUpGoogleUrls = () => {
      const links = document.querySelectorAll(
        'a[href^="/url?"], a[href*=".google.com/url?"]',
      );
      links.forEach((link) => {
        try {
          const params = new URLSearchParams(
            new URL(link.getAttribute("href"), window.location.origin).search,
          );
          const targetUrl = params.get("url");
          if (targetUrl) {
            link.setAttribute("href", targetUrl);
            if (link.hasAttribute("onmousedown"))
              link.removeAttribute("onmousedown");
          }
        } catch (e) {}
      });
    };

    const init = () => {
      cleanUpGoogleUrls();
      new MutationObserver(() => cleanUpGoogleUrls()).observe(document.body, {
        childList: true,
        subtree: true,
      });
    };

    if (document.readyState === "loading") {
      document.addEventListener("DOMContentLoaded", init);
    } else {
      init();
    }
  }
})();