!bangAnywhere

Use DuckDuckGo !bangs on your preferred search engine

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name        !bangAnywhere
// @namespace   https://github.com/RuiNtD
// @version     1.1.3
// @description Use DuckDuckGo !bangs on your preferred search engine
// @author      RuiNtD
// @match       https://*.google.com/search?*
// @match       https://*.bing.com/search?*
// @match       https://search.brave.com/search?*
// @match       https://*.qwant.com/?*
// @match       https://*.startpage.com/*/search*
// @noframes    
// @homepageURL https://greasyfork.org/scripts/469625
// @icon        https://icons.duckduckgo.com/ip2/duckduckgo.com.ico
// @require     https://cdn.jsdelivr.net/npm/@violentmonkey/url@0
// @resource    bangs https://duckduckgo.com/bang.js
// @license     MIT
// @grant       GM_getResourceText
// ==/UserScript==

(function (url) {
'use strict';

// Modified from https://github.com/t3dotgg/unduck
function getBangUrl(query) {
  const match = query.match(/!(\S+)/i);
  const bangTag = match?.[1]?.toLowerCase();
  if (!bangTag) return;
  const bangs = JSON.parse(GM_getResourceText("bangs"));
  const bang = bangs.find(b => b.t == bangTag);
  if (!bang) return null;
  const cleanQuery = query.replace(/!\S+\s*/i, "").trim();
  if (!cleanQuery) return `https://${bang.d}`;
  return bang.u.replace("{{{s}}}", encodeURIComponent(cleanQuery));
}
function checkQuery() {
  const url = new URL(window.location.href);
  const params = url.searchParams;
  const qInput = document.querySelector("input#q");
  const query = (params.get("q") || params.get("query") || qInput?.value || "").trim();
  if (!query) return;
  console.log("!bangAnywhere Query:", query);
  const bangUrl = getBangUrl(query);
  console.log("!bangAnywhere Redirect:", bangUrl);
  if (bangUrl) window.location.replace(bangUrl);
}
url.onNavigate(checkQuery);
checkQuery();

})(VM);