Created
February 1, 2010 13:10
-
-
Save cho45/291683 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Insert <del></del> as pressing Ctrl+D | |
// @namespace http://lowreal.net/ | |
// @include https://*.g.hatena.ne.jp/* | |
// ==/UserScript== | |
location.href = "javascript:"+encodeURIComponent(uneval(function () { | |
document.body.addEventListener("keydown", function (e) { | |
var target = e.target; | |
if (target.nodeName.toLowerCase() != "textarea") return; | |
if (e.ctrlKey && e.keyCode == 68) { | |
try { | |
e.stopPropagation(); | |
e.preventDefault(); | |
var cursor = target.selectionStart; | |
var value = target.value; | |
var lineStart = value.lastIndexOf("\n", cursor); | |
var lineEnd = value.indexOf("\n", cursor); | |
lineStart = lineStart == -1 ? 0 : lineStart; | |
lineEnd = lineEnd == -1 ? value.length : lineEnd; | |
var replace = value.substring(lineStart, lineEnd); | |
replace = replace.replace(/([-+]* *)(.+)/m, '$1<del>$2</del>'); | |
target.value = value.substring(0, lineStart) + replace + value.substring(lineEnd); | |
target.selectionStart = cursor + 5; | |
target.selectionEnd = cursor + 5; | |
} catch (e) { alert(e) } | |
} | |
}, true); | |
}))+"()"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment