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);
})();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址