Created
May 8, 2009 18:53
-
-
Save tsupo/108926 to your computer and use it in GitHub Desktop.
to use your favorite text-editor on Web forms
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
<script type="text/javascript"> | |
/* | |
$Id: extedit.js,v 1.6.1.1 2004/04/05 07:04:05 tsupo Exp $ | |
#Id: extedit.js,v 1.6 2004/03/28 17:41:49 ishinao Exp $ | |
Author: ishinao <[email protected]> | |
Licence: GPL | |
extedit - Webブラウザの入力フォームで好きなエディタを使う | |
see http://mylog.ishinao.net/id/1177 | |
*/ | |
//設定-------------> | |
//temporary file作成directory。空ならシステム設定temporaryパスになる。 | |
var tempdir = "c:\\user\\local\\menuExt\\log"; | |
//logファイル。空ならシステム設定temporaryパス+extedit.logになる。 | |
var logfile = "c:\\user\\local\\menuExt\\log\\extedit_log.html"; | |
//使用するeditorのpath。空なら「.txt」に関連づけられているエディタになる。 | |
var editor = "C:\\user\\local\\xyzzy\\xyzzy.exe"; | |
//使用済みのtemporaryを削除する? | |
var deletetemp = false; | |
//textarea名。優先順位が高い順に記述 | |
var targetItems = new Array( | |
"comment-text", // for TypePad, ココログ, ブログ人 | |
"text", // for Movable Type | |
"body", // for ishinao.net | |
"comment", // for blosxom, WebryBlog, doblog, goo BLOG, News Handler, 北国tv | |
"description", // for JUGEM | |
"cmnt", // for NewsCollector | |
"message" | |
); | |
//<-------------設定 | |
var window = external.menuArguments; | |
var page_url = window.document.URL; // ページのURL | |
var page_href = window.location.href; // 同上 | |
var title_txt = window.document.title; // タイトル文字列 | |
if ( page_href == "" ) { | |
page_href = page_url; | |
} | |
main(); | |
window.focus(); | |
self.close(); | |
function main() { | |
var event = external.menuArguments.event; | |
var current = window.document.elementFromPoint(event.clientX, event.clientY); | |
if (current && current.type == "textarea") { | |
doEdit(current); | |
return; | |
} | |
var elements = getAllTextarea(); | |
var names = targetItems; | |
for (ec = 0; ec < elements.length; ec++) { | |
for (nc = 0; nc < names.length; nc++) { | |
if (elements[ec].name.toLowerCase() == names[nc].toLowerCase()) { | |
doEdit(elements[ec]); | |
return; | |
} | |
} | |
} | |
if (elements.length > 0) { | |
doEdit(elements[0]); | |
return; | |
} | |
alert("no textarea"); | |
} | |
function zeroPadding(str) { | |
var s = "00" + str; | |
var len = s.length; | |
return s.substring(len - 2, len); | |
} | |
function monthString(date) { | |
return zeroPadding("" + (date.getMonth() + 1)); | |
} | |
function dateString(date) { | |
return zeroPadding("" + date.getDate()); | |
} | |
function hourString(date) { | |
return zeroPadding("" + date.getHours()); | |
} | |
function minuteString(date) { | |
return zeroPadding("" + date.getMinutes()); | |
} | |
function secondString(date) { | |
return zeroPadding("" + date.getSeconds()); | |
} | |
function doEdit(textarea) { | |
var fs = new ActiveXObject("Scripting.FileSystemObject"); | |
var date = new Date(); | |
if (tempdir == "") {tempdir = fs.GetSpecialFolder(2);} | |
var tempfile = tempdir + "\\"; | |
tempfile += "" + date.getYear() + monthString(date) + dateString(date); | |
tempfile += hourString(date) + minuteString(date) + secondString(date); | |
tempfile += ".txt"; | |
var body = textarea.value; | |
file = fs.CreateTextFile(tempfile, true); | |
file.Write(body); | |
file.close(); | |
shell = new ActiveXObject("WScript.Shell"); | |
var cmd = ""; | |
if (editor != "") { | |
cmd += "\""+editor+"\""+" "; | |
} | |
cmd += "\""+tempfile+"\""; | |
shell.run(cmd, 1, true); | |
body = ""; | |
file = fs.OpenTextFile(tempfile, 1); // read only で open | |
while (!file.AtEndOfStream) { | |
body += file.Read(1024); | |
} | |
file.close(); | |
textarea.value = body; | |
external.menuArguments.focus(); | |
if (deletetemp) { | |
fs.DeleteFile(tempfile); | |
} else { | |
var datestr = "" + date.getYear() + "/" + monthString(date) + "/"+ dateString(date); | |
datestr += " " + hourString(date) + ":" + minuteString(date); | |
file = fs.CreateTextFile(tempfile); | |
file.WriteLine("URL: " + page_href); | |
file.WriteLine("Date: " + datestr); | |
file.WriteLine(""); | |
file.Write(body); | |
file.close(); | |
if (logfile == "") { | |
logfile = tempdir + "\\extedit.log"; | |
} | |
if (fs.FileExists(logfile)) { | |
file = fs.OpenTextFile(logfile, 8); // 8 は append | |
} else { | |
file = fs.CreateTextFile(logfile); | |
} | |
if (logfile.substring(logfile.length-5,logfile.length) == ".html") { | |
file.WriteLine("<a href=\"" + page_href + "\">" + title_txt + "</a> (" + datestr + ")"); | |
} | |
else { | |
file.WriteLine("Date: " + datestr); | |
file.WriteLine("Title: " + title_txt); | |
file.WriteLine("URL: <a href=\"" + page_href + "\">" + page_href + "</a>"); | |
file.WriteLine("filename: " + tempfile); | |
file.WriteLine("-----------------------------------------------------"); | |
} | |
file.close(); | |
fs.DeleteFile(tempfile+".1~"); // for xyzzy (xyzzy が作り出したbackupファイルの削除) | |
} | |
} | |
function getAllTextarea() { | |
var elements = new Array(); | |
var doc = external.menuArguments.document; | |
for (fc = 0; fc < doc.forms.length; fc++) { | |
var form = doc.forms[fc]; | |
for (ec = 0; ec < form.elements.length; ec++) { | |
var element = form.elements[ec]; | |
if (element.type == "textarea") { | |
elements.push(element); | |
} | |
} | |
} | |
return elements; | |
} | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment