Staredit Network > Forums > Technology & Computers > Topic: Trying to fix Youtube Favourites Search
Trying to fix Youtube Favourites Search
Jul 12 2012, 8:45 am
By: Sand Wraith  

Jul 12 2012, 8:45 am Sand Wraith Post #1

she/her

Hello. I'm trying to fix the userscript Youtube Favourites Search, originally developed by someone else, for Greasemonkey on Firefox 13.0.1.

My testing ground is https://www.youtube.com/my_favorites.

My problem is the script only works on the videos of the first page, instead of all of the Favourited videos. How can I fix this?

Here is the code currently:

Code
// ==UserScript==
// @name                       YouTube Favourites Search
// @alternative_name        YouTube Favorites Search
// @namespace                 localhost

// @author                     Marat Levit
// @description                 Allows users to search their favoured YouTube videos from the Favourites page.
// @copyright                 2009+, Marat Levit of mlCodes (www.mlevit.posterous.com)
// @license                     Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported; http://creativecommons.org/licenses/by-nc-sa/3.0/
// @homepage                 http://userscripts.org/scripts/show/62580

// @version                     2.0.0
// @date                       15/12/2011

// @updateURL                 http://userscripts.org/scripts/source/62580.user.js

// @include                     http://www.youtube.com/my_favorites*
// @include                     http://www.youtube.com/my_liked_videos*
// @include                     http://www.youtube.com/my_history*
// @include                     https://www.youtube.com/my_favorites*
// @include                     https://www.youtube.com/my_liked_videos*
// @include                     https://www.youtube.com/my_history*

// @require                 http://userscripts.org/scripts/source/52251.user.js

// @contributor                 Buzzy     (http://userscripts.org/scripts/show/52251)
// @contributor                 lobo235 (http://www.netlobo.com)

// @feedback                 For any comments, problems, suggestions, discussions or defects please use our UserVoice Forum here: http://mlcodesos.uservoice.com/pages/34350-youtube-favourites-search
// ==/UserScript==

//Call to check if an updated script is available
autoUpdate (62580, "2.0.0");

//Constants start
var SEARCH_BOX_ID = "fav-search-box";
var SEARCH_BUTTON_ID = "fav-search-button";
var SEARCH_CHECKBOX_ID     = "fav-search-checkbox";

var SEARCH_PARAMETER = "q";

var SEARCH_BOX     = "<input id='" + SEARCH_BOX_ID + "' name='" + SEARCH_PARAMETER + "' class='search-term' type='text' style='border:1px solid #999999; font-size:100% !important; height:1.38462em; padding:4px 1px 1px; vertical-align:top; width:25em; margin-right: 10px; height: 25px; margin-left: 35px; padding: 2px 4px 3px;'/>";
var SEARCH_BUTTON = "<button id='" + SEARCH_BUTTON_ID + "' class='yt-uix-button' style='margin-left: -6px' onclick='document." + SEARCH_BOX_ID + ".submit();'><span class='yt-uix-button-content'>Search My Videos</span></button>";

var ENTER_BUTTON_KEYCODE = 13;
var URL_ENCODE_REGEX = "(%[^%]{2})";

var NULL_VALUE = null;
var EMPTY_VALUE = "";

var MATCH_TERMS_PARAMETER = "m";
var SEARCH_URL = "https://www.youtube.com/my_favorites?sf=added&sa=0&pi=0&" + SEARCH_PARAMETER + "=";

//Retrieves the actual number of Favourites a user has instead of setting a high value like before.
var DISPLAY_UPPER_LIMIT = document.getElementById("vm-num-videos-shown").innerHTML;
//Constants end

