Google Scholar in Google

This script add "Scholar" link to Google search result page.

当前为 2024-11-30 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Google Scholar in Google
// @namespace   https://thynanami.dev
// @description This script add "Scholar" link to Google search result page.
// @match       https://www.google.com/search*
// @version     0.0.1
// @author      Nanami Nakano
// @grant       GM_addStyle
// @license     MIT
// ==/UserScript==

(function () {
'use strict';

function getSearchText() {
  const searchTextarea = document.querySelector('[aria-label="Search"]');
  if (!searchTextarea) {
    const searchTextarea = document.querySelector('[role="textbox"]');
    const searchText = searchTextarea.value;
    return encodeURI(`https://scholar.google.com/scholar?q=${searchText}`);
  }
  const searchText = searchTextarea.textContent;
  return encodeURI(`https://scholar.google.com/scholar?q=${searchText}`);
}
function getTab() {
  const listItems = document.querySelectorAll('[role="listitem"]');
  if (listItems.length < 2) {
    throw new Error("Could not find the second listitem to copy styles from.");
  }
  return listItems[1];
}
try {
  const url = getSearchText();
  const tab = getTab();
  const newTab = document.createElement("div");
  Array.from(tab.attributes).forEach(attribute => {
    newTab.setAttribute(attribute.name, attribute.value);
  });
  const anchor = tab.querySelector("a");
  const newAnchor = document.createElement("a");
  Array.from(anchor.attributes).forEach(attribute => {
    newAnchor.setAttribute(attribute.name, attribute.value);
  });
  newAnchor.setAttribute("href", url);
  const title = anchor.querySelector("div");
  const newTitle = document.createElement("div");
  newTitle.textContent = "Scholar";
  Array.from(title.attributes).forEach(attribute => {
    newTitle.setAttribute(attribute.name, attribute.value);
  });
  newAnchor.appendChild(newTitle);
  newTab.appendChild(newAnchor);
  const navigationContainer = document.querySelector('[role="list"]');
  if (navigationContainer) {
    navigationContainer.insertBefore(newTab, tab);
  }
} catch (e) {
  console.warn(e);
}

})();