Google Fixed Tab Order (Oct. 2021)

Stops google from reordering the tabs like wtf are you doing you piece of shit, stolen from https://greasyfork.org/en/scripts/18521-google-fixed-tab-order/code and updated for October 2021

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Google Fixed Tab Order (Oct. 2021)
// @namespace   google.com
// @description Stops google from reordering the tabs like wtf are you doing you piece of shit, stolen from https://greasyfork.org/en/scripts/18521-google-fixed-tab-order/code and updated for October 2021
// @include     https://www.google.com/search?*
// @include     https://www.google.com/webhp?*
// @version     3.1
// @grant       none
// ==/UserScript==

function contains(selector, text) {
  var elements = document.querySelectorAll(selector);
  return [].filter.call(elements, function(element){
    return RegExp(text).test(element.textContent);
  });
}

function getTab(text) {
    let e = contains('.hdtb-mitem', text);
    if (e != undefined && e[0] != undefined)
        return e[0];
    e = contains('.NZmxZe', text);
    if (e != undefined && e[0] != undefined)
        return e[0];
    e = contains('[jscontroller="nabPbb"]', text);
    if (e != undefined && e[0] != undefined)
        return e[0];
}

function moveToFront(text) {
    var tab = getTab(text);
    if (tab == undefined)
        return;
    var newtab = tab.cloneNode(true);

    var wrapper = tab.parentElement;
    wrapper.removeChild(tab);
    wrapper.appendChild(newtab);
}

function removeTab(text) {
    getTab(text).style.display = 'none';
}

function fixTabs()
{
    moveToFront('Images');
    moveToFront('Videos');

    moveToFront('Maps');
    moveToFront('News');
    moveToFront('Books');
    moveToFront('Apps');
    moveToFront('Shopping');
    moveToFront('Flights');

    moveToFront('More');
}

(function() {
    fixTabs();
    // setInterval(fixTabs, 1000);
})();