TP.org

Direct image display

  1. // ==UserScript==
  2. // @name TP.org
  3. // @namespace https://greasyfork.org/users/4390-seriousm
  4. // @description Direct image display
  5. // @match http://*.teenplanet.org/*
  6. // @version 0.8
  7. // ==/UserScript==
  8.  
  9. if (document.location.href.indexOf("photos.teenplanet.org") >= 0){
  10. function toArray(nl) {
  11. for(var a=[], l=nl.length; l--; a[l]=nl[l]);
  12. return a;
  13. }
  14. var links = document.getElementsByClassName('thumb-box');
  15. for (var tbi = 0;tbi<links.length;tbi++){
  16. var linkElem = links[tbi];
  17. var imgElem = linkElem.getElementsByTagName('img')[0];
  18. var aElem = linkElem.getElementsByTagName('a')[0];
  19. var link = aElem.href;
  20. // load the file
  21. var xhr = new XMLHttpRequest();
  22. xhr.targetElem = aElem;
  23. xhr.targetImg = imgElem;
  24. xhr.onreadystatechange = function() {
  25. if (this.readyState == 4){
  26. // create a 'div' element to wrap it
  27. var elem = document.createElement('div');
  28. // inject the file in the div
  29. elem.innerHTML = this.responseText;
  30. var divs = elem.getElementsByTagName('div');
  31. var arr = toArray(divs);
  32. var arrFiltered = arr.filter(function(el){
  33. return el && el.id == "full-size";
  34. });
  35. var fullImg = arrFiltered[0].getElementsByTagName('a')[0].href;
  36. this.targetElem.href = fullImg;
  37. this.targetImg.src = fullImg;
  38. }
  39. };
  40. xhr.open( "GET", link, true );
  41. xhr.send();
  42. }
  43. }
  44. else if (document.location.href.indexOf("www.teenplanet.org/images") >= 0){
  45. var basePath = document.location.href.substr(0, document.location.href.indexOf("index.html")) + "images/";
  46. var images = document.querySelectorAll("div.thumbnail img");
  47. for(var i = 0; i < images.length; i++){
  48. var image = images[i];
  49. var imagePath = basePath + image.alt;
  50. image.parentNode.href = imagePath;
  51. }
  52. }
  53. else if (document.location.href.indexOf("teenplanet.org/galleries") >= 0){
  54. var images = document.querySelectorAll('div#galleryImages img');
  55. for(var i = 0; i < images.length; i++){
  56. var image = images[i];
  57. var imagePath = image.src;
  58. image.parentNode.href = imagePath.replace(/\/thumbs\//, '/');
  59. }
  60. }