Make input in program input value at website - input

I want a function in my JavaFX 2.0 program that takes user input and forwards it to a websites textfield, and then get the value the website returns. The website would be a site to check if the warranty for a spesific program is valid.
All the user would need to input is reg. ID and maybe program brand.
I'm just looking for ideas on how to do this, links or even code would be superb. I suspect it won't require that much code, but hey.. i've been surprised before!
Thanks! :)

A possible implementation algorithm:
Load the warranty check page in the WebView.
Monitor the webEngine.documentProperty to check for when the load has finished.
When the load has finished, use webEngine.executeScript to set the text field to the
required value and submit the form.
EITHER
a. monitor the webEngine.documentProperty some more, and, when the document has loaded, inspect the document (using either JavaScript or Java) to see if the warranty is valid.
OR
b. change the resultant warranty display page to call back into Java and notify your app of the warranty status.
Some background info
If you have control over the website page contents, then your implementation may turn out easier. But I think you should still be able to get the result you want without modifying the website.
There were some additions to the recent JavaFX 2.1 release to facilitate callbacks from Javascript to Java. The webview documentation you want to read is the sections "Processing JavaScript Commands" using the webEngine.executeScript method and "Making Upcalls from JavaScript to JavaFX" using JSObject.setMember.
You might want to also take a look at a Sample DatePicker for JavaFX using jQuery UI example I wrote. It demonstrates various methods for loading html into a WebView, invoking functions on the WebView from Java and getting the results of user interactions with the WebView back into Java. Not exactly what you are looking for, but perhaps the ideas in it may help.
Another option you have is just to:
Accept the registration id in a JavaFX control.
Create a java.net.URL and post to the webserver from your java app directly without using a WebView.
Parse the response from the webserver to extract out whether the warranty is valid.
This is the approach I might take for such a task - eliminating the use of WebView completely.

Related

Prevent my Elm app from crashing when a 3rd party changes the DOM

I have an Elm app. A while ago I realized that my app was crashing locally when I used FontAwesome icons. I came to understand that it happened because I chose SVG icons and therefore FontAwesome was modifying the DOM. That conflicted with Elm's VDOM mechanism.
This was easy to fix--I migrated to the CSS version of FontAwesome that uses pseudo elements. Recently some users complained that the app in production freezes and they showed screenshots of states that were not matching the log data I had. It took a while until I realized that all these users had Google Translate automatically translated the page for them. Google Translate clearly alters the DOM, so I'm not surprised that it made Elm crash.
How can I prevent my Elm app from crashing? Is there a way to be notified if a 3rd party changes the DOM? So that I could even notify the user that they have an extension that interferes with the app.
I had the same problem as you and solved it by migrating to the Elm-FontAwesome library. Basically all you have to do is replace this syntax:
i [ Svga.class "fas fa-check" ] []
with this one:
Icon.viewIcon Icon.check
You can have a look to the example project for more details: https://github.com/Lattyware/elm-fontawesome-example
Have a look here - How we made Elm and Google Translate work together.
Their approach is to hijack the Elm replaceData method that is called by Elm during dom updates using the function below. You would run this just before giving Elm control of the dom.
HTMLFontElement.prototype.replaceData =
function replaceData(_0, _1, string) {
this.parentNode.replaceChild(
document.createTextNode(string),
this
);
};
Apparently, "Google Translate replaces every text node in the DOM with a tag containing at least one more tag – one for each sentence". For example:
<span>Insurello. Rätt ersättning till alla</span>
is translated into
<span><font><font>Insurello. </font><font>The right compensation for everyone</font></font></span>
This method avoids attempting to edit the span and instead replace it with a new one. Once the node is added, Google Translate will translate that text.
I don't know about preventing the crashes, but I think you should be able to register changes to the DOM with the current mutation observer API.
Before that were several deprecated mutation events like DOMSubtreeModified that could also help, but well they are deprecated.
This problem is very closely linked to that of Google Maps or Google Places Autocomplete in Elm. The solution I've used in the past is to provide a childless div with an id I can point to from JavaScript.
Because the div is childless, Elm does not look under the hood to check whether it has changed internally.
Check out this blog post or google "maps in elm" for instructions on how to do this
-- EDIT --
Ive read the question better and this will probably not work for Google translate issues as it changes all text in the entire DOM. Ill leave it here incase the question brings otger people who have more regular problems caused when a 3rd party changes the DOM

Editing Video Effects panel on VLC for Mac

