Prevents Google from changing the order of the search categories
当前为
// ==UserScript==
// @name Fixed Order Google Categories
// @version 0.2
// @description Prevents Google from changing the order of the search categories
// @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==
(function() {
let properOrganized = ["All", "Images", "Videos", "News", "Maps", "Books", "Shopping", "Flights", "Finance", "Personal"],
categoriesVisible = document.getElementById("hdtb-msb-vis"),
categoriesMore = document.getElementsByClassName("cF4V5c")[0],
categories = [];
if(categoriesVisible === null || categoriesMore === null ){
console.log("404 - Google categories not found");
return;
}
let categoriesVisibleChildren = categoriesVisible.childNodes,
categoriesMoreChildren = categoriesMore.childNodes;
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.cloneNode(true);
inner.classList.remove("f9UGee");
let outerDiv = document.createElement("div");
outerDiv.className = "hdtb-mitem hdtb-imb";
outerDiv.appendChild(inner);
categories.push([item.innerText, outerDiv]);
});
let result = [];
properOrganized.forEach(function(key) {
let found = false;
categories.filter(function(item) {
if(!found && item[0] == key) {
result.push(item);
found = true;
}
});
});
while (categoriesVisible.firstChild) {
categoriesVisible.removeChild(categoriesVisible.firstChild);
};
result.forEach(function(item) {
categoriesVisible.appendChild(item[1]);
});
})();