0

I am new to this site! :)

I want to ask a question, the question is that, I want a tampermonkey/greasemonkey script in which a button (example- next) becomes available somewhere on the page and on clicking the button, it basically goes to the 2nd ID and on clicking it again, it goes the 3rd ID and so on..

EXAMPLE:-

There is the following trimmed html code present on a page:-

        <div style="width: 2917px; left: -660px;" id="PlaylistVideos">

                <a href="/watch/video/1" class="PlaylistVideo" id="PlaylistVideo1" onclick="return switchToVideoAndDisableLink(this);" index="0" title="1"></a>

                <a href="/watch/video/2" class="PlaylistVideo" id="PlaylistVideo2" onclick="return switchToVideoAndDisableLink(this);" index="0" title="2"></a>

                <a href="/watch/video/3" class="PlaylistVideo" id="PlaylistVideo3" onclick="return switchToVideoAndDisableLink(this);" index="0" title="3"></a>

        </div>
    </section>

So, what I want to do is that a Next Button becomes available on the page and, on clicking it, it goes to the next id that is "PlaylistVideo2" and on clicking it again, it goes to the next id that is "PlaylistVideo3" and so on..

I tried many codes, but, I wasn't able to make it work..

Any help would be appreciated. Thanks in advance for anyone who can help me..

KJ1
  • 53
  • 1
  • 8
  • What do you mean by "it goes to the next id"? Like scrolls down? – MortenMoulder Apr 04 '16 at 19:02
  • For eg, this is the link link There are 6 videos in there but there is no next button, I have to manually click next video so what I want to do is that, using javascript a next button come up on the page and when I click on that it automatically goes to next video Hoping that I was able to explain correctly So, can you please tell me the code to do that? Thanks in advance for replying it is really appreciated! :D – KJ1 Apr 05 '16 at 16:48
  • *Sorry, this is the link:- [link](http://www.swagbucks.com/watch/video/1026938/london-has-fallen) – KJ1 Apr 05 '16 at 16:55

1 Answers1

0

i saw that you disabled link selected. however you could set a clase "selected" and use the same logic maybe something like this is useful...

function getNextVideo(){
    var next =     $('.sbPlaylistVideo div.sbPlaylistVideoNowPlaying').closest('a').next()
    if(next==null || next == 'undefined' || !next.is('a.sbPlaylistVideo'))
        next = $('a.sbPlaylistVideo:first')
    next.triggerHandler('click');
}

I test this function in your site, for console, and it's work. i hope this is useful

  • Thnx for answering but I think you didnt understood me correctly For eg, this is the link [link](http://www.swagbucks.com/watch/video/1026938/london-has-fallen) As you can see,I tried your code but it didn't worked There are 6 videos in there but there is no next button, I have to manually click next button so what I want to do is that, using javascript a next button come up on the page and when I click on that it automatically goes to next video Hoping that I was able to explain correctly So, can you please tell me the code to do that? Thanks in advance for replying it is really appreciated! – KJ1 Apr 04 '16 at 16:11
  • That is not my site btw.. but, can you please gimme the code to do the above? Thanks in advance! :D – KJ1 Apr 04 '16 at 16:19
  • sorry, my english is poor and i not understand correctly... however when arrived at my home i will try see better that. I 'm sorry miss wasting time – Hernán Daniel Garau Apr 04 '16 at 18:19
  • i change mi answer. i hope its useful – Hernán Daniel Garau Apr 04 '16 at 19:08
  • It says that SyntaxError: missing ) after condition.. :( Can you please help me with that? – KJ1 Apr 05 '16 at 14:19
  • Please do help me! It will really help me! :) – KJ1 Apr 05 '16 at 16:34
  • SORRY, I FORGOT A ' AFTER 'undefined. NOW IT'S WORK. if haven't next play first video – Hernán Daniel Garau Apr 05 '16 at 17:10
  • What does it do? I can see nothing happening in the page using Chrome! :( – KJ1 Apr 06 '16 at 13:40
  • i'm using chrome and this fx it's work.... and i create a button onclick="javascript:getNextVideo()" and work . i dont know if you give me your mail i send a video with me test... – Hernán Daniel Garau Apr 06 '16 at 17:33
  • That would really help me! :D Here is my mail:- ronaldasdzxc@email.com Tell me here, once you have sent the video. Thank you really very much! :) – KJ1 Apr 07 '16 at 13:15
  • i sent you the video – Hernán Daniel Garau Apr 07 '16 at 15:49
  • You are the best man! :D Thank you really very much, its working perfectly! :D You just made my week man! You are awesome! :) Thank you, I hope that I could repay you with something.. :) – KJ1 Apr 07 '16 at 16:08
  • thank you for yours words. nice site!. see you later. i hope to learn english and to be more expressive to talk. – Hernán Daniel Garau Apr 07 '16 at 17:50