Pouet Plus

Preview screenshots straight from the prods search by hovering over links.

  1. // ==UserScript==
  2. // @name Pouet Plus
  3. // @namespace PP
  4. // @description Preview screenshots straight from the prods search by hovering over links.
  5. // @version 1.1.0
  6. // @include http://pouet.net/*
  7. // @include http://www.pouet.net/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. // Don't use this, prodScreenshot.user.js is better!
  12.  
  13. var bg_color = "#EAEAEA";
  14. var border_color = "#D5D5D5";
  15. var font_color = "#000000";
  16. var font_face = "tahoma";
  17. var font_size = "11px";
  18.  
  19. // I stole this hover code from somewhere else but forgot to credit it - sorry!
  20.  
  21. function locate(event) {
  22. var posx, posy;
  23. var d = find_div();
  24. if (d) {
  25. posx = event.clientX + window.pageXOffset;
  26. posy = event.clientY + window.pageYOffset;
  27. d.style.top = (posy - 23) + "px";
  28. d.style.left = (posx + 15) + "px";
  29. }
  30. }
  31.  
  32. function find_div() {
  33. return document.getElementById("link_tt");
  34. }
  35.  
  36. function setImageSource(tt_image, demo_num, ext) {
  37. // Used to work:
  38. //tt_image.src = "screenshots/"+demo_num+"."+ext;
  39. tt_image.src = "http://www.pouet.net/content/screenshots/"+demo_num+"."+ext;
  40. }
  41.  
  42. function addImage(tt_image, tt_div) {
  43. tt_div.innerHTML = "";
  44. tt_div.appendChild(tt_image);
  45. }
  46.  
  47. function create_div(event, elem) {
  48. var tt_div = document.createElement("div");
  49. tt_div.setAttribute("id", "link_tt");
  50. tt_div.setAttribute("style", "background:" + bg_color + ";border:1px solid " + border_color + ";padding:2px;color:" + font_color + ";font-family:" + font_face + ";font-size:" + font_size + ";position:absolute;z-index:1000;");
  51. var demo_num = elem.href.replace(/.*?which=([0-9]*).*/, '$1');
  52. var tt_image = new Image();
  53. setImageSource(tt_image, demo_num, "jpg");
  54. tryOtherExtensionsIfNeeded(tt_div, tt_image, demo_num, ["gif", "png"]);
  55. addImage(tt_image, tt_div);
  56. tt_div.style.display = 'none';
  57. document.body.appendChild(tt_div);
  58. locate(event);
  59. }
  60.  
  61. function tryOtherExtensionsIfNeeded(tt_div, tt_image, demo_num, imageTypes) {
  62. var fired = false;
  63. tt_image.addEventListener("error", function() {
  64. if (fired) {
  65. return;
  66. }
  67. fired = true;
  68. if (imageTypes.length == 0) {
  69. GM_log("We have run out of image types to try!");
  70. } else {
  71. var ext = imageTypes.pop();
  72. // It seems just updating the src was enough to unregister my error event listener (Chrome 32), so now I am going to create and replace the whole image element.
  73. tt_image = new Image();
  74. setImageSource(tt_image, demo_num, ext);
  75. addImage(tt_image, tt_div);
  76. tryOtherExtensionsIfNeeded(tt_div, tt_image, demo_num, imageTypes.slice(0));
  77. }
  78. }, false);
  79. tt_image.addEventListener("load", function() {
  80. tt_div.style.display = '';
  81. }, false);
  82. }
  83.  
  84. function kill_window() {
  85. var div = find_div();
  86. if (div) {
  87. div.parentNode.removeChild(div);
  88. }
  89. }
  90.  
  91. var timer = null;
  92. function resetTimeout(fn) {
  93. if (timer) {
  94. clearTimeout(timer);
  95. timer = null;
  96. }
  97. if (fn) {
  98. timer = setTimeout(fn, 300);
  99. }
  100. }
  101.  
  102. function create_event(elem) {
  103. elem.addEventListener("mouseover", function(event) { resetTimeout(function() { create_div(event, elem); }); }, false);
  104. elem.addEventListener("mouseout", function() { resetTimeout(null); kill_window(); }, false);
  105. elem.addEventListener("mousemove", function(event) { locate(event); }, true);
  106. }
  107.  
  108. var links = document.getElementsByTagName("a");
  109. for (i = 0; i < links.length; i++) {
  110. if (
  111. links[i].href.indexOf("/prod.php?which=")>=0 // Yes if this links points to a prod.
  112. && links[i].href.indexOf("&howmanycomments=")==-1 // But not if it's pointing to a specific comments page.
  113. ) {
  114. create_event(links[i]);
  115. }
  116. }
  117.