Greasy Fork镜像 支持简体中文。

Add PDF Tab to Google Search

Adds a PDF tab to Google search results

  1. // ==UserScript==
  2. // @name Add PDF Tab to Google Search
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Adds a PDF tab to Google search results
  6. // @author Bui Quoc Dung
  7. // @match *://www.google.com/search*
  8. // @icon https://www.google.com/favicon.ico
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Find the container for the search tabs (parent element containing the tab list)
  16. const tabContainer = document.querySelector('.crJ18e');
  17.  
  18. if (!tabContainer) return;
  19.  
  20. // Find the "Books" tab to insert the new tab after it
  21. const booksTab = [...tabContainer.querySelectorAll('div[role="listitem"]')]
  22. .find(tab => tab.textContent.trim() === 'Books');
  23.  
  24. if (!booksTab) return;
  25.  
  26. // Get the search query from the URL
  27. const urlParams = new URLSearchParams(window.location.search);
  28. const query = urlParams.get('q');
  29.  
  30. if (!query) return;
  31.  
  32. // Check if the query already contains "filetype:pdf"
  33. if (query.toLowerCase().includes("filetype:pdf")) {
  34. return; // If filetype:pdf is already in the query, do nothing
  35. }
  36.  
  37. // Create the URL for the PDF search by appending "filetype:pdf"
  38. const pdfSearchUrl = `/search?q=${encodeURIComponent(query)}+filetype:pdf`;
  39.  
  40. // Create a new PDF tab
  41. const pdfTab = document.createElement('div');
  42. pdfTab.setAttribute('role', 'listitem');
  43. pdfTab.innerHTML = `
  44. <a href="${pdfSearchUrl}" class="nPDzT T3FoJb">
  45. <div class="YmvwI">PDF</div>
  46. </a>
  47. `;
  48.  
  49. // Insert the PDF tab after the "Books" tab
  50. booksTab.insertAdjacentElement('afterend', pdfTab);
  51. })();
  52.  
  53.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址