How to make tampermonkey interact with website

Viewed 45

So I'm looking for advice on where to start on creating a script that can do 2 things, find a specific button on a website and click it, the location of the button can be static or sometimes dynamic so I'm unsure how to make the script find and click, I can do coordinates but not dynamic finding

1 Answers

you have to make the script to run at document end ! // @run-at document-end

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://*/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    document.querySelectorAll(".js-vote-up-btn").forEach(button => {button.click()})
    // Your code here...
})();

this will upvote everything in the page (stack overflow)

Related