GoogleNoRedir

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==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();
    }
  }
})();