Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Random Netflix List
  3. // @namespace https://www.netflix.com/
  4. // @include https://www.netflix.com/*
  5. // @version 1
  6. // ==/UserScript==
  7.  
  8. function Go(){
  9. if(!document.location.href.startsWith("https://www.netflix.com/browse/my-list")){
  10. //window.location.replace("https://www.netflix.com/browse/my-list");
  11. document.location.href = "https://www.netflix.com/browse/my-list?random=true";
  12. return;
  13. }
  14. Random();
  15. }
  16.  
  17. var results = [];
  18. function Random(play)
  19. {
  20. // Get a list of all titles
  21. var movies = document.querySelectorAll(".slider-item");
  22.  
  23. // pick a random number between 0 and length
  24. var random = Math.floor(Math.random() * movies.length);
  25.  
  26. // this is our movie
  27. var movie = movies[random];
  28. /*
  29. var org = movie;
  30. if(results.length < movies.length){
  31. while(results.includes(movie)){
  32. random++;
  33. if(random == movies.length){
  34. movie = org;
  35. break;
  36. }
  37. movie = movies[random];
  38. }
  39. } else {
  40. movie = org;
  41. results = [];
  42. }*/
  43.  
  44. if(!results.includes(movie)){
  45. results.push(movie);
  46. }
  47.  
  48. // we need to trigger three clicks, each one will make the next possible (due to dynamic rendering)
  49. if(movie == null){
  50. return;
  51. }
  52.  
  53. var a = movie.getElementsByClassName("slider-refocus")[0].getAttribute('href');
  54.  
  55. CreateButton(": " + random + "/" + movies.length);
  56.  
  57. document.location.href = "https://www.netflix.com" + a;
  58.  
  59. return;
  60. }
  61.  
  62. window.onload = Check;
  63.  
  64. function Check(){
  65. results = [];
  66. if(document.location.href.startsWith("https://www.netflix.com/browse/my-list?randomPlay=true")){
  67. Random(true);
  68. } else if(document.location.href.startsWith("https://www.netflix.com/browse/my-list?random=true")){
  69. Random(false);
  70. } else {
  71. CreateButton("");
  72. }
  73. }
  74.  
  75. function CreateButton(val){
  76. var input=document.createElement("input");
  77. input.type="button";
  78. input.value="Random" + val;
  79. input.onclick = Go;
  80. //input.style.position = fixed;
  81. input.style.bottom = "0px";
  82. input.style.right = "0px";
  83. input.style.width = "11%";
  84. input.style.border = "0px solid #FFFFFF";
  85. input.style.background = "000000";//"#141414";
  86. input.style.color = "#e50914";
  87. input.style.fontFamily = "'Helvetica Neue',Helvetica,Arial,sans-serif";
  88.  
  89. //document.body.appendChild(input);
  90. //document.getElementsByClassName("title").appendChild(input);
  91. var aTags = document.getElementsByTagName("a");
  92. var searchText = "My List";
  93. var found;
  94.  
  95. for (var i = 0; i < aTags.length; i++) {
  96. if (aTags[i].textContent == searchText) {
  97. found = aTags[i];
  98. //alert("found: " + found);
  99. break;
  100. }
  101. }
  102.  
  103. if(found !== null){
  104. found.parentNode.parentNode.parentNode.appendChild(input);
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement