Add Random Problem Button

Adds a button to choose a problem at random.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        Add Random Problem Button
// @namespace   Violentmonkey Scripts
// @match       https://seanprashad.com/leetcode-patterns/
// @grant       none
// @version     1.0
// @author      Mauville@Github
// @description Adds a button to choose a problem at random.
// ==/UserScript==
let randomProblem = () =>{
  let problems = document.querySelectorAll("tbody tr :nth-Child(2) a")
  let randomProb = problems[Math.floor(Math.random()*problems.length)];
  window.open(randomProb.getAttribute("href"), '_blank');
  
}

let navbar = document.querySelector(".nav, .navtabs")
let buttchild = document.createElement("li")
buttchild.innerHTML = '<button class="btn btn-primary">Random from Selection</button>'
buttchild.onclick = randomProblem;
navbar.appendChild(buttchild)