BillMonk Image Adder

Creates images from first comment, if its format is img:http://...

  1. // ==UserScript==
  2. // @name BillMonk Image Adder
  3. // @namespace http://www.arthaey.com/
  4. // @description Creates images from first comment, if its format is img:http://...
  5. // @include https://www.billmonk.com/receipt/*
  6. //
  7. // Backed up from http://userscripts.org/scripts/review/6706
  8. // Last updated on 2006-12-09
  9. // @version 0.0.1.20140612212410
  10. // ==/UserScript==
  11.  
  12. // TODO
  13. // - look at all comments and add multiple images if necessary
  14. // - make it a user preference whether image is added at top or in sidebar
  15.  
  16. window.addEventListener("load", function() {
  17. // check that elements are where we expect them to be
  18. var sharedImg = document.getElementsByTagName("img")[7];
  19. if (!sharedImg) return;
  20.  
  21. /*
  22. var sidebar = getElementsByClassName("sidebar_box", "table")[0];
  23. if (!sidebar) return;
  24. */
  25.  
  26. var commentDiv = document.getElementById("comments");
  27. if (!commentDiv) return;
  28.  
  29. // if Linkify has already run, then it will be a span with an anchor
  30. var src;
  31. var comment = commentDiv.getElementsByTagName("span")[0];
  32. if (comment && comment.childNodes[0].nodeValue == "img:") {
  33. src = comment.childNodes[1].href;
  34. }
  35. // otherwise, it's just plain text
  36. else {
  37. comment = commentDiv.getElementsByTagName("i")[0];
  38. if (!comment) return;
  39.  
  40. var regex = new RegExp("^img:(http://.+)$");
  41. src = comment.childNodes[0].nodeValue;
  42. if (!regex.test(src)) return;
  43. src = regex.exec(src)[1];
  44. }
  45. if (!src) return;
  46.  
  47. var img = document.createElement("img");
  48. img.style.cssFloat = "left";
  49. img.src = src;
  50.  
  51. // insert before "Shared Receipt" image
  52. sharedImg.parentNode.insertBefore(img, sharedImg);
  53.  
  54. /*
  55. img.style.marginTop = "1em";
  56. // insert after "Use your cell phone" box in sidebar
  57. sidebar.parentNode.insertBefore(img, sidebar.nextSibling);
  58. */
  59. }, true);
  60.  
  61. /*
  62. function getElementsByClassName(clsName,htmltag){
  63. var arr = new Array();
  64. var elems = document.getElementsByTagName(htmltag);
  65. for ( var cls, i = 0; ( elem = elems[i] ); i++ ){
  66. if ( elem.className == clsName ){
  67. arr[arr.length] = elem;
  68. }
  69. }
  70. return arr;
  71. }
  72. */