Click button on a website using javascript from a chrome extension - javascript

I wanted to click on the Wiki button of the below given url
https://courses.edx.org/courses/BerkeleyX/CS100.1x/1T2015/wiki/BerkeleyX.CS100.1x.1T2015/
How can I click on the same button after every 5 minutes to get the latest result.
I wanted to do this in google chrome how can I do this using javascript or by using any chrome extension and code in the same?
Awaiting for your response!!

I think you are trying to do web scraping.
In javascript, you could try artoo.
artoo.js is a piece of JavaScript code meant to be run in your browser's console to provide you with some scraping utilities.

you can use setInterval and in setInterval you can trigger the click.
setInterval(function(){ alert("Hello"); }, 1000);

Related

Click using Javascript in Chrome

I am trying to click on page two using JS
https://www.abbreviations.com/sr
So I opened the console and put
document.getElementsByClassName('rc5')[1].click();
But it didn't click it and go to that page
This worked for me:
document.querySelectorAll(".pager > .rc5")[1].click()
what kind action you want to get as your 'click' result? first, it may be important to determine, that browser defines clicks as 'native' and 'generated by the code' and in the case of security and browsers policies.
but there is one smart method to work with DOM - headless browsers, like puppeteer.
you can do really anything with the webpage, using pure javascript.

Can I detect which javascipt functions do I trigger by clicking a button?

Is there any browser extension or any other way to detect which javascript functions do I trigger by pressing a button or a link? I know the basics of JS but I need to find which function is called by one event, but I cannot find it in the .js file, because the guy who wrote it was a total madman and named every variable with a single letter, so I want to find the specific part, instead of going through the whole file.
You may use chrome dev tool and a breakpoint directly from that element.
Chrome Dev Tool:
hope it will help.

Timer [Javascript / PHP / Python ...]

I've looked all over the net for a solution to the following problem: how do I create a timer that works in an inactive tab on any modern web browser?
Solutions appear to exist using JavaScript (using setInterval / setTimeout and using a Date object / timestamp), but these require the user to refocus the window to reload the timer. What if the timer finishes and the window is out of focus? I need the timer to make a noise or alert the user in some way, so these solutions do not apply.
I'm asking for a solution using any server-side or client-side language.
setInterval and setTimeout should work even if tab is not in focus (as any other actions).
Try to write this in console of new tab and switch to another tab:
setTimeout(function(){alert('hello')}, 5000)
After 5 seconds some kind of mark would appear on tab.
This is how it looks in firefox:

Create button on Firefox toolbar to execute JS

I need the toolbar button to execute my custom JavaScript code in Firefox.
Currently I just copy-paste this JS into console, but it is annoying.
What is the best way to create such button?
Use a https://en.wikipedia.org/wiki/Bookmarklet.
Example - create a shortcut to any site on in your browser and replace the URL address with similar code:
javascript:(function(){ alert('Hello!'); })();

Trigger Javascript function in Firefox (or any other browser) from an external program

I would like to trigger a Javascript function on an already existing website I don't own by pressing a key.
Example : trigger my_function('my parameter 1'); when I press the 1 key on the keyboard.
I can type manually the command on the Firefox's debugger console, it works. But I can't figure a simple way to trigger the Javascript function from an external program. Can I use Firefox command line ? EventGhost ? AutoHotKey ? Should I write a Firefox extension ?
If your solution implies the use of another web browser you're welcome !
I suggest you to look at this https://api.jquery.com/keydown/. Jquery could be the solution but the problem isn't clear. The site you're talking about is yours or you want to inject this trigger event from outside? Do you want this trigger to be injected every time?
If it's just a one-night stand you can use the browser console but if it's not you could be interested in developing an add-on or a greasemonkey extention.
Update: Yo can use eventghost, specifically the window plugin http://www.eventghost.org/docs/pluginlist.html, to trigger a keypress on firefox. Now you have to inject a javascript event handler in the page every time you visit it and most of the work is done.
Update 2:
Here's the basic add-on, ;) have fun
var self = require('sdk/self');
exports.main = function() {
require('sdk/page-mod').PageMod({
include: '*.org',
contentScript: 'document.onkeypress = function (e) {console.log(e.which);}'
});
}
To use this thing download the cfx-tools from the mozilla site (sorry I can't post more than 2 links) follow the first tutorial ( be sure to read how to use the cfx tools) and when you're ready use the code I posted above.
replace the "include" value with the name of the site of your interest
Replace console.log(e.which) with your code
Last suggestion:
document.onkeypress = function (e) { if(e.which == 49){ /* trigger my function if I press 1*/}}
Bye
OK ! I finally created an AutoHotkey script and Chrome because :
I met focus problems with Javascript injection when Flash was full screen
Chrome accepts javascript commands typed in Omnibox
Here's how the script manages a channel change request :
Press Escape to exit full screen
Click in a blank zone of the webpage to be sure it gains focus
Press F6 to activate Omnibox
Past Javascript code needed to change channel
Click in the flash video area
Press F to return full screen
I don't paste the script here because it's long and Stack Overflow code parser really don't like AutoHotkey code ! Just ask if you want it.
#EdoPut suggestion is way cleaner, but it didn't solved the focus problem when Flash went full screen. Anyway thanks again EdoPut for your efforts.

Categories

Resources