Reorder Google Categories

Reorganizes the google search categories to the wanted order

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Reorder Google Categories
// @version      0.5
// @description  Reorganizes the google search categories to the wanted order
// @author       CoilBlimp
// @grant        none
// @include      http://*.google.com/search*
// @include      https://*.google.com/search*
// @include      https://*.google.*/search*
// @namespace https://greasyfork.org/users/392376
// ==/UserScript==
window.addEventListener('load', function() {
    let properOrganized = ["All", "Images", "Videos", "News", "Maps", "Books", "Shopping", "Flights", "Finance"],
        categoriesVisible = document.getElementById("hdtb-msb"),
        categoriesMore = document.getElementsByClassName("cF4V5c zriOQb UU8UAb gLSAk rShyOb")[0],
        categories = [];

    if(categoriesVisible === null || categoriesMore === null ){
        console.log("404 - Google categories not found");
        return;
    }

    let categoriesVisibleChildren = categoriesVisible.childNodes[0].childNodes[0].childNodes,
        categoriesMoreChildren = categoriesMore.childNodes,
		categoriesTools = categoriesVisible.childNodes[1];
	console.log(categoriesTools);

    categoriesVisibleChildren.forEach(function(item) {
        if(item.classList.contains("hdtb-msel")){
          	categories.push([item.innerText, item]);
        }
        else{
          	categories.push([item.firstChild.innerText, item]);
        }
    });
    categoriesMoreChildren.forEach(function(item) {
      	let inner = item.firstChild.firstChild.cloneNode(true);
      	inner.classList.remove("znKVS");
      	inner.classList.remove("tnhqA");
      	let outerDiv = document.createElement("div");
      	outerDiv.className = "hdtb-mitem hdtb-imb";
      	outerDiv.appendChild(inner);
        categories.push([item.innerText, outerDiv]);
    });
	console.log(categories)

    let result = [];

    properOrganized.forEach(function(key) {
        let found = false;
        categories.filter(function(item) {
			console.log(item[0]);
			console.log(key);
            if(!found && item[0] == key) {
                result.push(item);
                found = true;
				return false;
            }
			else{
				return true;
			}
        });
    });

	console.log(result);

    while (categoriesVisible.firstChild) {
        categoriesVisible.removeChild(categoriesVisible.firstChild);
    };

    result.forEach(function(item) {
      categoriesVisible.appendChild(item[1]);
    });

	categoriesVisible.appendChild(categoriesTools);
}, false);