vox -> tumblr migration
voxからtumblrへの引っ越し依頼を受けた。
voxはyoutubeとかswfを入れるときにiframeで囲んでページに入れている(cookieとられないように)。
フィードにもiframeがそのまま入っていてそこをどうしようか困った。けっきょくなにもしてない。
window.doc = window.doc || null; {with( new XMLHttpRequest() ) { open("GET", "http://ku0522.vox.com/library/posts/page/1/atom-full.xml", false); send(null) doc = createHTMLDocumentByString(responseText); } } function createHTMLDocumentByString(str) { var html = str.replace(/<!DOCTYPE.*?>/, '').replace(/<html.*?>/, '').replace(/<\/html>.*/, '') var htmlDoc = document.implementation.createDocument(null, 'html', null) var fragment = createDocumentFragmentByString(html) try { fragment = htmlDoc.adoptNode(fragment) } catch(e) { fragment = htmlDoc.importNode(fragment, true) } htmlDoc.documentElement.appendChild(fragment) return htmlDoc } function createDocumentFragmentByString(str) { var range = document.createRange() range.setStartAfter(document.body) return range.createContextualFragment(str) } // $X // based on: http://lowreal.net/blog/2007/11/17/1 // // $X(exp); // $X(exp, context); // $X(exp, type); // $X(exp, {context: context, // type: type, // namespace: {h:"http://www.w3.org/1999/xhtml"}}); function $X (exp, context) { var type, namespace={}; // console.log(String(exp)); if(typeof context == "function"){ type = context; context = null; }else if(typeof context != "undefined" && !context['nodeType']){ type = context['type']; namespace = context['namespace'] || context['ns']; context = context['context']; } if (!context) context = document; console.log(context, context.ownerDocument); var exp = (context.ownerDocument || context).createExpression(exp, function (prefix) { return namespace[prefix] || document.createNSResolver((context.ownerDocument == null ? context : context.ownerDocument).documentElement) .lookupNamespaceURI(prefix) || document.documentElement.namespaceURI; }); switch (type) { case String: return exp.evaluate( context, XPathResult.STRING_TYPE, null ).stringValue; case Number: return exp.evaluate( context, XPathResult.NUMBER_TYPE, null ).numberValue; case Boolean: return exp.evaluate( context, XPathResult.BOOLEAN_TYPE, null ).booleanValue; case Array: var result = exp.evaluate( context, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null ); var ret = []; for (var i = 0, len = result.snapshotLength; i < len; ret.push(result.snapshotItem(i++))); return ret; case undefined: var result = exp.evaluate(context, XPathResult.ANY_TYPE, null); switch (result.resultType) { case XPathResult.STRING_TYPE : return result.stringValue; case XPathResult.NUMBER_TYPE : return result.numberValue; case XPathResult.BOOLEAN_TYPE: return result.booleanValue; case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: { // not ensure the order. var ret = []; var i = null; while (i = result.iterateNext()) { ret.push(i); } return ret; } } return null; default: throw(TypeError("$X: specified type is not valid type.")); } } function post(title, body, date) { var d = document; var ce = function (n, a) { var e = d.createElement(n); for(var i in a ) { e.setAttribute(i, a[i] ); } return e } var f = ce("form", { action:"http://www.tumblr.com/api/write", target: "_blank", method:"POST", enctype: "multipart/form-data" } ); f.appendChild(ce("input", {type:"text", name:"email", value:email} )); f.appendChild(ce("input", {type:"text",name:"password", value:password} )); f.appendChild(ce("input", {type:"text",name:"title", value:title} )); f.appendChild(ce("input", {type:"text",name:"date", value:date} )); f.appendChild(ce("input", {type:"text",name:"body", value:body} )); f.appendChild(ce("input", {type:"submit"} )); document.body.appendChild(f); f.submit(); } $X("//entry", doc).map( function(e) { var body = $X(".//content", e).pop() ; var body = body.innerHTML.toString().replace( /\n/g, '') .replace(/^.+?ns\/at">\s*/, '') .replace(/<p style.+/, '') .replace(/\s+$/, '') .replace(/<div at:.+?>(.+?)<\/div>/, "$1") //.replace(/<div\s+class="enclos.+?">(.+?)<\/div>/g, "$1") //.replace(/<div\s+class="enclos.+?">(.+?)<\/div>/g, "$1") //.replace(/<div\s+class="enclos.+?">(.+?)<\/div>/g, "$1") //.replace(/<div\s+class="enclos.+?">(.+?)<\/div>/g, "$1") //return body post( $X(".//title", e).pop().textContent , body, $X(".//published", e).pop().textContent ); } );