trying to call functions asynchronously in javascript (with angularjs) - javascript

I'm trying to call a function (for TTS) in phonegap that varies in length (i'm reading different news headlines) immediately following each headline, I have a voice recognition function, prompting the user for a voice command. like this...
navigator.tts.speak("If you would like to go to the next article, please say continue. Otherwise, say read me for another section");
$scope.reco();
The reco() calls voice recognition. I cannot get the previous call
navigator.tts.speak(*<news_headline.>*)
to finish before reco() is called. I am using angular, so I've tried using angular's promises ($q) (in a few different ways), but I can't seem to figure out how to get speak() to wait before reco() is called. Any suggestions?
One more dimension: I am using phonegap (almost entirely for android purposes), and in my little experience, it can cause a lot of trouble.
Any help regarding this would be appreciated.

I just checked the documentation for both TTS plugins listed on build.phonegap.com and both have callback functionality.
Try this:
navigator.tts.speak("If you would like to go to the next article, please say continue. Otherwise, say read me for another section",$scope.reco);

Related

How to wait for PyScript to be fully initialised (environment included)?

Good morning,
I would like to wait for a message (logged to my browser's console by a script I imported in my HTML tag) to be logged and then do an action in JavaScript.
For example, I'd like to wait for "ABCD:READY" to be printed in the console to use a function called finallyStart().
Is it possible ?
I thought I only needed to read the content of stdout to do this, but it looks like browsers don't call their console output stdout...
I also tried to find an answer in stackoverflow, but none of the posts I found were similar to the one I'm currently writing.
I'm a novice when it comes to JS in browsers (I've only used NodeJS for back-end), so thanks in advance for your help !
I faced the same problem and eventually came up with this hacky but working solution.
First create a dummy element in your html.
<div hidden id="start"></div>
Make an event for that element call a function in your js script.
document.getElementById("start").onclick = main;
Then trigger that event manually from your python script.
from pyscript import Element
Element("start").element.click()
No python code can execute until pyscript has finished initializing, so this seems like a reliable strategy. It would be even better if you could call the main() function directly from your python script, but i didn't have the patience to figure that out.
p.s. For some reason it takes a few seconds after pyscript has officially initialized for the code to kick off (at least in my test). I have no idea what's happening during that time, though i suppose it doesn't make a big difference to the already hefty build time.

How can I hook into new message windows using a bootstrapped Thunderbird extension?

I am currently trying to create a Thunderbird extension that write the recipients of a draft into the title of the composing window.
The default behaviour of Thunderbird is Compose: [Subject] (translated from German, YMMV), but I'd like to have something like this: Compose to [recipient(s)]: [Subject], so my time tracking software can keep track of the time I spend writing emails to clients.
My general idea for this extension is:
Hook into every composing window that is created / opened (I know they are reused) via event listeners
For every window, listen to the event recipients_changed, if such a thing exists. Otherwise, it's a bit more work (monitor all recipient input fields), but that should not be a problem.
Also listen for subject_changed (easier, because it's only one input) to prevent the default title overwriting our extended title.
I have already created a skeleton extension (bootstrapped), and the startup function in bootstrap.js is actually getting called. Since this is my first extension to Firefox/Thunderbird, this is the first success! :)
However, the only reason I know the function is called because the many exceptions my different trials have thrown are logged in the error console...
I have read many texts, but the learning curve seems to be pretty steep.
I learned that at the time startup is called, pretty much nothing is defined yet (my first attempts were alert and then settimeout).
This answer looked promising, but it throws the exception 'wm' is not defined:
https://stackoverflow.com/a/14291575/1886765
Maybe I used the code wrongly - hard to say for a beginner.
It would probably be easier to make a non-bootstrapped extension (I could overlay the compose window and wouldn't need step #1), but now that I've started this way, I'd like to finish it this way.
Maybe the solution is some XPCOM connector, but this field is still completely dark for me.
Could you kindly point me in the right direction?

Using JS (In FF-Pentadactyl), how to get a handle to site content like media players?

Using the Firefox Web Console (which can be brought up with control shift k ) I can easily access things like flowplayers.
jwplayer().play(), for example
The console even offers autocompletion suggestions for it.
What does the console do to be in that kind of, for my lack of words and knowledge, namespace?
I tried things like
content.document.getElementsByName('flvplayer').item(0)
Using Pentadactyls JS intepreter (accessed with :js)
This does seem to give me the player handle, or at least it prints out a <html:object> which corresponds to it.
Appending a .play() to it doesn't work, though. It's not a function.
What do I need to do to emulate the Web-Consoles way of doing it?
I realize that this might be a very spoonfeedy question, so if that is not acceptable then I'd still appreciate to get pointed into directions where I could possibly discover the solution myself by reading.
I tried searching for it myself but the terms seem to be quite ambiguous and I usually get results with people talking about their own sites, with scripts running inside of that 'namespace', not from outside like I am trying to do.
(Unless I am wrong about the concepts of inside and outside here.)
Cheers~~
The following command works for me; it defines the command ypl which
plays the YouTube video on the page
command! ypl open javascript:(function()
{content.document.getElementById('movie_player').playVideo()})()
Another example: this defines the ytr command which takes an integer argument and moves the current time position of the video by that amount in seconds
command! -nargs=1 ytr open javascript:(function(){var vid =
content.document.getElementById('movie_player'); vid.seekTo(vid.getCurrentTime() +
(<args>), true)})()
I hope that helps a bit. When I wrote those a while ago I may have tried :js and if it didn't work used :open javascript:....

How do the scores on this sports ticker update itself without ajax calls?

I was looking at scores at http://www.cbssports.com/nfl/scoreboard earlier and upon inspection of the code, I couldn't quite figure out how they update their scores.
I don't see any ajax calls and the games don't appear to be wrapped into iframes, etc.
Can anyone explain to me how this works?
It seems like they are using Flash code to update the scores. I disabled Flash in my browser and got the following message:
However, if you want to implement something like that without using a Plugin, you can use Websockets in Javascript.
Check out line 1884 of the scoreboard file. The storePlayers function will format that big string into sets of markup that is used in the ticker.

Plupload - Show a warning when using Flash Runtime and the Browser has no Flash

I need to show an info message when Plupload decides to use Flash but the Browser doesn't support it.
Currently nothing happens(TM) after plupload.init() and even though the API specifies a "runtime"-property which should name the used runtime I could find no way to find the currently used runtime.
This results in a non-working Upload-Button and the user does not understand whats going on.
What I'm looking for is something like this:
if(plupload.runtime == "flash" && !detect_flash()) {
$("#flash_warning").show();
}
Unfortunately, failed runtime loading attempts do not seem to trigger any event you can subscribe to.
So I don't see any way to subscribe to a failed runtime loading attempt aside from modifying plupload sources.
Open plupload.js or pluploadfull.js, look for the first match of '.init('.
What you want to subscribe to is the 'else' part of the callback function that processes loading attempt (just before calling w() at the end of the following line )
G.init(B,function(H){if(H&&H.success){B.features=F;B.runtime=G.name;B.trigger("Init",{runtime:G.name});B.trigger("PostInit");B.refresh()}else{w()}})
Anyway, best thing to do in my opinion is to follow the examples and have a disclaimer message in the container which is supposed to hold the uploader. This way, if all runtimes fail to load, you will have your disclaimer message.

Categories

Resources