// Jane Style から Tumblr に Photo を post するための JScript // C:\Program Files\Jane Style\script フォルダに保存して command.dat に次の行を追加する。 // tumblr - Photo=wscript "$BASEPATHscript\tumblr.Photo.js" "$LINK" "$URL" "$TITLE" "$TEXT" // スレ内の画像リンクを右クリックして Tumblr - Photo でポスト。 // // IE で Tumblr にログインしている必要がある。 // // パスの通ったフォルダに // wscript.exe version 5.7.0.18066 // msxml6.dll version 6.20.2003.0 // が置いてある Windows XP SP3 上で動いた。 (function() { function share() { var xhr = new ActiveXObject('Msxml2.XMLHTTP.6.0'); xhr.open('GET', 'http://www.tumblr.com/new/photo'); xhr.send(); xhr.onreadystatechange = post(xhr); } function findKeys(xhr) { return { 'upload_id' : xhr.responseText.match(/name="UPLOAD_IDENTIFIER" value="([^"]+)"/)[1], 'form_key' : xhr.responseText.match(/name="form_key" value="([^"]+)"/)[1] } } function post(xhr) { if (xhr.readyState == 4) { var link = WScript.arguments(0); var thread_url = WScript.arguments(1); var thread_title = WScript.arguments(2); var selected_text = WScript.arguments(3) || ''; var description = '

' + thread_title + '

'; if (selected_text != "") description += '

' + selected_text.replace(/\n/g, '
') + '

'; var form = { 'UPLOAD_IDENTIFIER' : findKeys(xhr).upload_id, 'form_key' : findKeys(xhr).form_key, 'post[two]' : description, 'post[type]' : "photo", 'post[source_url]' : thread_url, 'photo_src' : link, 'post[three]' : link } var re = []; for (n in form) { re.push(encodeURIComponent(n) + '=' + encodeURIComponent(form[n])); } var content = re.join('&'); var header = { 'Host' : 'www.tumblr.com', 'User-Agent' : 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.22) Gecko/20110902 Firefox/3.6.22 ( .NET CLR 3.5.30729; .NET4.0E)', 'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language' : 'en-us,en;q=0.7,ja;q=0.3', 'Accept-Encoding' : 'gzip,deflate', 'Accept-Charset' : 'UTF-8,*', 'Keep-Alive' : '115', 'Connection' : 'keep-alive', 'Content-Length' : content.length, 'Content-Type' : 'application/x-www-form-urlencoded' } xhr.open('POST', 'http://www.tumblr.com/new/photo'); for (n in header) { xhr.setRequestHeader(n, header[n]); } xhr.send(content); xhr.onreadystatechange = checkStatus(xhr); } } function checkStatus(xhr) { if (xhr.readyState == 4 && xhr.status != 200) { echo('post できなかったかも\n\nstatus : ' + xhr.status + '\n\nheaders : \n' + xhr.getAllResponseHeaders); } } function echo(str) { WScript.Echo(str); } try { share(); } catch(e) {} })();