//Only starts the script up once the page has finished loading. This will make sure that all the videos have already been loaded
//before the script starts searching through them.
window.addEventListener('load', function ()
{
    //Retrieve the videos array stored in the database
    var storedVideosArray = eval(GM_getValue("videos_array"));

    if (storedVideosArray == NULL_VALUE)
    {
        storedVideosArray = new Array();
        GM_setValue("videos_array", storedVideosArray.toSource());
    }

    //Get search query parameter
    var query = getParameter(SEARCH_PARAMETER);
    var matchTerms = getParameter(MATCH_TERMS_PARAMETER);

    var searchBar = document.getElementById("vm-page-subheader");
    var buttonBar = document.getElementById("vm-video-actions-inner");
   
    var newSearchBar = document.createElement("div");
    newSearchBar.setAttribute("id", "vm-page-subheader");
    newSearchBar.innerHTML = '<form action="" method="get" name="' + SEARCH_BOX_ID + '">' + SEARCH_BOX + SEARCH_BUTTON + '</form>';
    document.getElementById("yt-admin-content").insertBefore(newSearchBar, searchBar.nextSibling);

    var searchBox = document.getElementById(SEARCH_BOX_ID);
    var searchButton = document.getElementById(SEARCH_BUTTON_ID);
    var videoCSSClass = "video even";

    searchBox.focus();

    //Start searching if the user has searched
    if (query != EMPTY_VALUE)
    {
        //Creates a regular expression to get rid of special characters (e.g. space, comma, double quote etc)
        var urlEncodeRegex = new RegExp(URL_ENCODE_REGEX,'i');
        query = query.replace(urlEncodeRegex, " ");
       
        //Splits the search query into seperate terms
        var splitQuery = query.split(" ");
       
        var videoDIV = document.getElementById("vm-video-list-container");
        var videos = document.getElementById("vm-playlist-video-list-ol").getElementsByTagName("li")
       
        document.getElementById("vm-pagination").style.display = "none";
        storedVideosArray = new Array();
        //Run through all the videos on the page
        for (var i = 0; i < videos.length; i++)
        {
            var matchesFound = 0;
           
            //Retrieve the title elements for the video
            var title = videos[i].getElementsByClassName("vm-video-title-content")[0].innerHTML;
           
            //Rotate through each search term and see if a match can be found with the videos details
            for (var j = 0; j < splitQuery.length; j++)
            {
                //Make a regular expression from the search term, the 'i' is to make sure it is case insensitive
                var regex = new RegExp(splitQuery[j],'i');
                var match = title.search(regex);
               
                //Match found
                if (match != -1)
                {
                    matchesFound++;
                }
            }
               
            //If no match found then hide the video
            if (matchesFound == 0)
            {
                videos[i].style.display = "none";
            }
            //If user has selected "Match all terms" and not all terms have been matched then hide the video
            else if (matchTerms != EMPTY_VALUE && matchesFound != splitQuery.length)
            {
                videos[i].style.display = "none";
            }
        }
    }
}, true); // end window load event listener

//Retrieves the value of the parameter passed in: http://www.netlobo.com/url_query_string_javascript.html
function getParameter(name)
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
   
    if (results == null)
    {
        return "";
    }
    else
    {
        return results[1];
    }
}

function debug(message, type)
{
    if (type == 1)
    {
        var currentTime = new Date();
        GM_log(currentTime.getHours() + ":" + currentTime.getMinutes() + ":" + currentTime.getSeconds() + ":" + currentTime.getMilliseconds() + ": " + message);
    }
    else
    {
        GM_log(message);
    }
}





Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[02:13 pm]
Vrael -- pee poo sibling
[2026-6-28. : 7:00 pm]
Symmetry -- poo poo papa
[2026-6-28. : 2:46 pm]
lil-Inferno -- pee pee child
[2026-6-27. : 6:10 pm]
Ultraviolet -- sweet summer child
[2026-6-26. : 10:31 am]
NudeRaider -- blessed innocent soul knows nothing of the strife we had before EUDs were discovered :teehee:
[2026-6-23. : 3:29 am]
DarkenedFantasies -- Probably just didn't care. For example, at some point before release, they've updated the graphics of some of the Protoss buildings (Forge, CyberCore, Citadel, Observatory, Arbiter Tribunal), but instead of properly re-rendering them with edited 3D models, they did crappy copy-paste jobs on the rendered graphics.
[2026-6-22. : 8:35 pm]
Ultraviolet -- :wob:
[2026-6-21. : 11:38 pm]
Symmetry -- :wob:
[2026-6-21. : 4:56 am]
Ultraviolet -- I suppose we'll likely never know, but my guess would be that they already saw it operating successfully and there was no monetary incentive to finish the original work. And the dev cycle in old school Blizzard was so hectic, it's possible it just got forgotten about after the original game got released. Plus there's an element of existing MPQ files that were packaged with the original discs becoming outdated if they updated it. And it's not like they remade the original MPQs, they just made new ones for BW specifically
[2026-6-21. : 4:26 am]
Oh_Man -- so that makes me think maybe the theory they are unfinished is not true and its a deliberate design decision, coz why not finish them wen ur making brood war?
Please log in to shout.


Members Online: Excalibur, Roy, jy2413804