Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name Mediamaker img local replace
// @namespace http://efcl.info/
// @include http://mediamarker.net/u/自分のID
// ==/UserScript==
var XPath = {
cache: null,
reset: function () {
this.cache = {__proto__: null};
},
get: function (context, expr, type) {
var x = new XPathEvaluator();
var cache = this.cache, evaluator;
if (expr in cache) {
evaluator = cache[expr];
} else {
evaluator = cache[expr] = x.createExpression(expr, null);
}
return evaluator.evaluate(context, type, null);
},
has: function (context, expr) {
return this.get(context, expr, XPathResult.BOOLEAN_TYPE).booleanValue;
},
first: function (context, expr) {
return this.get(context, expr, XPathResult.FIRST_ORDERED_NODE_TYPE).singleNodeValue;
},
last: function (context, expr) {
var all = this.get(context, expr, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE);
return all.snapshotItem(all.snapshotLength - 1) || null;
},
all: function (context, expr) {
var all = this.get(context, expr, XPathResult.ORDERED_NODE_ITERAATE_TYPE);
var ret = [];
for (var i; (i = all.iterateNext()) !== null;) {
ret.push(i);
}
return ret;
}
};
XPath.reset();
/*
http://dl.dropbox.com/u/11111111/kansou/
file:///D:/MyDocuments/My%20Dropbox/Public/kansou/
*/
function start(doc){
var originSrc = "http://dl.dropbox.com/u/ドロップボックスID";
var newSrc = "file:///D:ドロップボックスのPublicフォルダのパス";
var imgs = XPath.all(doc,'//td[@class="main"]//div[@class="rm_grid"]//a');
imgs.map(function(ele){
var imgSrc = XPath.first(ele ,'./img').src;
imgSrc = imgSrc.replace(originSrc ,newSrc);
ele.href = ele.href.replace(originSrc ,newSrc);
})
}
start(document);
document.body.addEventListener('AutoPagerize_DOMNodeInserted',function(evt){
var node = evt.target;
// 処理
start(node);
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.