Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name fillin_hatena_diary_twi_content_with_title
// @namespace http://shiba-yu36.net/
// @description fill in hatena diary twitter content with title in edit.
// @include http://d.hatena.ne.jp/*/edit
// @include http://d.hatena.ne.jp/*/#edit_in_place
// ==/UserScript==
(function(){
//その場編集時のアクション
var editInPlaceAction = function() {
var fillInTwitterEditInPlace = function(e) {
if (e.target.name == 'title') {
var title = e.target;
var twitter_prefix = title.form.elements.namedItem('twitter_notification_prefix');
twitter_prefix['focus']();
twitter_prefix['blur']();
twitter_prefix.value = title.value;
twitter_prefix.style.color = "";
}
};
document.addEventListener('change', fillInTwitterEditInPlace, true);
};
//詳細編集時のアクション
var detailEditAction = function() {
//twitter_contentにfillin
var fillInTwitterContentInDetail = function(value) {
var res_snap;
res_snap = document.evaluate('//*[@id="twitter_notification_prefix"]',
document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var twitter_notifier = res_snap.snapshotItem(0);
twitter_notifier.value = value;
};
//編集のtextareaをパースする
var textareaParseAndFillin = function (){
var res_snap = document.evaluate('//*[@id="textarea-edit"]',
document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var textarea = res_snap.snapshotItem(0);
var text = textarea.value;
var text_array = text.split("\n");
for(var i=0; i<text_array.length; i++) {
if (text_array[i].match(/^\*\s*[^*]+/)) {
var title = text_array[i].replace(/\*\s*/, "");
fillInTwitterContentInDetail(title);
return;
}
}
fillInTwitterContentInDetail(null);
};
//3秒ごとにfillin
var timer = window.setInterval(textareaParseAndFillin, 3000);
var res_snap = document.evaluate('//*[@id="twitter_notification_prefix"]',
document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
//twitter_notifierがフォーカスされたらfillinしなくする
res_snap.snapshotItem(0).addEventListener('focus',
function(){
window.clearInterval(timer);
},false);
};
//URLで挙動を変える
if (/\#edit_in_place/.test(window.location.href)) {
editInPlaceAction();
}
else {
detailEditAction();
}
})();
@shiba-yu36

This comment has been minimized.

Copy link
Owner Author

commented Jun 9, 2010

var が抜けていたので、修正

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.