Greetings

On another site there is a button that you need to click automatically after updating the page. Button source code:

<li> <a original-title="" href="javascript:;" class="bump" data-tradeid="25346231" data-tipsy="Bump"> <div class="icon_bump"></div> </a> </li> 

The script will be executed in Greasemonkey (userscript). Please tell me how to do this or where to find the necessary information on such a problem.

    3 answers 3

    The fact that one attribute is randomized should have been clarified in the condition.
    So it will probably work:

     function load(){ var links = document.querySelectorAll('a.bump[data-tipsy="Bump"]'); // Ищем все ссылки с классом "bump" и data-tipsy="Bump", на data-tradeid можно забить, хотя если критично, можно и по нему искать Array.prototype.forEach.call(links, function(e){ // Проходим все найденные ссылки e.click(); // Кликаем! }); } document.addEventListener('DOMContentLoaded', load); // Чтобы скрипт сработал после создания элементов в DOM 
     <li> <a original-title="" href="javascript:" class="bump" data-tradeid="25346231" data-tipsy="Bump"> <div class="icon_bump"></div> </a> </li> 

    • It really works. And Greasemonkey behaves adequately and as it should be. Thank you so much! A little off topic, but please tell me a book on JS to start learning. I know a lot of advice on the Internet, but I see that you understand and rather tell me the right option. Thanks again. - excellproj
    • @mrforester, Any book on any PL will give only basic knowledge. They can be taken in almost any book, for example, many people praise "JavaScript. User's Bible" (it’s strange that it’s not a pogrommist ...) Danny Goodman. Personally, I got the basics from the site, not the books: javascript.ru A very extensive amount of mans and without water, which always infuriates books for beginners (save through "Ctrl + S", click here ... I, damn it, beginner not a child with Down syndrome!). But the main thing is the practice, with the basics you will not get further "Hello, world". Good luck in learning! - user31688

     var links = document.getElementsByClassName('bump'); for (var i = 0, link; (link = links[i]); i++) { if (link.getAttribute("data-tradeid") === '25346231') { link.click(); } } 
     <li> <a original-title="" href="javascript:;" class="bump" data-tradeid="25346231" data-tipsy="Bump" onclick='this.innerHTML = "clicked"'>no clicked <div class="icon_bump"></div> </a> <a original-title="" href="javascript:;" class="bump" data-tradeid="25346232" data-tipsy="Bump" onclick='this.innerHTML = "clicked"'>no clicked <div class="icon_bump"></div> </a> </li> 

    • data-tradeid = "". This is a random attribute. Unfortunately, the example does not work even with data-tradeid = "25346231". - excellproj
    • @mrforester, sorry, in FF innerText does not plow) - SanŚ́́́́́́́́́́́́

    If without jQuery, then as an option:

     // получаем в масcив все элементы с классом bump var l = document.getElementsByClassName("bump"); // .click() для первого елемента в масиве for (var i = 0; i < 1; i++) { l[i].click(); } 
    • Unfortunately it does not work. I tried to do jquery, but the page also uses it and this leads to a conflict. All javascript stops working on the page. - excellproj