Created
April 17, 2010 14:32
-
-
Save tarao/369593 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name HatenaDiaryDraftAutoPreview | |
// @namespace http://orezdnu.org/ | |
// @include http://d.hatena.ne.jp/*/draft?* | |
// ==/UserScript== | |
(function(d) { | |
var $ = function(id) { | |
return typeof id == 'string' ? d.getElementById(id) : id; | |
}; | |
var $f = function(form, name) { | |
if (form[name]) return form[name].value; | |
var es = form.elements; | |
for (var i=0; i < es.length; i++) { | |
if (es[i].name == name) return es[i].value; | |
} | |
}; | |
var textarea = $('textarea-edit'); | |
var edit = $('draft_form'); | |
if (!textarea || !edit) return; | |
var form = d.createElement('form'); | |
form.method = 'post'; | |
var url = location.href.match(/(http:\/\/d[^\/]*\/[^\/]*\/[^\/]*)/); | |
form.action = url[1]; | |
var param = { | |
mode: 'enter', | |
rkm: unsafeWindow.Hatena.Diary.rkm, | |
title: $f(edit, 'title'), | |
body: textarea.value, | |
year: $f(edit, 'year'), | |
month: $f(edit, 'month'), | |
day: $f(edit, 'day'), | |
preview: '確認する' | |
}; | |
for (var key in param) { | |
var input = d.createElement('input'); | |
input.type = 'hidden'; | |
input.name = key; | |
input.value = param[key]; | |
form.appendChild(input); | |
} | |
d.body.appendChild(form); | |
form.submit(); | |
})(unsafeWindow.document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment