Guest User

WIP GPForums Youtube Autoplay

a guest
Dec 4th, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           GPForums Youtube Autoplay
  3. // @namespace      awt
  4. // @description    WIP - To autoplay embedded youtube clips one at a time
  5. // @include        http://www.gpforums.co.nz/*
  6. // ==/UserScript==
  7.  
  8. document.body.style.background = "#636363"; // Just to make it obvious script is running or not.
  9.  
  10. //alert("Youtube Embedded List Autoplay Script Started");
  11.  
  12. var nodeList = document.getElementsByTagName("embed"); // Get all embedded objects
  13. var objects = new Array();
  14.  
  15. // Convert NodeList "nodeList" to an Array of Nodes "objects"
  16. for (i=0;i<nodeList.length;i++){
  17.    objects.push(nodeList[i]);
  18. }
  19.  
  20. // Ensure embedded objects are YouTube, and remove duplicates.
  21. i = 0;
  22. do {
  23.    var stringA;
  24.    var stringB;
  25.    
  26.    // Get source of the embedded object
  27.    var attributes = objects[i].attributes;
  28.    var source = attributes.getNamedItem("src");
  29.    
  30.    // Checks that embedded file is youtube.  **Don't know if this works, haven't come across any non-youtube embeds.**
  31.    if (source == -1|| source.nodeValue.indexOf("http://www.youtube.com/v/") == -1) {
  32.       alert("Non-YouTube embedded object found");
  33.       // ... and will need to write something else here, if this situation ever arises.
  34.    }
  35.    
  36.     // Ensure each equivalent (same source) object is only present once in the array.
  37.     stringA = source.nodeValue;
  38.     j = 0;
  39.     do {
  40.         var compAttributes = objects[j].attributes;
  41.         var compSource = compAttributes.getNamedItem("src");
  42.        
  43.         stringB = compSource.nodeValue;
  44.        
  45.         if (stringA == stringB &&  !(i==j) ){ // If same source but not the same index
  46.            objects.splice(j,1);
  47.            j--; // array length changed by splice, so need to re-check this index
  48.         }
  49.        
  50.         j++;
  51.        
  52.     } while (j < objects.length);
  53.    
  54.     i++;
  55. } while (i < objects.length);
  56.  
  57.  
  58. alert(objects.length + " Youtube clips lined up.");
  59.  
  60.  
  61.  
  62. // *** All code below here is things i'm not sure about *****
  63.  
  64. // Add the <object.. (parent node of <embed..) to the objs array
  65. // Not sure which
  66. var objs = new Array();
  67.  
  68. for(var k = 0; k < objects.length; k++){
  69.    var parent = objects[k].parentNode;
  70.    objs.push(parent);
  71. }
  72.  
  73.  
  74.  
  75.  
  76. // The big FFFFUUUUU.   This is supposed to be called automatically when the embedded player(s?) are ready to accept commands.
  77. function onYouTubePlayerReady(playerid){
  78.    alert("TYPR!!!!!!");
  79. }
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment