您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Adds a PDF tab to Google search results
// ==UserScript== // @name Add PDF Tab to Google Search // @namespace http://tampermonkey.net/ // @version 1.0 // @description Adds a PDF tab to Google search results // @author Bui Quoc Dung // @match *://www.google.com/search* // @icon https://www.google.com/favicon.ico // @grant none // ==/UserScript== (function() { 'use strict'; // Find the container for the search tabs (parent element containing the tab list) const tabContainer = document.querySelector('.crJ18e'); if (!tabContainer) return; // Find the "Books" tab to insert the new tab after it const booksTab = [...tabContainer.querySelectorAll('div[role="listitem"]')] .find(tab => tab.textContent.trim() === 'Books'); if (!booksTab) return; // Get the search query from the URL const urlParams = new URLSearchParams(window.location.search); const query = urlParams.get('q'); if (!query) return; // Check if the query already contains "filetype:pdf" if (query.toLowerCase().includes("filetype:pdf")) { return; // If filetype:pdf is already in the query, do nothing } // Create the URL for the PDF search by appending "filetype:pdf" const pdfSearchUrl = `/search?q=${encodeURIComponent(query)}+filetype:pdf`; // Create a new PDF tab const pdfTab = document.createElement('div'); pdfTab.setAttribute('role', 'listitem'); pdfTab.innerHTML = ` <a href="${pdfSearchUrl}" class="nPDzT T3FoJb"> <div class="YmvwI">PDF</div> </a> `; // Insert the PDF tab after the "Books" tab booksTab.insertAdjacentElement('afterend', pdfTab); })();