Greasy Fork

Greasy Fork is available in English.

Additional Google Options

Additional Google Options (languages, discussion)

当前为 2024-04-22 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name Additional Google Options
// @description:en Additional Google Options
// @version 1.1
// @grant none
// @include /^http(s)?:\/\/(www)?\.google\.\w*\/search.*$/
// @namespace
// @description Additional Google Options (languages, discussion)
// @namespace http://greasyfork.icu/users/1291433
// ==/UserScript==
(function () {
  const langList = ['ru', 'de', 'en', 'ja', 'fr']
  const discussion = ['discussions']
  const wiki = ['wiki']
  const url = new URL(location.href)

  const menu = document.createElement('div')
  menu.style.position = 'absolute'
  menu.style.top = '0'
  menu.style.left = '0'
  menu.style.right = '0'
  menu.style.zIndex = '9999999999'
  menu.style.display = 'flex'
  menu.style.flexDirection = 'row'
  menu.style.gap = '1rem'
  menu.style.justifyContent = 'center'
  menu.style.fontSize = '18px'

  langList.forEach(l => {
    const item = document.createElement('div')
    url.searchParams.set('lr', `lang_${l}`)
    item.innerHTML = `<a href="${url}">${l}</a>`
    menu.appendChild(item)
  })

  discussion.forEach(d => {
    const item = document.createElement('div');
    const searchParams = new URLSearchParams(window.location.search);
    const query = searchParams.get('q');
    const modifiedQuery = `inurl:forum|viewthread|showthread|viewtopic|showtopic|comments|comment|questions|"index.php?topic"|intext:"reading this topic"|"next thread"|"next topic"|"send private message"`;
    const url = new URL(window.location.href);
    const searchParamStr = url.searchParams.toString();
    const updatedSearchParamStr = searchParamStr ? `${searchParamStr}&q=${encodeURIComponent(modifiedQuery)}` : `q=${encodeURIComponent(modifiedQuery)}`;
    url.search = updatedSearchParamStr;
    item.innerHTML = `<a href="${url}">${d}</a>`;
    menu.appendChild(item);

    // Find the text area by searching for nearby elements
    const form = document.querySelector('form[name="f"]');
    if (form) {
      const textArea = form.querySelector('textarea[name="q"]');
      if (textArea) {
        textArea.value = query; // Set only the original query
      }
    }
  })

  wiki.forEach(d => {
    const item = document.createElement('div');
    const searchParams = new URLSearchParams(window.location.search);
    const query = searchParams.get('q');
    const modifiedQuery = `inurl:wiki`;
    const url = new URL(window.location.href);
    const searchParamStr = url.searchParams.toString();
    const updatedSearchParamStr = searchParamStr ? `${searchParamStr}&q=${encodeURIComponent(modifiedQuery)}` : `q=${encodeURIComponent(modifiedQuery)}`;
    url.search = updatedSearchParamStr;
    item.innerHTML = `<a href="${url}">${d}</a>`;
    menu.appendChild(item);

    // Find the text area by searching for nearby elements
    const form = document.querySelector('form[name="f"]');
    if (form) {
      const textArea = form.querySelector('textarea[name="q"]');
      if (textArea) {
        textArea.value = query; // Set only the original query
      }
    }
  });




  document.querySelector('body').appendChild(menu)
})()