jcunews

unicoder.vbs

Oct 25th, 2025
1,222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Unicoder v1.0.1, 2025-10-26.
  2. 'https://www.reddit.com/user/jcunews1
  3. 'https://pastebin.com/u/jcunews
  4. 'https://greasyfork.org/en/users/85671-jcunews
  5. '
  6. 'Convert text with source character set to Unicode.
  7. 'A tool to help displaying CJK text when system codepage is not set to CJK.
  8. 'For use in console only.
  9.  
  10. sub help
  11.   wsh.stdout.writeline "Usage: unicoder [/u] {charset} [input file]" _
  12.     & vbcrlf & "If not input file is specified, use standard input." _
  13.     & vbcrlf & "Use /u switch for UTF-8 output (for redirected output)."
  14.   wsh.quit 1
  15. end sub
  16.  
  17. if wsh.arguments.unnamed.count = 0 then help
  18. set ds = createobject("adodb.stream") : ds.open
  19. on error resume next
  20. cs = wsh.arguments.unnamed(0)
  21. ds.charset = cs
  22. if err.number <> 0 then
  23.   wsh.stdout.writeline "Invalid charset."
  24.   wsh.quit 2
  25. end if
  26. on error goto 0
  27. if wsh.arguments.unnamed.count >= 2 then
  28.   ds.loadfromfile wsh.arguments.unnamed(1)
  29.   ds.position = 0
  30.   s = ""
  31.   do while not ds.eos
  32.     s = s & ds.readtext(1)
  33.   loop
  34.   wsh.stdout.write s
  35.   wsh.quit
  36. else
  37.   ds.charset = "x-user-defined"
  38.   ds.writetext wsh.stdin.readall
  39.   ds.position = 0
  40.   ds.charset = cs
  41. end if
  42. s = ""
  43. do while not ds.eos
  44.   s = s & ds.readtext(1)
  45. loop
  46. if wsh.arguments.named.exists("u") then
  47.   set d = createobject("htmlfile")
  48.   d.open
  49.   d.write "<meta charset=utf-8><body><script id=z type=z>" & s & _
  50.     "</script><script language=jscript>" & _
  51.     "document.s=unescape(encodeURI(z.text))</script>"
  52.   d.close
  53.   s = d.s
  54.   on error resume next
  55.   for i = 1 to len(s)
  56.     c = mid(s, i, 1)
  57.     err.number = 0
  58.     wsh.stdout.write c
  59.     if err.number <> 0 then wsh.stdout.write chr(ascw(c))
  60.   next
  61. else
  62.   wsh.stdout.write s
  63. end if
  64.  
Advertisement
Add Comment
Please, Sign In to add comment