BillMonk Image Adder

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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;
}
*/