-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblock-auto-add-opensearch.user.js
57 lines (51 loc) · 1.99 KB
/
block-auto-add-opensearch.user.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
// ==UserScript==
// @name 禁止自动添加自定义搜索引擎
// @version 0.1.2
// @description 用于禁止网站通过opensearch自动向浏览器添加自定义搜索引擎,以避免浏览器出现非常多的自定义搜索引擎。如需允许,请将其域名添加入排除名单,然后重新刷新页面即可。
// @author binsee
// @namespace https://github.com/binsee/tampermonkey-scripts
// @supportURL https://github.com/binsee/tampermonkey-scripts/issues
// @license GPL
// @run-at document-start
// @match *://*/*
// @exclude *://*.bilibili.com/*
// @exclude *://*.github.com/*
// @exclude *://*.google.com/*
// @exclude *://*.google.cn/*
// @exclude *://*.youtube.com/*
// @exclude *://*.yandex.com/*
// @exclude *://*.douban.com/*
// @exclude *://*.zhihu.com/*
// @grant none
// ==/UserScript==
let debugFlag = false
let jsName = '禁止自动添加自定义搜索引擎'
let logger = {
debug: createDebugMethod('debug'),
info: createDebugMethod('info'),
warn: createDebugMethod('warn'),
error: createDebugMethod('error')
};
function createDebugMethod(name) {
const bgColorMap = {
debug: '#0070BB',
info: '#009966',
warn: '#BBBB23',
error: '#bc0004'
};
name = bgColorMap[name] ? name : 'info';
return function () {
const args = Array.from(arguments);
args.unshift(`color: white; background-color: ${bgColorMap[name] || '#FFFFFF'}`);
args.unshift(`【${jsName}】 %c[${name.toUpperCase()}]:`);
console[name].apply(console, args);
}
}
(function () {
'use strict';
var elOpenSearch = document.querySelector('[type="application/opensearchdescription+xml"]');
if (elOpenSearch) {
logger.info('此站点配置了OpenSearch,以向浏览器添加自定义搜索引擎,已经对其进行屏蔽。如需同意此站点添加自定义搜索引擎,请为本脚本排除此站点域名。\nelOpenSearch:', elOpenSearch);
elOpenSearch.remove();
}
})();