BillMonk Image Adder

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name           BillMonk Image Adder
// @namespace      http://www.arthaey.com/
// @description    Creates images from first comment, if its format is img:http://...
// @include        https://www.billmonk.com/receipt/*
//
// Backed up from http://userscripts.org/scripts/review/6706
// Last updated on 2006-12-09
// @version 0.0.1.20140612212410
// ==/UserScript==

// TODO
//  - look at all comments and add multiple images if necessary
//  - make it a user preference whether image is added at top or in sidebar

window.addEventListener("load", function() {
   // check that elements are where we expect them to be
   var sharedImg = document.getElementsByTagName("img")[7];
   if (!sharedImg) return;

   /*
   var sidebar = getElementsByClassName("sidebar_box", "table")[0];
   if (!sidebar) return;
   */

   var commentDiv = document.getElementById("comments");
   if (!commentDiv) return;

   // if Linkify has already run, then it will be a span with an anchor
   var src;
   var comment = commentDiv.getElementsByTagName("span")[0];
   if (comment && comment.childNodes[0].nodeValue == "img:") {
      src = comment.childNodes[1].href;
   }
   // otherwise, it's just plain text
   else {
      comment = commentDiv.getElementsByTagName("i")[0];
      if (!comment) return;

      var regex = new RegExp("^img:(http://.+)$");
      src = comment.childNodes[0].nodeValue;
      if (!regex.test(src)) return;
      src = regex.exec(src)[1];
   }
   if (!src) return;

   var img = document.createElement("img");
   img.style.cssFloat = "left";
   img.src = src;

   // insert before "Shared Receipt" image
   sharedImg.parentNode.insertBefore(img, sharedImg);

   /*
   img.style.marginTop = "1em";
   // insert after "Use your cell phone" box in sidebar
   sidebar.parentNode.insertBefore(img, sidebar.nextSibling);
   */
}, true);

/*
function getElementsByClassName(clsName,htmltag){ 
  var arr = new Array(); 
  var elems = document.getElementsByTagName(htmltag);
  for ( var cls, i = 0; ( elem = elems[i] ); i++ ){
    if ( elem.className == clsName ){
      arr[arr.length] = elem;
    }
  }
  return arr;
}
*/