Finya XL Image Previewer

Preview Finya userimages without leaving a trace in the "last visited by" section of that user

  1. // ==UserScript==
  2. // @name Finya XL Image Previewer
  3. // @include http://*.finya.de/*
  4. // @description Preview Finya userimages without leaving a trace in the "last visited by" section of that user
  5. // @version 4.00
  6. // @namespace https://greasyfork.org/users/8629
  7. // ==/UserScript==
  8.  
  9. var allIMGs, thisIMG, xTop, leftOffset, topOffset;
  10. matchRegEx = /_1[0-2].jpg/i; // Identifies image sources for small images
  11. replaceString = '_4.jpg' // Replacement so we can find the large images
  12. leftOffset = 20; // X-axis offset to the mouse pointer
  13. topOffset = -50; // Y-axis offset to the mouse pointer
  14. borderWidth = 1; // Large image border width
  15. toWatch = new Array('appstage','content','sidebar','list-online','searchbar-wrapper','voting-history-wrapper','header-content'); // Elements which have dynamic img content
  16. toWatchClasses = new Array('userpic','searchbar-thumb'); // Image style classes containing relevant images
  17. toWatchParentClasses = new Array('morepics'); // Style classes of parent elements containing relevant images
  18. imgCache = new Object(); // Used for pre-loading images
  19.  
  20. // Event functions
  21. function animate (e, tagetXL) {
  22. xTop = (document.documentElement.scrollTop || document.body.scrollTop); // cross-browser top
  23. // horizontal position
  24. if ((e.pageX + leftOffset + (2 * borderWidth))>(document.documentElement.clientWidth + document.documentElement.scrollLeft - targetXL.width)) {
  25. if ((e.pageX + (2 * borderWidth) + 2)<(document.documentElement.clientWidth + document.documentElement.scrollLeft - targetXL.width)) {
  26. targetXL.style.left = document.documentElement.clientWidth + document.documentElement.scrollLeft - targetXL.width - (2 * borderWidth) + 'px';
  27. } else {
  28. targetXL.style.left = e.pageX - targetXL.width - leftOffset + 'px';
  29. }
  30. } else {
  31. targetXL.style.left = e.pageX + leftOffset + 'px';
  32. }
  33.  
  34. // vertical position
  35. if ((e.pageY - topOffset + (2 * borderWidth))>(document.documentElement.clientHeight + xTop)) {
  36. targetXL.style.top = document.documentElement.clientHeight + xTop - targetXL.height - (2 * borderWidth) + 'px';
  37. } else if ((e.pageY - targetXL.height - topOffset)<xTop) {
  38. targetXL.style.top = xTop + 'px';
  39. } else {
  40. targetXL.style.top = e.pageY - targetXL.height - topOffset + 'px';
  41. }
  42. }
  43.  
  44. function mouseOver(e) {
  45. targetXL = document.getElementById('ImgElem');
  46. if (targetXL.src != this.getAttribute('targetSrc')) {
  47. targetXL.src = this.getAttribute('targetSrc');
  48. }
  49. animate (e, targetXL);
  50.  
  51. targetXL.style.display='block';
  52. }
  53.  
  54. function mouseMove(e) {
  55. targetXL = document.getElementById('ImgElem');
  56. if (targetXL.src != this.getAttribute('targetSrc')) {
  57. targetXL.src = this.getAttribute('targetSrc');
  58. }
  59. animate (e, targetXL);
  60. }
  61.  
  62. function mouseOut() {
  63. document.getElementById('ImgElem').style.display='none';
  64. document.getElementById('ImgElem').src='';
  65. }
  66.  
  67. // Add big-sized preview images for all small preview images
  68. function addPrvImg() {
  69. var smallIMGs = new Array();
  70. var usedIMGs = new Array();
  71. // identify all relevant small images
  72. // a) search for images via their classes
  73. for (var i = 0; i < toWatchClasses.length; i++) {
  74. var possibleImages = document.getElementsByClassName(toWatchClasses[i]);
  75.  
  76. for (var j = 0; j < possibleImages.length; j++) {
  77. if (possibleImages[j].nodeName == 'IMG' && possibleImages[j].src.search(matchRegEx)>0) {
  78. smallIMGs.push(possibleImages[j]);
  79. }
  80. }
  81. }
  82. // b) search for images via their parents' classes
  83. for (var i = 0; i < toWatchClasses.length; i++) {
  84. possibleParents = document.getElementsByClassName(toWatchParentClasses[i]);
  85.  
  86. for (var j = 0; j < possibleParents.length; j++) {
  87. var possibleImages = possibleParents[j].getElementsByTagName('IMG');
  88.  
  89. for (var k = 0; k < possibleImages.length; k++) {
  90. if (possibleImages[k].src.search(matchRegEx)>0) {
  91. smallIMGs.push(possibleImages[k]);
  92. }
  93. }
  94.  
  95. }
  96. }
  97.  
  98. // loop small images
  99. for (var i = 0; i < smallIMGs.length; i++) {
  100. var thisIMG = smallIMGs[i];
  101. // get target source from image source file name
  102. var targetSrc = thisIMG.src.replace(matchRegEx,replaceString);
  103.  
  104. // Collect target sources for images which are still active in the document
  105. usedIMGs.push(targetSrc);
  106.  
  107. if (thisIMG.getAttribute("targetSrc")!=targetSrc) {
  108. // set "targetSrc" attribute to the target's source. it will be used by the event functions to locate the big preview image
  109. thisIMG.setAttribute("targetSrc", targetSrc);
  110.  
  111. // only cache preview image if it does not already exist (somewhere else in the document)
  112. if (!(imgCache.hasOwnProperty(targetSrc))) {
  113. imgCache[targetSrc] = new Image();
  114. imgCache[targetSrc].src = targetSrc;
  115. }
  116. // activate event listeners for small preview image
  117. thisIMG.title = thisIMG.alt;
  118. thisIMG.addEventListener('mouseover', mouseOver, false);
  119. thisIMG.addEventListener('mousemove', mouseMove, false);
  120. thisIMG.addEventListener('mouseout', mouseOut, false);
  121. // (Re-)activate pointer events in case there were disabled (as is the case for the favorites submenu)
  122. if (thisIMG.style.pointerEvents = "none") {
  123. thisIMG.style.pointerEvents = "auto";
  124. }
  125. }
  126. }
  127. // remove unused images from imgCache
  128. for (image in imgCache) {
  129. if (usedIMGs.indexOf(image)<0) {
  130. delete imgCache[image];
  131. }
  132. }
  133. }
  134.  
  135. // initial execution
  136. addPrvImg();
  137.  
  138. // Create blank image element. It will be filled with actual XL images and unhidden during execution
  139. var imgXL = document.createElement('img');
  140.  
  141. imgXL.setAttribute('style', 'z-index:10000; overflow:hidden; position:absolute; display:none; border-width:' + borderWidth + 'px; box-shadow: 0px 0px 16px #036; border-style:solid; border-color:#FFF;');
  142. imgXL.setAttribute('id', 'ImgElem');
  143. document.body.insertBefore(imgXL, document.body.firstChild);
  144.  
  145. // add event listeners to dynamic elements
  146. for (var i = 0; i < toWatch.length; i++) {
  147. if (thisElem = document.getElementById(toWatch[i])) {
  148. thisElem.addEventListener('DOMSubtreeModified', addPrvImg, false);
  149. }
  150. }