Skip to content

Instantly share code, notes, and snippets.

@koduki
Created February 23, 2009 20:37
Show Gist options
  • Save koduki/69162 to your computer and use it in GitHub Desktop.
Save koduki/69162 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name url2thum
// @namespace pascal.orz.cn
// @include http://*.2ch.net/*
// ==/UserScript==
var ExObject = function(){
var obj = this;
this.replace_html = function(filter){
obj.innerHTML = filter(obj.innerHTML);
return this;
};
};
var wrapArray = function(xs){
var fn = arguments.callee;
xs.maph = function(filter) fn(xs.map(function(x) x.replace_html(filter)));
return xs;
};
var bindReady = function(callback){
document.addEventListener( "DOMContentLoaded", function(){
document.removeEventListener( "DOMContentLoaded", arguments.callee, false );
callback();
}, false );
};
var xfind = function(xpath) {
var results = document.evaluate(xpath, document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var nodes = new Array();
for(var i=0; i<results.snapshotLength; i++){
var x = results.snapshotItem(i);
ExObject.prototype = x;
nodes.push(new ExObject());
}
return wrapArray(nodes);
};
var Validator = {
isFunction: function( obj ){return typeof(obj) == "function";},
isArray: function( obj ){return toString.call(obj) === "[object Array]";}
};
var $ = function(arg){
return (Validator.isFunction(arg)) ? bindReady(arg)
: xfind(arg);
};
//$(function(){
var ttp = /([^h])(ttp:\/\/[\x21-\x7E]+)/ig;
$("//dd").maph(function(x) x.replace(ttp, "h$2") )
.maph(function(x) x.replace(/(http.*\.jpg)/g,
"<img src='$1' width='240px' height='320px'/>") );
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment