Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <meta http-equiv="x-ua-compatible" content="IE=9" />
- <hta:application id=hta border=dialog contextmenu=no maximizebutton=no />
- <script id=helptxt type=text>
- Choice, March 2022.
- https://www.reddit.com/user/jcunews1
- https://pastebin.com/u/jcunews
- https://greasyfork.org/en/users/85671-jcunews
- Usage: choice.hta [options]
- Options:
- /t {str} Set dialog title. Default is "Choice".
- /m {str} Set dialog message. Default is predefined.
- /u Allow multiple selections using checkboxes.
- /c {str} Set text of choices. "`" separated. Required.
- /d {num} Set index of default choice. Default: 1.
- If /u is used, multiple indexes are specified as command separated.
- /n {num} Set number of choice columns. Default: 1.
- /e {num} Set timeout in seconds. Default: 0 (no timeout)
- /o Choose OK on timeout instead of Cancel.
- /v Use selected choice's text instead of index, as output.
- /l Format the output to put each item in its own line. For use with /u.
- /f Only use file as output.
- If the user doesn't choose OK, no output will be written.
- Unless /f option is specified, the output is written to the standard output
- (of a console window or redirection). If standard output is not available,
- the output is written into a file named "choice.out" in the temporary
- directory.
- When /u is used, the output is a comma separated choice indexes.
- If /v is used, the output is "`" separated choice text.</script>
- <style>
- #fs{display:none}
- html{background:buttonface}
- #content{display:inline-block}
- #choices table{border-collapse:collapse}
- #choices table td:last-child{word-break:break-all}
- #cwrap{margin-top:1em;overflow-y:auto}
- label{display:block}
- input{vertical-align:middle}
- span{display:inline-block;vertical-align:middle}
- #actions{margin-top:1em;text-align:center}
- #buttons{display:inline-block;white-space:nowrap}
- #cancel{margin-left:3ex}
- </style>
- </head>
- <body>
- <object id=fs classid="clsid:0D43FE01-F093-11CF-8940-00A0C9054228"></object>
- <form id=content>
- <div id=message></div>
- <div id=cwrap><table id=choices></table></div>
- <div id=actions>
- <div id=buttons>
- <button id=ok>OK</button><button id=cancel>Cancel</button>
- </div>
- </div>
- </form>
- <script language=vbscript>
- sub document_onkeypress(e)
- if e.keycode = 27 then close
- end sub
- sub ok_onclick(e)
- e.returnvalue = false
- r = ""
- if ubound(achoices) > 0 then
- set cs = content.choice
- else
- cs = array(content.choice)
- end if
- i = 0
- for each c in cs
- if c.checked then
- if aline then
- if atext then
- r = r & c.value & vbcrlf
- else
- r = r & (i + 1) & vbcrlf
- end if
- elseif atext then
- r = r & c.value & "`"
- else
- r = r & (i + 1) & ","
- end if
- end if
- i = i + 1
- next
- if not aline then r = r & vbcrlf
- if not afile then
- on error resume next
- fs.getstandardstream(1).write(r)
- if err.number <> 0 then
- on error goto 0
- afile = true
- end if
- end if
- if afile then
- set f = fs.getspecialfolder(2).createtextfile("choice.out")
- f.write r
- f.close
- end if
- close
- end sub
- sub cancel_onclick(e)
- e.returnvalue = false
- close
- end sub
- sub timeout
- atimeout = atimeout - 1
- if atimeoutok then
- content.ok.innertext = "OK (" & atimeout & ")"
- else
- content.cancel.innertext = "Cancel (" & atimeout & ")"
- end if
- if atimeout <= 0 then
- clearinterval ti
- if atimeoutok then
- content.ok.click
- else
- close
- end if
- end if
- end sub
- sub help
- document.body.innerHTML = "<div style=""white-space:pre;" _
- & "display:inline-block;word-wrap:break-word;font:16px/16px monospace"">" _
- & mid(helptxt.text, instr(helptxt.text, vblf) + 1) & "</div>"
- resizeto screen.width, screen.height
- resizeto _
- document.body.children(0).offsetWidth + (screen.width - innerwidth) * 3, _
- document.body.children(0).offsetHeight + (screen.height - innerheight) * 2
- end sub
- function getArg
- s = m(i).submatches(0)
- if left(s, 1) = """" then
- if right(s, 1) = """" then
- s = trim(mid(s, 2, len(s) - 2))
- else
- s = ltrim(mid(s, 2))
- end if
- end if
- getArg = s
- end function
- function getOptValue
- i = i + 1
- if i < m.count then
- getOptValue = getArg
- else
- getOptValue = null
- end if
- end function
- atitle = "Choice"
- amessage = ""
- amulti = false
- adefault = 1
- acolumns = 1
- atimeout = 0
- atimeoutok = false
- atext = false
- aline = false
- afile = false
- set x = new regexp
- x.pattern = "\s*(""[^""]+""|\S+)"
- x.global = true
- set m = x.execute(hta.commandline)
- i = 1
- s = ""
- do while i < m.count
- if getArg = "" then
- achoices = empty
- exit do
- end if
- if left(s, 1) = "/" then
- s = ucase(s)
- select case s
- case "/T"
- atitle = getOptValue
- if isnull(atitle) then
- achoices = empty
- exit do
- end if
- case "/M"
- amessage = getOptValue
- if isnull(amessage) then
- achoices = empty
- exit do
- end if
- case "/U"
- amulti = true
- case "/C"
- achoices = getOptValue
- if isnull(achoices) then
- achoices = empty
- exit do
- end if
- case "/D"
- adefault = getOptValue
- if isnull(adefault) then
- achoices = empty
- exit do
- end if
- case "/N"
- acolumns = getOptValue
- if isnull(acolumns) then
- achoices = empty
- exit do
- end if
- on error resume next
- acolumns = clng(acolumns)
- if (err.number <> 0) or (acolumns < 1) then
- on error goto 0
- achoices = empty
- exit do
- end if
- on error goto 0
- case "/E"
- atimeout = getOptValue
- if isnull(atimeout) then
- achoices = empty
- exit do
- end if
- on error resume next
- if (err.number <> 0) or (atimeout < 0) then
- on error goto 0
- achoices = empty
- exit do
- end if
- atimeout = clng(atimeout)
- on error goto 0
- case "/O"
- atimeoutok = true
- case "/V"
- atext = true
- case "/L"
- aline = true
- case "/F"
- afile = true
- case else
- achoices = empty
- exit do
- end select
- else
- achoices = empty
- exit do
- end if
- i = i + 1
- loop
- if amessage = "" then
- if amulti then
- amessage = "Please select choice(s)."
- else
- amessage = "Please select a choice."
- end if
- end if
- if not isempty(achoices) then
- achoices = split(achoices, "`")
- adefault = split(adefault, ",")
- on error resume next
- if amulti then
- for i = 0 to ubound(adefault)
- err.clear
- adefault(i) = clng(adefault(i))
- if (err.number <> 0) or (adefault(i) < 1) then
- achoices = empty
- exit for
- end if
- if adefault(i) > (ubound(achoices) + 1) then _
- adefault(i) = ubound(achoices) + 1
- next
- else
- adefault(0) = clng(adefault(0))
- if (err.number <> 0) or (adefault(0) < 1) then
- achoices = empty
- elseif adefault(0) > (ubound(achoices) + 1) then
- adefault(0) = ubound(achoices) + 1
- end if
- end if
- on error goto 0
- end if
- if not isempty(achoices) then
- if acolumns > (ubound(achoices) + 1) then acolumns = ubound(achoices) + 1
- f = fs.getspecialfolder(2).path & "\choice.out"
- if fs.fileexists(f) then fs.deletefile f
- document.title = atitle
- message.innertext = amessage
- nr = round((ubound(achoices) + 1) / acolumns)
- if amulti then
- t = "checkbox"
- else
- t = "radio"
- end if
- for ri = 0 to nr - 1
- set r = choices.insertrow()
- for ci = 0 to acolumns - 1
- set c = r.insertcell()
- i = ci * acolumns + ri
- if i <= ubound(achoices) then
- c.innerhtml = "<label><table><tr><td><input name=choice type=" & t & _
- " /></td><td class=label></td></tr></table></label>"
- set l = c.queryselector("input")
- l.value = achoices(i)
- k = false
- for each j in adefault
- if j = (i + 1) then
- k = true
- exit for
- end if
- next
- l.checked = k
- c.queryselector(".label").innertext = achoices(i)
- end if
- next
- next
- document.queryselector("#choices input:checked").focus
- margin = content.offsetleft
- resizeto screen.width, screen.height
- border = screen.width - innerwidth
- caption = screen.height - innerheight - border
- wid = content.offsetwidth + (margin * 2) + int(border * 1.2)
- hei = content.offsetheight + (margin * 2) + caption + int(border * 1.5)
- if wid > int(screen.width * 0.7) then wid = int(screen.width * 0.7)
- a = int(screen.height * 0.7)
- if hei > a then
- cwrap.style.height = (cwrap.offsetheight - (hei - a)) & "px"
- hei = a
- end if
- resizeto wid, hei
- moveto int((screen.width - wid) / 2), int((screen.height - hei) / 2)
- if atimeout > 0 then
- if atimeoutok then
- content.ok.innertext = "OK (" & atimeout & ")"
- else
- content.cancel.innertext = "Cancel (" & atimeout & ")"
- end if
- ti = setinterval(getref("timeout"), 1000)
- end if
- else
- help
- end if
- </script>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement