HTA. how to fade-out the embedded music mp3 (reload) [duplicate] - audio

This question already has answers here:
Fade out of a Mp3 song using javascript
(2 answers)
Closed 12 months ago.
I really need some help IN All the examples I found the fade out effect was relying on the "audio id" element :
<audio id="myAudio">
<source src="./LZ.mp3" type='audio/mp3'>
</audio>
in all cases my HTA will not play any sound
It seem I can only use the "embed" or even the "bgsound" method
but then I'm lost on applying the needed fade out functions
The following code is the simplified Hta script I use to start a splash together with the mp3 music file.
<html>
<head>
<script language="vbscript">
winWidth=350
winHeight=90
window.resizeto winWidth,winHeight
centerX=(screen.width-winWidth)/2
centerY=(screen.height-winHeight)/2
</script>
</head>
<head>
<HTA:APPLICATION
ID="start"
VERSION="2.0"/>
<body>
<button style=" title="">Starting </button> <p>
</body>
</head>
<script type="text/javascript">
function countdown() {
var i = document.getElementById('start');
{
window.close();
}
}
setInterval(function(){ countdown(); },30000);
</script>
<body>
<embed audio src="./LZ.mp3"></audio >
</body>
</html>
The splash will last 30 secs. and on closing will cut the sounds
I would like to add a fade out effect after 25 secs (5 secs. before the end)
(I cannot apply the fade out effect directly to the mp3 file because very quickly using another script I can chose to use any other mp3 )
the music will auto-start and the fade out effect should be automatic ( I mean no manual buttons)
EDIT: thanks to LesFerch my simplified hta now is playing + the music is closing with the aimed fade out effect. I'm just trying to add again the "Starting" title and the colors effects:
<body>
<button style= title="">Starting Firefox</button> <p>
<script language="VBScript">
Dim Intrval, direction
Dim c 'Used to increment
Function Color(i) : Color = "#" & Hex(i) & Hex(ii) & Hex(i) : end function
Sub Window_Onload
c = &hff
direction = -2
Intrval = setInterval("changeColor", 20)
end sub
sub changeColor
document.body.bgColor = Color(c)
c = (c + direction)
if c > (&hff - Abs(direction)) or c < Abs(direction) then direction = -direction
end sub
</script>

Using the answer in the duplicate link, I made some adjustments to eliminate an IndexSizeError, play the mp3 without a button, and make the fade last a reasonable amount of time. Since your sample code starts off in VBScript, I've assumed that's your preferred language. If not, I can post a JScript version as well.
Note: What makes this, perhaps, not a duplicate is that, for an HTA, the document mode must be declared and set to IE=9 or higher.
Note: Document mode IE=9 and higher are much more case sensitive. For example, screen.availWidth will work, screen.AvailWidth will throw an error.
<!DOCTYPE html>
<html>
<head>
<title>Fade Test</title>
<meta charset="UTF-8" http-equiv="X-UA-Compatible" content="IE=9">
<hta:application
id=oHTA
icon=SndVol.exe
>
<script language="vbscript">
Set oWSH = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
w = 350
h = 90
window.resizeTo w, h
window.moveTo (screen.availWidth - w)/2, (screen.availHeight - h)/2
MyPath = Mid(document.URL,8)
MyFolder = oFSO.GetParentFolderName(MyPath)
oWSH.CurrentDirectory = MyFolder
Sub window_onLoad
mp3.play
FadeOut
End Sub
Sub FadeOut
If mp3.volume >= 0.1 Then
mp3.volume = mp3.volume - 0.1
window.setTimeout "FadeOut()", 2000
Else
self.close
Exit Sub
End If
End Sub
</script>
<style>
</style>
</head>
<body>
<audio id="mp3">
<source src="./LZ.mp3" type='audio/mp4'>
</audio>
</body>
</html>

Related

How can I get a voluntary text fragment within start and end index

I need to get text within start and end index.
For example for a text like
"Fabric.js is a powerful and simple Javascript HTML5 canvas library"
for start index "0" and end index "8" it must show the result "Fabric.js".
Is there a method similar to getSelectedText(start, end)?
With the difference that I need to get a voluntary text fragment, not the selected one
Your question is kinda vague. I am not sure I understand what you mean by 'voluntary text fragment'.
However, if you are using a fabric.IText instance, you can use the following attributes to get/set the start & end of the text selection :
var canvas = this.__canvas = new fabric.Canvas('Canvas');
var myText = new fabric.IText('Fabric.js is a powerful and simple Javascript HTML5 canvas library',{
top: 50,
left: 50,
fontSize: 20
});
canvas.add(myText);
canvas.renderAll();
myText.enterEditing(); // Enter text editing mode
myText.selectionStart = 0;
myText.selectionEnd = 9;
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/4.3.1/fabric.js"
integrity="sha512-CzyxOXSECwo2nGJQZ2P8fdDxWVMVzn0jNdT2lYJ3afbqDJbaQ4qxgv9sLc85f6KP8HO2y929Bu+lnPKGC3ofSg=="
crossorigin="anonymous"></script>
<div class="container">
<canvas id="Canvas" width="700" height="300"></canvas>
</div>
<script src="canvas.js"></script>

Split CSV File, Name Based on Contents, Save As HTML

Click here to view table
I think this is a simple task, but I'm a biologist who only knows a teeny bit of code and after several days of trying to figure this out, I'm out of ideas.
Using terminal on a Mac. I have a CSV file that I want to split into separate files by row (162 rows) and I want to name the file by the content of the first and second column (genus_species). Then I need all 162 genus_species to be saved as HTML files.
I have only attempted the "splitting" part with Ruby (recommendation from StackExchange/overflow). Below are some of my attempts. They are frankensteins of helpful-ish forums, and after each I made a little comment on why it did not work.
Example HTML
<!DOCTYPE html>
<html><head>
<meta charset="UTF-8">
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script></head>
<body>
<h1><em><!-- Species name --></em> - <!-- Common name --></h1>
<h2>Status</h2>
<p></p>
<h2>Info</h2>
<p></p>
<h2>Time of year this bee is seen</h2>
<p></p>
<h2>Identification</h2>
<p></p>
<h3>Similar Species</h3>
<p></p>
<h2>Flowers</h2>
<p></p>
<h2>Sociality</h2>
<p></p>
<h2>Nest</h2>
<p></p>
<div id="refs" class="references">
--<br>More information:<br> <!-- Bug Guide --></div>
</body></html>
More Info Based on Comments
Here are some lines copied from the text file:
Genus,species,Common name,Status,Info,Time of year this bee is seen,Identification,Similar Species,Flowers,Sociality,Nest,Bug Guide,Discover Life,Other,
Agapostemon,melliventris,Honey-tailed Striped-Sweat bee,Secure G5,Excavates into deep burrows in ground nests,March-December,Agapostemon males have black and yellow stripes on the abdomen. Females have a yellow band on the lower margin of the clypeus.,All other Agapostemon species,Wide variety of plants,Solitary,"Deep, underground excavation",https://bugguide.net/node/view/70932,https://www.discoverlife.org/20/q?search=Agapostemon+melliventris,https://explorer.natureserve.org/Taxon/ELEMENT_GLOBAL.2.928401/Agapostemon_melliventris,
Agapostemon,sericeus,Silky Striped Sweat Bee,Secure G5,"Not choosy about lawn, as long as flowers are present",April-October,Agapostemon males have black and yellow stripes on the abdomen. A. sericeus males have a tooth on its hind femur. Female has metallic green abdomen.,All other Agapostemon species,Wide variety of plants,Solitary,Ground-nester in loamy soils,https://bugguide.net/node/view/83023,https://www.discoverlife.org/mp/20q?search=Agapostemon+sericeus,https://www.sharpeatmanguides.com/sweat-bees,
Agapostemon,splendens,Brown-winged Striped-Sweat Bee,Secure G5,This is the most common Agapostemon found in the southeast region,April-October,Agapostemon males have black and yellow stripes on the abdomen. A. splendens have brown wings. The female abdomen is often somewhat bluish.,All other Agapostemon species,"Jacquemontia reclinata, wide variety of plants",Solitary,Ground-nester in sandy soils,https://bugguide.net/node/view/74478,https://www.discoverlife.org/mp/20q?search=Agapostemon+splendens,,
Updated code I've tried based on comments.
This worked and I think it's heading in the direction I want, but it's hard to tell in the terminal window:
f = File.new("bee_key_fact_sheet .csv")
f.each_line { |line| puts line }
Currently playing with some kind of File.write line to add here and then close?
Attempt #1
file = File.open("bee_key_fact_sheet.csv")
awk
'(NR==1){header=$0;next}
(NR%l==2) {
close(file);
file=sprintf("%s.%0.5d.csv",FILENAME,++c)
sub(/csv[.]/,"",file)
print header > file
}
{f.write}'
File.close
#AWK not recognized, asks to "display all possibilities (y/n)" I tried returning "y" and "yes" and both times it says my answer is not recognized
Attempt #2
file_data = File.read("bee_key_fact_sheet.csv").split
#This works but splits by each comma
Attempt #3
file_data = File.foreach("bee_key_fact_sheet.csv") { |line| puts line}.split
#This returned something slightly less messy than splitting by each comma but got this error message "undefined method `split' for nil:NilClass"
Attempt #4
bee_key_fact_sheet.csv.foreach('so1.csv', :headers => true, :col_sep => ",", :skip_blanks => true) do |row|
id, name = row[0], row[1]
unless (id =~ /#/)
names = name.split
end
#This returned nothing
Your example of CSV input (bee_key_fact_sheet.csv):
Genus,species,Common name,Status,Info,Time of year this bee is seen,Identification,Similar Species,Flowers,Sociality,Nest,Bug Guide,Discover Life,Other,
Agapostemon,melliventris,Honey-tailed Striped-Sweat bee,Secure G5,Excavates into deep burrows in ground nests,March-December,Agapostemon males have black and yellow stripes on the abdomen. Females have a yellow band on the lower margin of the clypeus.,All other Agapostemon species,Wide variety of plants,Solitary,"Deep, underground excavation",https://bugguide.net/node/view/70932,https://www.discoverlife.org/20/q?search=Agapostemon+melliventris,https://explorer.natureserve.org/Taxon/ELEMENT_GLOBAL.2.928401/Agapostemon_melliventris,
Agapostemon,sericeus,Silky Striped Sweat Bee,Secure G5,"Not choosy about lawn, as long as flowers are present",April-October,Agapostemon males have black and yellow stripes on the abdomen. A. sericeus males have a tooth on its hind femur. Female has metallic green abdomen.,All other Agapostemon species,Wide variety of plants,Solitary,Ground-nester in loamy soils,https://bugguide.net/node/view/83023,https://www.discoverlife.org/mp/20q?search=Agapostemon+sericeus,https://www.sharpeatmanguides.com/sweat-bees,
Agapostemon,splendens,Brown-winged Striped-Sweat Bee,Secure G5,This is the most common Agapostemon found in the southeast region,April-October,Agapostemon males have black and yellow stripes on the abdomen. A. splendens have brown wings. The female abdomen is often somewhat bluish.,All other Agapostemon species,"Jacquemontia reclinata, wide variety of plants",Solitary,Ground-nester in sandy soils,https://bugguide.net/node/view/74478,https://www.discoverlife.org/mp/20q?search=Agapostemon+splendens,,
In this CSV, all the lines (including the header) end with a comma, so the last column probably doesn't mean anything and is to be discarded.
Also, you have commas inside the data (fields with double-quotes), so you'll need a real CSV parser to read the content of the file. BTW, you're right in choosing Ruby for this task because it includes a CSV parser in its core library.
Here's one way of reading your CSV (Edit: fixed CSV#Row conversion for older Rubys):
require 'csv'
filepath = 'bee_key_fact_sheet.csv'
CSV.foreach(filepath, headers: true) do |row|
genus, species = row[0], row[1]
#data = row[0...-1] # NOTE: not sure about the Ruby version compatibility
data = row.to_hash.values[0...-1]
filename = "#{genus}_#{species}.txt".tr("\0/",'')
filecontent = " * #{data.join("\n * ")}"
puts "\n#{filename}:\n#{filecontent}"
end
About tr("\0/",''): The characters that are allowed in a filename depend on the filesystem. All the filesystems (that I know of) ban at least the NULL-byte and the slash characters, so I strip them (but you may want to strip a few more).
Question: What exactly is the expected HTML output? A table row?
Update: HTML generation
When generating content programmatically, it's fundamental to escape your data for the right format/language/context. In Ruby you can escape HTML with CGI.escapeHTML
Your example of HTML output:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
</head>
<body>
<h1><em><!-- Species name --></em> - <!-- Common name --></h1>
<h2>Status</h2>
<p></p>
<h2>Info</h2>
<p></p>
<h2>Time of year this bee is seen</h2>
<p></p>
<h2>Identification</h2>
<p></p>
<h3>Similar Species</h3>
<p></p>
<h2>Flowers</h2>
<p></p>
<h2>Sociality</h2>
<p></p>
<h2>Nest</h2>
<p></p>
<div id="refs" class="references">
--
<br>More information:
<br> <!-- Bug Guide -->
</div>
</body>
</html>
I'll make a few changes to the HTML:
Add a title to the page.
Remove MathJax which seams unnecessary.
Convert the <h3> tag to <h2> because you use it only for "Similar Species". Changing it also permits the use of a loop while generating the HTML.
You have 2 links in the CSV that you don't use in the HTML: "Discover Life" and "Other", don't you want to display them ? I added the code for that ;-)
OK, first, you create a function that, given a CSV row, generates the corresponding HTML. Here I use ERB templating but you can do it directly with string literals (Edit: fixed ERB#result arguments for Ruby < 2.4.0):
require 'cgi'
require 'erb'
def renderHTML row
htmlsafe = row.each_with_object({}) { |(k,v),h| h[k] = CGI.escapeHTML v if v }
template = <<-'EOF'
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><%= "#{htmlsafe['Genus']} #{htmlsafe['species']}" %></title>
</head>
<body>
<h1><em><%= "#{htmlsafe['Genus']} #{htmlsafe['species']}" %></em> - <%= htmlsafe['Common name'] %></h1>
<% for key in ['Status','Info','Time of year this bee is seen','Identification','Similar Species','Flowers','Sociality','Nest'] %>
<h2><%= key %></h2>
<p><%= htmlsafe[key] %></p>
<% end %>
<div id="refs" class="references">
--
<br>More information:
<% for key in ['Bug Guide', 'Discover Life', 'Other'].select{ |k| htmlsafe[k] } %>
<br><%= key %>
<% end %>
</div>
</body>
</html>
EOF
#ERB.new(template, trim_mode: "<>").result(binding) # NOTE: only for Ruby >= 2.4.0
ERB.new(template, nil, "<>").result(binding)
end
Then you can call the previous function while reading each row of your CSV file:
require 'csv'
filepath = 'bee_key_fact_sheet.csv'
CSV.foreach(filepath, headers: true) do |row|
filename = "#{row['Genus']}_#{row['species']}.html".tr("\0/",'')
html = renderHTML row
puts "\n# #{filename}\n#{html}"
#File.write(filename, html)
end
Note: I commented out the File.write line that will create the HTML files.
Can you try this? It should be reading lines of file
f = File.new("name_of_file")
f.each_line { |line| puts line }
You can later save them as new file, more on that here:
How to create a file in Ruby

Uploading to the Web with VBA

<div id="xe-editor-container-1" class="input_area xpress_xeditor_editing_area_container" style="height: 400px;">
<iframe id="editor_iframe_1" allowtransparency="true" frameborder="0" src="http://my_URL.or.kr/xe/modules/editor/styles/default/editor.html" scrolling="yes" style="width: 100%; height: 400px; display: block;">
<html xmlns="http://www.w3.org/1999/xhtml>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="editor.css">
<title>XpressEngine</title>
</head>
<body class="xe_content editable"></body>
</html>
</iframe>
<textarea id="xpress-editor-1" rows="8" cols="42" style="display: none; width: 100%;"></textarea>
<textarea rows="8" cols="42" class="input_syntax " style="display:none"></textarea>
</div>
I want to copy two tables, ListObjects ("Tbl1") on Sheet1, ListObjects ("Tbl2") on Sheet2, and upload them as a single post on the web.
The range of the table can be changed every time.
Logging in to the web, navigating to the bulletin board, pressing the write button and typing the title succeeded.
But I have failed to upload the post.
Perhaps you can not find the bulletin board object.
Code I created by searching the web.
The HTML above is the board's HTML code.
With ie
.navigate "http://my_URL/offering"
ieBusy ie 'Procedure fetched as search (check the ready status)
.Document.getElementsByClassName("ico_16px write")(0).Click
ieBusy ie
Dim oTitle As Object, Ocontents As Object
Set oTitle = .Document.getElementsByname("title")(0) 'Sometimes fail(sometimes Nothing)
Set oContents = .Document.getElementsByClassName("xe_content editable")(0) 'evry time fail(=Nothing)
oTitle.Value = "my Title"
oContents.Value = ????
.Document.forms(0).submit 'I could not confirm it because it did not work anymore.
End With
Sub ieBusy(ie As Object)
Do While ie.Busy Or ie.readyState < 4
DoEvents
Loop
End Sub
title HTML
board HTML
1) Use an additional timed loop to set oTitle as per https://stackoverflow.com/a/55334183/6241235
2) Your oContents variable is selecting for an element which is inside an iframe I think. I would expect you to instead be targeting a textarea element. There are two that come after the iframe. The first has id xpress-editor-1

VBA question: Cannot get html element after clicked to another page

I wish to make a macro which can auto login a page and then autofill the search input field and finally web scraping the search result.
I have been struggling for a long time that I can successfully login the page. However, when I click the login button, I cannot further get the input tag for the search field as well as adding the value to that input field. The index of those input tags are absolutely correct.
Below is my vba script, many thanks!
Sub login_and_search()
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate "http://loginpage.html"
Do While .Busy Or _
.readyState <> 4
DoEvents
Loop
Set inputElement = .document.getELementsByTagName("input")
inputElement.Item(0).Value = "abc" 'username
inputElement.Item(1).Value = "xyz" 'password
inputElement.Item(2).Click
Do While ie.Busy Or _
.readyState <> 4
DoEvents
Loop
Set searchField = .document.getELementsByTagName("input")
searchField.Item(0).Value = "searchitems" 'search field
searchField.Item(1).Click
End With
End Sub
Below are the 2 html files, sorry for the too simplified html files as I roughly make them for testing the vba script only. The first one is the login page and the second one is the page after login.
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form class="" action="search.html" method="post">
<input type="text" name="" value="">
<input type="password" name="" value="">
<input type="submit" name="" value="login">
</form>
</body>
</html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form class="" action="searchResults.html" method="post">
<input type="text" name="" value="">
<input type="submit" name="" value="Search">
</form>
</body>
</html>
There is no error showing when running the macro, I think it is a logic error instead of syntax error.
Once again, thanks all!

How to disable up/down pan in UIWebView?

I want to have my web view pannable left and right but not up and down.
Is that possible?
Thanks.
ok, well wrap your one line of html like this:
<html>
<head>
<meta name = "viewport" content = "height = device-height, user-scalable = no, width = WIDTH">
</head>
<body>
...YOUR HTML
</body>
</html>
Replace width with the width of your content, and see how it works.

Resources