Add Site Search Links To Google Search Result

Add a "Site Results" link onto each Google search result entries to search from that site. The link will be added either in the search result entry's popup menu, or after the green URL below the entry's title.

2019-10-23 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Add Site Search Links To Google Search Result
// @namespace    https://greasyfork.org/en/users/85671-jcunews
// @version      1.0.6
// @license      AGPL v3
// @author       jcunews
// @description  Add a "Site Results" link onto each Google search result entries to search from that site. The link will be added either in the search result entry's popup menu, or after the green URL below the entry's title.
// @include      *://www.google.*/search*
// @include      *://www.google.*.*/search*
// @grant        none
// ==/UserScript==

(function(a) {
  function dropdownClick(a) {
    this.setAttribute("aria-expanded", a = this.classList.toggle("selected"));
    this.parentNode.querySelector(".action-menu-panel").style.visibility = a ? "inherit" : "";
  }
  location.search.substring(1).split("&").some(function(v) {
    if (v.indexOf("q=") === 0) {
      if (a = decodeURIComponent(v.substr(2).trim().replace(/\+/g, " ")).match(/(?:^|\s)site:([^\s]+)/)) {
        a = a[1];
      } else a = "";
      return true;
    }
  });
  if (!a) document.querySelectorAll("#ires .g,#search .g").forEach(function(entry, menu, point, e) {
    if (!(point = entry.querySelector(".r>a"))) return;
    if (menu = entry.querySelector(".action-menu-item")) { //v2: has menu
      if ((/:\/\/webcache/).test(menu.firstElementChild.href)) {
        e = menu.nextElementSibling;
      } else if ((/=related:http/).test(menu.firstElementChild.href)) {
        e = menu;
      } else e = null;
      menu = menu.parentNode.insertBefore(menu.cloneNode(true), e).firstElementChild;
    } else if (menu = entry.querySelector(".f")) { //v1
      menu.insertAdjacentHTML("beforeend", ' - <a class="fl"></a>');
      menu = menu.lastElementChild;
    } else { //v2: no menu
      point.parentNode.insertBefore(menu = document.createElement("SPAN"), point.nextSibling);
      menu.innerHTML = `\
<div class="action-menu ac_ctl">
  <a class="GHDvEf ab_button" href="#" aria-label="Result Options" aria-expanded="false" aria-haspopup="true" role="button" jsaction="m.tdd;keydown:m.hbke;keypress:m.mskpe"><span class="mn-dwn-arw"></span></a>
  <div class="action-menu-panel ab_dropdown" role="menu" tabindex="-1" jsaction="keydown:m.hdke;mouseover:m.hdhne;mouseout:m.hdhue">
    <ol><li class="action-menu-item ab_dropdownitem" role="menuitem"><a class="fl"></a></li></ol>
  </div>
</div>`;
      menu.querySelector("a").onclick = dropdownClick;
      menu = menu.querySelector(".fl");
    }
    menu.textContent = "Site Results";
    if (point.pathname === "/url") {
      point = unescape(point.search.match(/&url=([^&]+)/)[1]).match(/:\/\/([^:/]+)/)[1];
    } else point = point.hostname;
    menu.href = location.href.replace(/([&?]q=[^&]+)/, "$1+site:" + escape(point));
    menu.onmousedown = null;
  });
})();