Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Random Netflix List
- // @namespace https://www.netflix.com/
- // @include https://www.netflix.com/*
- // @version 1
- // ==/UserScript==
- function Go(){
- if(!document.location.href.startsWith("https://www.netflix.com/browse/my-list")){
- //window.location.replace("https://www.netflix.com/browse/my-list");
- document.location.href = "https://www.netflix.com/browse/my-list?random=true";
- return;
- }
- Random();
- }
- var results = [];
- function Random(play)
- {
- // Get a list of all titles
- var movies = document.querySelectorAll(".slider-item");
- // pick a random number between 0 and length
- var random = Math.floor(Math.random() * movies.length);
- // this is our movie
- var movie = movies[random];
- /*
- var org = movie;
- if(results.length < movies.length){
- while(results.includes(movie)){
- random++;
- if(random == movies.length){
- movie = org;
- break;
- }
- movie = movies[random];
- }
- } else {
- movie = org;
- results = [];
- }*/
- if(!results.includes(movie)){
- results.push(movie);
- }
- // we need to trigger three clicks, each one will make the next possible (due to dynamic rendering)
- if(movie == null){
- return;
- }
- var a = movie.getElementsByClassName("slider-refocus")[0].getAttribute('href');
- CreateButton(": " + random + "/" + movies.length);
- document.location.href = "https://www.netflix.com" + a;
- return;
- }
- window.onload = Check;
- function Check(){
- results = [];
- if(document.location.href.startsWith("https://www.netflix.com/browse/my-list?randomPlay=true")){
- Random(true);
- } else if(document.location.href.startsWith("https://www.netflix.com/browse/my-list?random=true")){
- Random(false);
- } else {
- CreateButton("");
- }
- }
- function CreateButton(val){
- var input=document.createElement("input");
- input.type="button";
- input.value="Random" + val;
- input.onclick = Go;
- //input.style.position = fixed;
- input.style.bottom = "0px";
- input.style.right = "0px";
- input.style.width = "11%";
- input.style.border = "0px solid #FFFFFF";
- input.style.background = "000000";//"#141414";
- input.style.color = "#e50914";
- input.style.fontFamily = "'Helvetica Neue',Helvetica,Arial,sans-serif";
- //document.body.appendChild(input);
- //document.getElementsByClassName("title").appendChild(input);
- var aTags = document.getElementsByTagName("a");
- var searchText = "My List";
- var found;
- for (var i = 0; i < aTags.length; i++) {
- if (aTags[i].textContent == searchText) {
- found = aTags[i];
- //alert("found: " + found);
- break;
- }
- }
- if(found !== null){
- found.parentNode.parentNode.parentNode.appendChild(input);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement