本帖最后由 CrLf 于 2015-7-12 04:31 编辑
回复 7# 867258173
ctrl+s 将结果以指定编码保存到原文件,更多语言在注释处自己加,界面不好看请自行改良:- <!-- :
- @start mshta "%~f0" & exit /b
- -->
- <script src=http://www.bathome.net/lib/diy/Libs.js></script>
- <script>
- var libs = ['Prototype','WSH','Function','iconv']
- for(var i in libs)Libs.get(libs[i])
- </script>
-
- <input type="file" id=filePath onchange=typefile() style="width:700px;float:left" />
- 原编码:<select id=charSetIn onchange=typefile()></select>
- 新编码:<select id=charSetOut onchange=savefile()></select>
- <br /><br />
- <textarea id=textarea style="width:100%;height:90%" ></textarea>
-
- <script>
- var list = [
- {text:'简体中文',value:'gb2312'},
- {text:'繁体中文',value:'big5'},
- {text:'日语',value:'shift-jis'},
- {text:'utf-8',value:'utf-8'},
- {text:'unicode',value:'utf-7'}
- //依此类推,要什么自己加
- ]
-
- list._each(
- function(o){
- charSetIn.add(new Option(o.text,o.value)),charSetOut.add(new Option(o.text,o.value))
- }
- )
-
- document.onkeydown = function(e){
- if(event.ctrlKey&&event.keyCode==83)savefile()
- }
-
- function typefile(){
- document.title = filePath.value + ' *'
- var bin = iconv.load(filePath.value)
- charset = iconv.checkBom(bin) ? charSetIn.options[charSetIn.selectedIndex].value : iconv.checkBom(bin)
- textarea.value = iconv.toStr(bin,charset)
- }
-
- function savefile(){
- if(/\*$/.test(document.title)){
- var fso = newcom('Scripting.FileSystemObject')
- var tmpFile = fso.GetTempName()
-
- iconv.saveText(
- textarea.value,
- tmpFile,
- charSetOut.options[charSetOut.selectedIndex].value
- )
-
- fso.CopyFile(tmpFile,filePath.value,true)
- fso.DeleteFile(tmpFile,true)
-
- document.title = filePath.value
- }
- }
- </script>
复制代码 妈了个鸡,试了一下午才明白 adodb.stream 出错的原因是不能写入被 input file 选中的文件,ado 真差劲 |