Gemini DeepResearch Auto Extract Links

Extract all links from Gemini Deep Research result into a clean list (one per line). Suitable for importing into NotebookLM.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Gemini DeepResearch Auto Extract Links
// @name:zh-CN   Gemini DeepResearch自动提取链接
// @namespace    https://gemini.google.com/
// @version      1.0.2
// @description  Extract all links from Gemini Deep Research result into a clean list (one per line). Suitable for importing into NotebookLM.
// @description:zh-CN 从 Gemini 深度研究结果中提取所有链接,每行一个,方便导入 NotebookLM。
// @match        https://gemini.google.com/*
// @grant        GM_setClipboard
// @license      MIT
// @run-at       document-idle
// ==/UserScript==

(function () {
  // Extract all links inside browse-web-item elements
  function extractLinks() {
    const aTags = [...document.querySelectorAll('browse-web-item a')];
    if (aTags.length === 0) {
      alert("No browse-web-item links found.");
      return;
    }

    const links = aTags.map(a => a.href).join("\n");

    // Copy to clipboard
    if (typeof GM_setClipboard === "function") {
      GM_setClipboard(links);
    } else if (navigator.clipboard && navigator.clipboard.writeText) {
      navigator.clipboard.writeText(links).catch(err => console.error(err));
    }

    console.log("Extracted links:\n" + links);
    alert(`Copied ${aTags.length} links to clipboard.`);
  }

  // Insert Extract button into the Gemini toolbar
  function addButtonIfNeeded() {
    const actionButtons = document.querySelector(".toolbar.has-title .action-buttons");
    if (!actionButtons) return;

    // Prevent duplicate buttons
    if (actionButtons.querySelector(".extract-links-button")) return;

    const btn = document.createElement("button");
    btn.textContent = "Extract Links";
    btn.className =
      "mdc-button mat-mdc-button-base mat-mdc-unelevated-button extract-links-button";
    btn.style.marginLeft = "8px";

    btn.addEventListener("click", extractLinks);

    actionButtons.insertBefore(btn, actionButtons.firstChild);
  }

  // Run once on load
  addButtonIfNeeded();

  // Observe DOM since Gemini loads UI dynamically
  const observer = new MutationObserver(() => {
    addButtonIfNeeded();
  });

  if (document.body) {
    observer.observe(document.body, { childList: true, subtree: true });
  }
})();