ShufflR

Shuffle a YouTube playlist

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        ShufflR
// @namespace   VoteToClose
// @description Shuffle a YouTube playlist
// @include     https://www.youtube.com/playlist*
// @version     1
// @grant       none
// ==/UserScript==
html_md=true
main=()=>document.getElementById('browse-items-primary').children[0].children[0]
items=[]
//while(main().children[1]) main().children[1].click() //TODO: fix infinite while loop
content=main().children[0].children[0]
for(i=0;i<content.children.length;i++){
  el=content.children[i].children[3].children[0]
  text=el.text.trim().replace(/\s?\[[^\]]*\]\s?-?\s?/g, '')
  href=el.href
  items.push(md?`[${text}](${href})`:html?`<li><a href="${href}">${text}</a></li>`:html_md?`<li>[${text}](${href})</li>`:`${text}: ${href}`)
}
window.shuffled=[]
while(items.length){
  rand=Math.floor(Math.random()*(items.length))
  shuffled.push(items[rand])
  items.splice(rand,1)
}
if(html||html_md){
  div=document.createElement('div')
  div.innerHTML=`<ul style="list-style:none">${shuffled.join('')}</ul>`
  document.body.prependChild(div)
}