-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFixGoogleSearchTabOrdering.js
52 lines (46 loc) · 1.88 KB
/
FixGoogleSearchTabOrdering.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// ==UserScript==
// @name FixGoogleSearchTabOrdering
// @namespace google.com
// @include https://www.google.com/search?*
// @include https://www.google.com/webhp?*
// @include https://www.google.ca/search?*
// @include https://www.google.ca/webhp?*
// @version 2.0
// @grant none
// ==/UserScript==
(function ()
{
var order = ["All", "Web", "Images", "Videos", "News", "Maps", "Books", "Apps", "Shopping", "Flights"];
function enableObserver() {
observer.observe(document.querySelector("#main"), { childList: true, subtree: true });
}
function disableObserver() {
observer.disconnect();
}
var observer = new MutationObserver(function(mutations) {
disableObserver();
fixTabs();
enableObserver();
});
enableObserver();
function fixTabs() {
var parent = document.querySelector("#hdtb-msb-vis");
if (parent == null) { return; }
var all = parent.querySelectorAll(".hdtb-mitem.hdtb-msel.hdtb-imb");
var tabs = parent.querySelectorAll(".hdtb-mitem");
var more = document.querySelector("#hdtb-more");
var tools = document.querySelector("#hdtb-tls");
while (parent.firstChild) {
parent.removeChild(parent.firstChild);
}
for (var i = 0; i < order.length; i++) {
for (var t = 0; t < tabs.length; t++) {
if (order[i] == tabs[t].textContent) {
parent.appendChild(tabs[t]);
}
}
}
parent.appendChild(tools);
}
fixTabs();
})();