Ok so this question is actually in two parts.
I coded a video filter for VLC and I would like to add a control to the Video Effects panel on the OS X UI. So far I've been able to link my plugin the the UI by hijacking one of the existing controls, but this isn't ideal.
Now, if I open up the Xcode project (I'm running Xcode 6.3.1) and try to open the VideoEffect.xib file, I get the following error:
I tried to google this but it sounds like the only alternative would be to play archaeologist and dig up an old copy of Xcode 3. Is there any other way to be able to open this file and edit it somehow? I tried to look at the XML code but if I started to change that I'd do more damage than good.
The second thing I'd like to do is sending back values from the effect module to the UI. At the moment (by hijacking one of the existing sliders), all I can do is read a value from the panel with
config_ChainParse(p_filter, FILTER_PREFIX, ppsz_filter_options, p_filter->p_cfg);
p_filter->p_sys->i_factor = var_CreateGetIntegerCommand(p_filter, FILTER_PREFIX "factor");
and then, inside the callback function:
p_sys->i_factor = VLC_CLIP( newval.i_int, 0, 255 );
However, I haven't been able to write back the value. I'd like the filter to set p_sys->i_factor to a random value at start. This works (using var_SetInteger()), but it isn't reflected in the position of the slider in the Video Effect panel. I suspect I need to hack a bit deeper for that. Any ideas?
Regarding your first question with the xib-file. Consider downloading and using our forthcoming 3.0 code from git://git.videolan.org/vlc.git - it allows editing of said file without Xcode 3.
Regarding your second question, why would you want your video filter to interfere with the UI? This is not how the architecture of VLC works and there is no correct way to do it at this point. You would need to edit the core to do another global variable callback to ask the UI to reload the presented filter configuration.
Perhaps, if you give details about what your filter does and what you want to achieve, we find a more supported way :)

Show a single thumbnail when posting on facebook

A little background info is that my team and I developed a website for a Real Estate Agency and I've been assigned the task of setting the image of the currently selected property into facebook's sharing feature.
The webpage for the property is dynamic as there are several listings, so what I've done is select the first image that is loaded on the page and set it to the og:image meta tag.
Now let's say I copy the URL and post it on Facebook, it'll show the correct thumbnail, HOWEVER, it'll also show multiple thumbnails from other listings.
All images on the website are over 200 x 200px and are within an aspect ratio of 3:1.
My question is, how do I tell Facebook to only take my initial image and not grab others while it's as it.
Is there perhaps a SelectSingleImage property that I can apply?
I've already spent more time searching for the answer to this issue than I would have liked, so thanks for any help provided, it's much appreciated.
One method I use sometimes is to recognize Facebook's server and simply provide it with different data. This way you can actually only have one image on the page (as far as Facebook knows).
I don't know anything about vb.net, but here is a simple code sample in PHP. All it does is perform a regular expression on the user agent of the request to match it against the string "facebook".
$isFacebook = false;
if(preg_match("/facebook/",strtolower($_SERVER["HTTP_USER_AGENT"]))) {
$isFacebook = true;
}
Facebook may very well change their user agent signature one day, but for now, I'm pretty sure you'll be safe but keep synced with the Developers Blog and the Roadmap.
It seems that Facebook saved those images in cache for some bizarre reason, but to resolve this issue all I had to do was enter the URL into Facebook's Linter tool which in turn cleared the cache on their server.

Sencha Touch Passcode

Is there a control in Sencha Touch to show a passcode field like shown in picture below?
No theres no native component who does exactly this. But you can build it by yourself: its a form with 4 input fields and a dozen buttons. See documentation for more details: http://docs.sencha.com/touch/1-1/#!/api/Ext.form.FormPanel
No, you have to build and design this one completly by yourself.
Note: To get rid of the browser controls, you have to enforce that the application is running form the homescreen. You can control (with some Javascript) if the application is running MobileSafari or as a "Web App". (see: http://cubiq.org/add-to-home-screen as an example of such an implementation)
But, however, I would not recommend using such a component. A) This can confuse people and B) Can intent users to type in their regular passcode. As a developer I wouldn't be comfortable with that situation.

Getting DOM from page using Chromium/WebKit

Trying to get access to a page's DOM after rendering. I do not need to view the page and plan to apply this programmatically without any GUI or interaction.
The reason I am interested in post-rendering is that I want to know where objects appear. Some location information is coded in the HTML (e.g., via offsetLeft), but much is not. Also, Javascript can change the ultimate positioning. I want positions that are as close to what the user will see as possible.
I've looked into Chromium code and think there is a way to do this but there is not enough documentation to get started.
Putting it VERY simply I'd be interested in pseudo-code like this:
DOMRoot *r = new Page("http://stackoverflow.com")->getDom();
Any tips on starting points?
You should use the Web API wrapper that Chromium exposes; specifically, the WebDocument class contains the functionality that you need. You can call it like this:
WebFrame * mainFrame = webView->mainFrame();
WebDocument document = mainFrame->document();
WebElement docElement = document->docElement();
// Manipulate the DOM here using docElement
...
You can browse the source code for Chromium's Web API wrapper here. Although there's not much in the way of documentation, the header files are fairly well-commented and you can browse Chrome's source code to see the API in action.
It's difficult to get started using Chromium. I recommend looking at the test_shell application. Also, a framework like the Chromium Embedded Framework (CEF) simplifies the process of embedding Chromium in your application; I use CEF in my current project and I'm very satisfied with it.