PDF search on Google

Adds a button to search PDF with Google

  1. // ==UserScript==
  2. // @name PDF search on Google
  3. // @version 1.0.0
  4. // @description Adds a button to search PDF with Google
  5. // @author Mario O.M. and D.V
  6. // @namespace https://github.com/marioortizmanero/reddit-search-on-google/
  7. // @include http*://www.google.*/search*
  8. // @include http*://google.*/search*
  9. // @run-at document-end
  10. // @license MIT
  11. // ==/UserScript==
  12. // Creating the element
  13. let el = document.createElement('div');
  14. el.className = 'hdtb-mitem';
  15. const link = document.createElement('a');
  16.  
  17. // Adding the svg icon
  18. if (useIcon) {
  19. const span = document.createElement('span');
  20. span.className = isImageSearch ? 'm3kSL' : 'bmaJhd iJddsb';
  21. span.style.cssText = 'height:16px;width:16px';
  22. span.innerHTML = redditIcon;
  23. link.appendChild(span);
  24. }
  25.  
  26. // Hyperlink to add 'site:reddit.com' to the query
  27. link.appendChild(document.createTextNode('PDF'));
  28.  
  29. // Agregar un menú desplegable
  30. const menu = document.createElement('ul');
  31. menu.id = 'pdf-menu';
  32. menu.style.display = 'none';
  33. const menuItems = ['Opción 1', 'Opción 2', 'Opción 3'];
  34. menuItems.forEach((item) => {
  35. const menuItem = document.createElement('li');
  36. const menuItemLink = document.createElement('a');
  37. menuItemLink.href = '#';
  38. menuItemLink.innerText = item;
  39. menuItem.appendChild(menuItemLink);
  40. menu.appendChild(menuItem);
  41. });
  42. el.appendChild(menu);
  43.  
  44. link.addEventListener('mouseover', () => {
  45. menu.style.display = 'block';
  46. });
  47.  
  48. link.addEventListener('mouseout', () => {
  49. menu.style.display = 'none';
  50. });
  51.  
  52. // Reemplazar el enlace original
  53. link.href = window.location.href.replace(queryRegex, (match) => {
  54. // Replaces the existing `site` flags
  55. return match.search(siteRegex) >= 0 ? match.replace(siteRegex, redditUrl) : match + redditUrl;
  56. });
  57.  
  58. if (isImageSearch) {
  59. link.classList.add('NZmxZe');
  60. el = link;
  61. } else {
  62. el.appendChild(link);
  63. }
  64.  
  65. // Inserting the element into Google search
  66. if (appendRight) {
  67. const toolsBtn = document.querySelector(isImageSearch ? '.ssfWCe' : '.t2vtad');
  68. toolsBtn.parentNode.insertBefore(el, toolsBtn.nextSibling);
  69. } else {
  70. const menuBar = document.querySelector(isImageSearch ? '.T47uwc' : '.MUFPAc');
  71. if (isImageSearch) {
  72. menuBar.insertBefore(el, menuBar.children[menuBar.childElementCount - 1]);
  73. } else {
  74. menuBar.appendChild(el);
  75. }
  76. }

QingJ © 2025

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