Full disclosure: I am very much a neophyte Applescript person (and Javascript). I have spent several hours trying to figure this out on my own, searching the Internet and trying many variations of Applescript, but no luck. I'm at a dead end without some help.
I'm modifying an Applescript that opens several web pages to lookup a word in Latvian - a language that I'm studying. The word I'm searching goes in the URL for most pages (i.e. Google Translate); however, the best dictionary I've found uses a simple form to enter a word - I can't embed the word in the URL. So, I've been trying to figure out how to enter the word on the form and "click" submit (Meklēt=search on the page in question).
The website in question is: http://www.latvianforyou.com/cgi-bin/l.pl
Here's the latest version of the Applescript I've tried:
tell application "Google Chrome"
activate
delay 3
execute javascript "document.getElementsByName('word').childNodes[0].value={{!VAR1}}"
execute javascript "document.forms[0].submit()"
end tell
The script doesn't seem to do anything. I get a "missing variable" back in the Applescript editor; I'm not sure that's an error. I've read that it simply means a null value was returned.
VAR1 is the word I'm searching/looking up and I know that variable is working - at least in the URLs of the other sites I'm searching. In any case, I have also tried directly entering the search term: "...value="akmens"" and "...value=123"" (akmens is "stone" in Latvian). However, nothing is entered into the search field.
I used the Inspect feature within Chrome to find the name of the input field, which is "word": ().
The page does open with my Applescript; it is the last tab in a new Chrome window (the other tabs in that Chrome window are the other sites that I'm searching). The script above switches over to Chrome to the correct tab - with the site I'm having trouble with. IOW - I don't think that selecting the correct Chrome window/tab is an issue.
I'm hoping that my mistake is relatively simple/easy to fix. If not - if entering some text in this field and "clicking" submit/search is much more complex, then I may just bag it and enter the word on that site manually.
Thanks very much in advance for any help.
Cheers
You may have already solved this but I have 2 possible solutions for you
pass in a full url such as
http://www.latvianforyou.com/cgi-bin/l.pl?word=1234
Use safari as I think Chrome is now broken
set thejavascript to "correctly_formatted_js"
tell application "Safari"
activate
do JavaScript (thejavascript & ";") as text in document 1
end tell
JAYTEE
Related
I was looking at popular LinkedIn post feature, the three dots seems to trigger html injection inside specific tags. My first question would be, why they did this choice, however what really interest me, is how can I debug and understand the mechanics involved, since when I inspect the page with firefox I cannot find the starting point nor the triggers to control this pop-up trigger?
I am making an engine on Scratch that works with a bookmarklet to provide more functionality without creating a Scratch extension. I have had no trouble reading variables through the DOM when they are showing. However, I am trying to find a way to change the values of the variables so that the bookmarklet can return data to the engine instead of just reading data. The link to the project is https://scratch.mit.edu/projects/574836102/.
I have searched Google and read the Blockly documentation, and couldn't find anything. Scratch has also appeared to have removed the "Blocks", "Variables", and "JavaScript" from the Blockly object. Does anyone know a way that I can write to project variables so the project can read them?
i have not found a way to make a Bookmarklet change a Variable, but i found an other idea...you could make in your scratch project a [ASK()] block and insert text in to the answer. i found 2 bookmarklets 1 does the inserting text and the other presses the enter button, but i did not found a way to get it displayed in the answer Variable... i think the problem is it does not record it as a Users input and does not store it...
https://scratch.mit.edu/projects/610547353/
my remix press space and then 1st bookmarklet and 2ond bookmarklet.
First bookmarklet
javascript: var els=document.getElementsByClassName("question_question-submit-button_3nYah"); if(els.length == 0) alert("Button not found"); else els[0].click();
Second Bookmarklet
javascript:(function(a){a.value=a.value.slice(0,a.selectionStart)+"Hello"+a.value.slice(a.selectionEnd);})(document.activeElement);
I have been trying to do some manipulation on webpages using JavaScript. So I started with the basic Google page(https://google.com).
I ran the command
document.getElementById('lst-ib').value = 'search_term';
Then after that tried running
document.getElementsByName('btnI')[0].click();
which is the I'm feeling Lucky button.
It is showing undefined on doing so.
But when I try only click on the I'm Feeling Lucky button without changing the content of the search bar, it works.
The target is to click the Search Button, it is also not working.
So I used the I'm Feeling Lucky button for testing to see if anything can be clicked.
The Same is happening in YouTube search bar as well
Any help or guidance would be much appreciated.
Also please note that I am N00b and trying to learn as I go :(
TLDR; The Idea is to simulate all the operation a user can do on the browsers using JavaScript.
document.getElementById('lst-ib').value = 'search_term';
document.getElementById('tsf').submit();
(or document.querySelector("form").submit();)
I'm not entirely sure what you're trying to achieve, but did you consider just using the queryparams? google.com?search=search_term ?
I found this ID simply by going to google.com, rightclicking on the input field, choose 'inspect element' and search for the first ancestor that is a 'form'.
I've added the Google Translate widget "Website Translator plugin" to my website. Translations works fine, but I'm not able to add corrections, nor can suggestions be made from the interface. Added corrections does not seem to apply, and while the select tooltips shows up, clicking the submit button gives an Javascript error.
Removing the associated google-translate-customization-meta tag makes it possible to send in suggestions, but these suggestions does not show up in the Translator Manager interface. What am I doing wrong? Is this feature no longer supported?
I have the exact same issue:
Contributions kick off a JS error
Furthermore, on Safari for Mac, I get a cross domain error when submitting the contributions.
Removing the META tag lets users submit but they don't show up in my Translation Manager. I believe these contributions are entered into Google's global TM (translation memory) instead.
I scoured the web for a solution to no avail. I am not sure what to do but I did find a solution - it's not great but it's my only recourse at the moment:
Use Google Translator Toolkit: https://translate.google.com/toolkit
Once you log in to the Toolkit interface, go to Tools on the left side and you should see "Translation Memories".
Click on that, and you should see the website that you added in the Translation Manager.
This indicates that you can use the toolkit to add custom translations to your site's TM (translation memory).
So, to submit translations:
click "Active" under "Translations" on the left side.
Then, click the big red "UPLOAD" button.
On the next screen, click on "Add content to translate" and select one of the options. For testing, you can simply choose "Input Text". Once you get the hang of this you can use "URL" to translate whole web pages.
Choose the languages you want to make suggestions/corrections to.
Important: next, under Pick a translation memory, select your site's TM. The Glossary should be useful too if you are using that.
Click Next.
On the next screen, click "No thanks" (I'll translate myself or invite friends for help.) I believe the idea here is you can pay someone to do it for you.
You will now be returned to the main Toolkit page
Now you can perform your translation corrections/suggestions:
In the Active Translations screen, click the translation document you just created.
This opens the text up in a Google Doc in translation mode, where you can see the translation and correct/change it.
After you're done, click on Complete on the upper right.
You're actually done at this point. It may take several minutes for the changes to take place. I found it took about 5 minutes. If you go to one of your web pages with the phrase you corrected, you should see your corrected text.
To verify:
Hopefully you will see the changes on your (translated) site
From Translation Toolkit, you can go to Tools->Translation Memories->(your website TM) then go to Search tab to search for submitted corrections in your TM
You can also go to your Google Translation control panel now, and click on Corrections, and see them there as well.
At the end of the day, this may actually be a better way to work on translations. I'm not sure yet.
I hope this helps.
I was having the same issue and it has recently appeared that Google are removing this feature from March 16th 2015, evidenced in the attached screenshot. This will be why we're seeing these unsupported issues with it.
Unfortunately they don't seem to have handled the features removal very gracefully and have wasted a few peoples time, including my own >:[
Im annoyed that this doesn't seem possible, but i wanted to check with the community to see if someone has developed a working version of something similar.
I'm a graduate student and spend a LOT of time online researching, and when I find that sweet paragraph that makes just the argument I've been searching for, I've gotta copy and paste it out of chrome (on mac os x) and into word (2011). I've built a "strip all formatting" macro that works well enough, but what i would like is a pipe from chrome into my open word document that gives me 1 key "send selection to word document" (like ~).
I've got the js working to get selected text and move it around, but i cannot seem to open the document i want to move the text into. Ideally, this would work as a chrome plugin (I've built them before), but I've seen no documentation about JS => Word on other platforms (obviously activeX controls dont work for me).
Any suggestions?
You can use an automator service to do this. Open Applications > Automator, and then create a service, which receives selected text (one of the built in defaults). This works in any app, and is accessible via the Services menu when you right click.
You can do this easily with TextEdit for example using these two actions:
Service receives selected text
New Textedit Document.
I've just tried it to confirm it. It can also copy rich text etc (including links) if you want. I imagine something similar is possible with word, and there is a built in service already to do the same if you have installed TextWrangler (another word processor).
JavaScript is contained within the browser for security reasons, so you will not be able to do it with JavaScript.
The best thing that i can come up with is to write a 'bot' kinda thing that just coppy pastes, so not for in an extention.