My Red Book

By Scary Monster Last update Aug 18, 2008 — Installed 165 times.

There are 2 previous versions of this script.

// ==UserScript==
// @name           My Red Book
// @namespace      myredbook
// @include        http://forum.myredbook.com/cgi-bin/*
//@description  preview images on  myredbook.com forums. Inspiration from craigslist image review script.
// Updated - No Images appear after the link
// Image links go to the posting instead of the images them selves.
// ==/UserScript==


var DEBUG = false;
var PREFIX = "*cs*.";
var SIZE_PARAM = "size";
var KEEP_ASPECT_RATIO_PARAM = "aspect.ratio";
var MAX_RESULTS_PARAM = "max.results";
var MAX_MAX_RESULTS = 50;
var CLASS = "_c";
var size = 0;
var keepAspectRatio = true;
var maxResults = 100;

function setValue(key,val) {
  GM_setValue(PREFIX + key,val);
  return val;
}

function getValue(key,defaultValue) {
  var res = GM_getValue(PREFIX + key);
  if (!res) res = defaultValue;
  return res;
}

/**
 * String[tag] (Node) -> Node
 * Creates a new node.
 */
function $n(tag,on) {
  var e = document.createElement(tag);
  if (on) on.appendChild(e);
  return e;
}

/**
 * String[text] (Node) -> Node
 * Creates a new text node.
 */
function $t(text,on) {
  var e = document.createTextNode(text);
  if (on) on.appendChild(e);
  return e;
}

function insertAfter(newNode,target) {
  var parent   = target.parentNode;
  var refChild = target.nextSibling;
  if(refChild) parent.insertBefore(newNode, refChild);
  else parent.appendChild(newNode);  
}

var cnt=0;
function newFunction(_a) {
  var a = _a;
  return function(details) {
    if (details.responseText) {
      
      if (m = details.responseText.match(/img src=\"([^\"]+)\"/gi)) {

        //
        // Go thru the links
        // div will hold the new div below the links parent
        //
        var div;
        var cnt = 0;
        for (var j=0; j<m.length; j++) {
          s = m[j];
          if (!s) continue;
		  if(s.match("\"/images/")|| s.match(/.*\/dcforum2\/Images\/.*/)) continue;
		  // basically a hack, but I thought this would return  an array
          s = s.replace(/img src=/g,"");
          s = s.replace(/\"/g,"");
          //
          // For the first time create the div to hold the links
          //
          if (!div) {
			var tr = a.parentNode.parentNode;		   			
            var newTr = $n("tr");
			insertAfter(newTr, tr);
			var div = $n("td", newTr);
			div.colSpan = 5;			
          }
          //
          // Create the link and image and add them
          //
          var newA = $n("a",div);
          var img = $n("img",newA);
          img.className = CLASS;
          img.src = s;
          //
          // 1.5: Don't change the height if we're keeping the aspect ratio
		  // Also don't resize if size is zero.
          //
		  if(size > 0){
	          if (!keepAspectRatio) {
	            img.style.width = size + "px";
	          }
	          img.style.height = size + "px";
		  }
          newA.href = a;
          if (++cnt > maxResults-1) {
            var amt = m.length-maxResults;
            if (amt != 0) {
              $t(" ...",div);
              $t(amt + " more ",div);
            }
            break;
          }
          $t(" ",div);
        }
      }
    }
  };
}


function showImages() {
  //
  // find all the links to listings and display the images
  //
  links = document.getElementsByTagName("a");
  for (i=0; i<links.length; i+=2) {
    link = links[i];
    if (link.href && link.href.match(/.*forum.myredbook.com.*\/\d+\.html$/)) {
      GM_xmlhttpRequest({
        method:"GET",
            url: link.href,
            headers:{
            "User-Agent": "monkeyagent",
              "Accept":"text/html,text/monkey,text/xml,text/plain",
              },
            onload: newFunction(link)
        });
    }
  }
}

function main() {
  showImages();
}

try {main();} catch (e) { if (DEBUG) alert(e); }