YouTube - Search By Date Added

By JoeSimmons Last update Nov 17, 2009 — Installed 1,490 times.

There are 4 previous versions of this script.

// ==UserScript==
// @name           YouTube - Search By Date Added
// @namespace      http://userscripts.org/users/23652
// @description    Adds a "By Date" button next to the search button
// @include        http://*.youtube.com/*
// @include        http://youtube.com/*
// @copyright      JoeSimmons
// @version        1.0.1
// @license        Creative Commons Attribution-Noncommercial 3.0 United States License
// ==/UserScript==

var f = window.document.getElementsByName('searchForm')[0];

if(f) {
var a = document.createElement('a');
a.setAttribute('class', 'yt-button yt-button-primary');
a.setAttribute('href', 'javascript:void(0);');
a.addEventListener('click', function(){
var f = window.document.getElementsByName('searchForm')[0],
date_added = window.document.createElement('input');
date_added.setAttribute('type', 'hidden');
date_added.setAttribute('name', 'search_sort');
date_added.setAttribute('value', 'video_date_uploaded');
f.appendChild(date_added);
f.submit();
}, false);
var box = window.document.createElement('span');
box.textContent = 'By Date';
a.appendChild(box);

var oldbox = document.evaluate("//a[contains(@onclick,'searchForm') and @class='yt-button yt-button-primary']/span[.='Search']",document,null,8,null).singleNodeValue;
oldbox.parentNode.parentNode.insertBefore(a, oldbox.nextSibling);
}