AllDataSheet: straight to PDF

With this script you will directly go to the PDF version of the datasheet when you click on the PDF icon in the search results.

  1. // ==UserScript==
  2. // @name AllDataSheet: straight to PDF
  3. // @name:it AllDataSheet: dritto al PDF
  4. // @description With this script you will directly go to the PDF version of the datasheet when you click on the PDF icon in the search results.
  5. // @description:it Con questo script andrai direttamente alla versione in PDF della scheda tecnica quando clicchi sull'icona del PDF nei risultati della ricerca.
  6. // @namespace StephenP
  7. // @match http://*.alldatasheet.com/*
  8. // @match https://*.alldatasheet.com/*
  9. // @match http://*.alldatasheetde.com/*
  10. // @match https://*.alldatasheetde.com/*
  11. // @match http://*.alldatasheet.com/*
  12. // @match https://*.alldatasheet.com/*
  13. // @match http://*.alldatasheetru.com/*
  14. // @match https://*.alldatasheetru.com/*
  15. // @match http://*.alldatasheet.es/*
  16. // @match https://*.alldatasheet.es/*
  17. // @match http://*.alldatasheetit.com/*
  18. // @match https://*.alldatasheetit.com/*
  19. // @match http://*.alldatasheet.pl/*
  20. // @match https://*.alldatasheet.pl/*
  21. // @match http://*.alldatasheetcn.com/*
  22. // @match https://*.alldatasheetcn.com/*
  23. // @match http://*.alldatasheet.jp/*
  24. // @match https://*.alldatasheet.jp/*
  25. // @match http://*.alldatasheet.co.kr/*
  26. // @match https://*.alldatasheet.co.kr/*
  27. // @match http://*.alldatasheetpt.com/*
  28. // @match https://*.alldatasheetpt.com/*
  29. // @match http://*.alldatasheet.vn/*
  30. // @match https://*.alldatasheet.vn/*
  31. // @version 1.2.1
  32. // @contributionURL https://buymeacoffee.com/stephenp_greasyfork
  33. // @grant none
  34. // ==/UserScript==
  35. function clickOnMenu(){
  36. var links=document.getElementsByClassName("main")[0].getElementsByTagName("A");
  37. for(var link of links){
  38. if((link.href.includes("//pdf"))&&(link.href.includes("/view/"))){
  39. link.click();
  40. break;
  41. }
  42. }
  43. }
  44. if((window.location.href.includes("/datasheet-pdf/"))&&(!window.location.href.includes("pdfjs/web/viewer.html?file=/"))){
  45. if((window.location.href.includes("pdf1.alldatasheet"))||(window.location.href.includes("pdf2.alldatasheet"))){
  46. document.body.style.opacity="0"; //Not really necessary, but avoids misunderstanding on what the script is doing.
  47. var frames=document.getElementsByTagName("IFRAME");
  48. var found=false;
  49. for(let frame of frames){
  50. console.log("There are "+frames.length+" frames on the page");
  51. if(frame.src.includes("/datasheet-pdf/")){
  52. console.log("A frame with a datasheet pdf has been found: "+frame.src);
  53. found=true;
  54. window.location.href=frame.src;
  55. }
  56. }
  57. if(found==false){
  58. if(document.location.href.split("?file=//").length>1){
  59. let lnk=document.createElement("a");
  60. lnk.href="https://"+document.location.href.split("?file=//")[1];
  61. document.body.appendChild(lnk);
  62. lnk.click();
  63. }
  64. else{
  65. console.log("No way to extract a datasheet have been found.");
  66. document.body.style.opacity="100";
  67. clickOnMenu();
  68. }
  69. }
  70. }
  71. else if(window.location.href.includes("manufacture1.alldatasheet")){
  72. clickOnMenu();
  73. }
  74. else if(window.location.href.includes("www.alldatasheet")){
  75. clickOnMenu();
  76. }
  77. }
  78. else if(window.location.href.includes(".jsp")){
  79. var images = document.getElementsByTagName("IMG");
  80. for(let image of images){
  81. if(image.src.includes("datasheet.gif")){
  82. if(image.parentNode.href.includes("www.alldatasheet")){
  83. image.parentNode.href=image.parentNode.href.replace("www.alldatasheet","pdf1.alldatasheet").replace("/pdf/","/view/");
  84. }
  85. else if(image.parentNode.href.includes("manufacture1.alldatasheet")){
  86. image.parentNode.href=image.parentNode.href.replace("manufacture1.alldatasheet","pdf2.alldatasheet").replace("/pdf/","/view/");
  87. }
  88. }
  89. }
  90. }