Created
August 27, 2010 04:13
-
-
Save awq/552772 to your computer and use it in GitHub Desktop.
はてな匿名ダイアリーにおけるhttp記法を修正する
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 anond httpnotation modification | |
// @namespace http://anond.hatelabo.jp/20100827132032 | |
// @include http://anond.hatelabo.jp/* | |
// @description はてな匿名ダイアリーにおけるhttp記法を修正する | |
// ==/UserScript== | |
(function(doc){ | |
var modifyHttp = function(){ | |
var i = doc.getElementById("text-body").value; | |
var j = i.replace(/\[(https?:\/\/[^\]:]+)(?::title=([^\]]*))?\]/g, function() { | |
var titleOld = arguments[2]? | |
arguments[2]: | |
arguments[1]; | |
var titleNew = ""; | |
for(var n = 0; n < titleOld.length; n++) { | |
if ( titleOld[n] == "\n" ) { | |
titleNew += "\n"; | |
} else if ( titleOld[n] == "\r" ) { | |
titleNew += "\r"; | |
} else if ( titleOld[n] == "m") { | |
titleNew += "m"; | |
} else { | |
titleNew += ("&#"+(titleOld.charCodeAt(n))+";"); | |
} | |
titleNew += "‎"; | |
} | |
return "[" + arguments[1] + ":title=" + titleNew + "]"; | |
}); | |
doc.getElementById("text-body").value = j; | |
}; | |
var explain = doc.evaluate('id("body")//span[@class="explain"]', doc, null, 9, null).singleNodeValue; | |
var prevButtonPlain = doc.evaluate('id("body")//input[@name="preview"]', doc, null, 9, null).singleNodeValue; | |
var prevButtonHttp = prevButtonPlain.cloneNode(false); | |
prevButtonHttp.value = '確認する(http修正)', prevButtonHttp.name = 'preview_http'; | |
prevButtonHttp.addEventListener('click', function(){ | |
modifyHttp(); | |
prevButtonPlain.click(); | |
}, false); | |
prevButtonPlain.parentNode.insertBefore(prevButtonHttp, explain); | |
var editButtonPlain = doc.evaluate('id("body")//input[@name="edit"]', doc, null, 9, null).singleNodeValue; | |
var editButtonHttp = editButtonPlain.cloneNode(false); | |
editButtonHttp.value = 'この内容を登録する(http修正)', editButtonHttp.name = 'edit_http'; | |
editButtonHttp.addEventListener('click', function(){ | |
modifyHttp(); | |
editButtonPlain.click(); | |
}, false); | |
editButtonPlain.parentNode.insertBefore(editButtonHttp, explain); | |
})(content.document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment