directGelF

direct link to all gelbooru images in search results+

  1. // ==UserScript==
  2. // @name directGelF
  3. // @namespace directGelF
  4. // @version 1.81
  5. // @description direct link to all gelbooru images in search results+
  6. // @homepage https://greasyfork.org/ru/scripts/114-directgelf
  7. // @run-at document-end
  8. // @grant GM_openInTab
  9. // @match http://*.gelbooru.com/*
  10. // ==/UserScript==
  11.  
  12. if (typeof GM_openInTab === "undefined")
  13. {
  14. GM_openInTab = window.open;
  15. }
  16.  
  17. if(document.location.hostname != "simg4.gelbooru.com")
  18. {
  19. var els = document.getElementsByClassName("preview");
  20.  
  21. for(var x = 0; x < els.length; x++)
  22. {
  23. // Obtaining the final URL of the image
  24. var dir = els[x].src;
  25. dir = dir.split("thumbnails")[1] || dir.split("thumbs")[1]; // gelbooru sometimes can't decide one
  26. dir = dir.split('?')[0].replace("thumbnail_","");
  27. dir = "http://simg4.gelbooru.com//images" + dir;
  28. // Setting original link to right click
  29. els[x].id = els[x].parentNode.href; // save url
  30. els[x].setAttribute('oncontextmenu',"return false;"); // block menu
  31. els[x].addEventListener('contextmenu', function(aEvent) {GM_openInTab(this.id);window.focus();}, true, true); // R-Click
  32.  
  33. // Setting the new href
  34. els[x].parentNode.href = dir;
  35. }
  36. }
  37. else // file extension fix
  38. {
  39. if(document.title.indexOf("404 ") == 0)
  40. {
  41. if(window.location.href.lastIndexOf(".jpg") != -1)
  42. {
  43. window.location.href = window.location.href.replace(".jpg", ".jpeg");
  44. }
  45. else if(window.location.href.lastIndexOf(".jpeg") != -1)
  46. {
  47. window.location.href = window.location.href.replace(".jpeg", ".png");
  48. }
  49. else if(window.location.href.lastIndexOf(".png") != -1)
  50. {
  51. window.location.href = window.location.href.replace(".png", ".gif");
  52. }
  53. else if(window.location.href.lastIndexOf(".gif") != -1)
  54. {
  55. window.location.href = window.location.href.replace(".gif", ".jpg");
  56. }
  57. }
  58. }