-
Notifications
You must be signed in to change notification settings - Fork 64
/
hide_search_history.js
70 lines (64 loc) · 2.49 KB
/
hide_search_history.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// ==UserScript==
// @name 隐藏搜索历史
// @namespace http://tampermonkey.net/
// @version 0.4
// @description 隐藏搜索引擎下拉框的历史记录,目前仅适配Google
// @homeurl https://github.com/dengyuhan/LardMonkeyScripts
// @homeurl https://greasyfork.org/zh-CN/scripts/392368
// @author xiandanin
// @include *://encrypted.google.*/search*
// @include *://*.google*/
// @include *://*.google*/search*
// @include *://*.google*/webhp*
// @exclude *://*.google*/sorry*
// @grant none
// ==/UserScript==
(function () {
'use strict'
const deleteCache = []
function deleteFunc () {
// 删除按钮的元素
let elements = document.querySelectorAll(".sbai");
let deleteElements = []
let deleteParentElement = []
elements.forEach(function (element) {
// 没隐藏的说明可以删除
if (element.parentElement.style.display !== 'none') {
let parentElement = element.parentElement.parentElement;
let textElement = parentElement.querySelector('div > div:nth-child(2) > div:nth-child(1)');
let textContent = textElement.textContent;
if (textElement && textContent && deleteCache.indexOf(textContent) === -1) {
deleteElements.push(element)
deleteParentElement.push(parentElement)
deleteCache.push(textContent)
}
}
})
console.info("可删除元素%d个", deleteElements.length)
for (let i = 0; i < deleteElements.length; i++) {
deleteParentElement[i].style.display = 'none'
deleteElements[i].click()
setTimeout(function () {
deleteParentElement[i].style.display = ''
}, 1000)
console.info("删除搜索记录", deleteParentElement[i], deleteParentElement[i].textContent)
}
}
let inputElements = document.getElementsByName("q")
for (let i = 0; i < inputElements.length; i++) {
inputElements[i].oninput = function () {
setTimeout(deleteFunc, 150)
}
}
let target = document.querySelector(".UUbT9")
if (target != null) {
let observer = new MutationObserver(function (mutations, observer) {
deleteFunc()
})
observer.observe(target, {
characterData: true,
childList: true,
subtree: true
})
}
})()