Youtube: Auto-sort search results by upload date

Rewrites the URL of a YouTube search results page to automatically sort by video upload date, if the sort order is not already present

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name            Youtube: Auto-sort search results by upload date
// @description     Rewrites the URL of a YouTube search results page to automatically sort by video upload date, if the sort order is not already present
// @author          Archangel1C
// @license         GPL-3.0-only
// @namespace       https://github.com/Archangel1C
// @version         0.1
// @match           *://*.youtube.com/results*
// @run-at          document-start
// @grant           none
// @compatible      chrome
// @contributionURL https://flattr.com/@Archangel1C
// ==/UserScript==
//
// Sources/Influences:
// - https://stackoverflow.com/a/28956498/4423698


(function() {
// debugger instruction lets Chrome stop here
//  debugger;

    // https://www.w3schools.com/js/js_strict.asp
    // https://stackoverflow.com/a/1335881/4423698
    'use strict';

    var query = new URLSearchParams(window.location.search);
    // for(let param of query.entries()) console.log(param);

    // - do not change the sort order, if there is already one defined
    // - avoid infinite recursion
    if(query.get("search_sort") == null) {
        query.append("search_sort", "video_date_uploaded");
        window.location.search = "?" + query.toString();
    }
})();