javascript - .click()/.trigger('click') doesn't work with Tampermonkey in Spotify -


i'm trying write script skip next song on spotify after event, can't work.

i'm aware there lot of asked questions here, tried answers don't work me.

when try using chrome console these work fine, not in script:

document.getelementsbyclassname('spoticon-skip-forward-16')[0].click(); /*or*/ document.getelementsbyclassname('spoticon-skip-forward-16')[0].trigger('click'); 

jquery('spoticon-skip-forward-16:first').click(); /*or*/ jquery('spoticon-skip-forward-16:first').trigger('click'); 

   jquery('spoticon-skip-forward-16:first').each(function () {         jquery(this).css("color", "yellow");         var clickevent  = document.createevent("mouseevents");         clickevent.initevent ("click", true, true);         this.dispatchevent (clickevent);     }); 

jquery('spoticon-skip-forward-16:first') can substituted jquery('spoticon-skip-forward-16').get(0) or jquery('spoticon-skip-forward-16')[0], work in console not in tampermonkey.

i know event happens because i've set change button color before click , happens every time.

i no errors , tried try , catch nothing happens.

you forgot add . whenever referring element class in jquery need add . in front of class name.

mistake

jquery('spoticon-skip-forward-16:first').click(); /*or*/ jquery('spoticon-skip-forward-16:first').trigger('click'); 

change to

jquery('.spoticon-skip-forward-16:first').click(); /*or*/ jquery('.spoticon-skip-forward-16:first').trigger('click'); 

example jsfiddle

$('.spoticon-skip-forward-16').click(function(){  	console.log($(this).attr('id'));  });    $('.spoticon-skip-forward-16:first').click();   $('.spoticon-skip-forward-16:last').click();     $('.spoticon-skip-forward-16').each(function () {    $(this).css({      color: 'yellow',      background: '#000'    });    var clickevent  = document.createevent("mouseevents");    clickevent.initevent ("click", true, true);    this.dispatchevent (clickevent);  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <button type="submit" class="spoticon-skip-forward-16" id="btn1">  submit  </button>    <button type="submit" class="spoticon-skip-forward-16" id="btn2">  submit  </button>    <button type="submit" class="spoticon-skip-forward-16" id="btn3">  submit  </button>


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -