Discussions » Development

Need help with one script and document.querySelector

§
Posted: 2018-12-21

Need help with one script and document.querySelector

I'm trying to make a simple script that would click on the "Starred" button automatically on https://tvlistings.zap2it.com to have automatically the starred channel without the need to click manually the button since the dafault is "All Channels".

I tried many methods but all seem to fail and I don't understand why ?

Here's the last script I've tried:

_// ==UserScript== // @name Zap2it Starred on open // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match https://tvlistings.zap2it.com/* // @grant none // @require http://code.jquery.com/jquery-latest.js // ==/UserScript==

setTimeout(function(){

document.querySelector('.grid-filter-controls__starred').click()

}, 25000);

_

I've put the setTimeout to let the page load before clicking on the button but it don't work.

The problem must be obvious but sadly I don't see what is wrong and why it don't work ??? :no_mouth:

§
Posted: 2018-12-21

you should click the a element in grid but not the grid itself,blow selector may work

document.querySelector('.grid-filter-controls__starred>a').click()
§
Posted: 2018-12-21

Thanks a lot it work now :smiley:

Could you explain me why it did not work when I use only the "'.grid-filter-controls__starred" class ?

Also where I can learn more about the syntax of putting element with ">" sign ?

Thanks again for the help ! 👍

§
Posted: 2018-12-22
Edited: 2018-12-22

because only the <a> element inside "'.grid-filter-controlsstarred" class element have click event listener witch can response your click in this page,usually you can see if element have event listeners in browser's element inspector ,the <a> element means a link that often can be click. want to know more about selector you can google about CSS selectors ,the ">" sign means Child combinator, `.grid-filter-controlsstarred>ameans the` type element inside ".grid-filter-controls__starred" element

§
Posted: 2018-12-26

Thanks a lot for your explanation 👍☺️

Post reply

Sign in to post a reply.