通过chrome扩展打开网页

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
function Background () {
chrome.runtime.onInstalled.addListener(function (details) {
// only run the following section on install
if (details.reason !== "install") {
return;
}

chrome.tabs.create({
url: "https://webdesktop.net"
});
});
};

var background = new Background();

chrome.omnibox.onInputEntered.addListener(function (text) {
chrome.tabs.query({
'currentWindow': true,
'active' : true
}, function (tabs) {
chrome.tabs.update(tabs[0].id, {
url: "https://webdesktop.net"
});
});
});



chrome.browserAction.onClicked.addListener(function (activeTab) {
chrome.tabs.create({url: "https://webdesktop.net"});
});

禁用浏览器调试工具脚本

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
71
72
73
74
/**
* Created by OXOYO on 2018/11/9.
*
* 禁用调试工具
*/

const closeWindow = (loop) => {
clearInterval(loop)
// 关闭当前窗口
window.close()
// 将当前窗口跳转置空白页
window.location = 'about:blank'
console.clear()
}

export default {
init: function () {
window.onkeydown = window.onkeyup = window.onkeypress = function (event) {
// 判断是否按下F12,F12键码为123
if (event.keyCode === 123) {
event.preventDefault()
window.event.returnValue = false
}
}
// 为右键添加自定义事件
window.oncontextmenu = function (event) {
event.preventDefault()
return false
}
// 打开控制台的宽或高阈值
let threshold = 160
let div = document.createElement('div')
Object.defineProperty(div, 'id', {
get: () => {
closeWindow(loop)
}
})
// 循环检测
let loop = setInterval(function () {
let startTime = performance.now()
if (
// 方式一:检测console相关对象
(window.console && (console.firebug || console.table && /firebug/i.test(console.table()))) ||
(typeof opera === 'object' && typeof opera.postError === 'function' && console.profile.length > 0) ||
(typeof console.profiles === 'object' && console.profiles.length > 0) ||
// 方式二:检测窗口宽高
(window.outerWidth - window.innerWidth > threshold) ||
(window.outerHeight - window.innerHeight > threshold)
) {
closeWindow(loop)
}
// 方式三:复写div.id的getter方法,控制台打开时打印div会调用其div.id的get方法
console.log(div)
console.clear()
// 方式四:复写toString方法,控制台打开时打印devtools会调用其toString方法
let devtools = /./
devtools.toString = function () {
this.opened = true
closeWindow(loop)
}
console.log('%c', devtools)
console.clear()
// 方式五:检测代码耗时,devtool下代码运行速度降低
for (let i = 0; i < 1000; i++) {
console.log(i)
console.clear()
}
let diff = performance.now() - startTime
if (diff > 200) {
closeWindow(loop)
}
}, 1000)
}
}

package.json ~ ^ 等符号解读

See semver for more details about specifying version ranges.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
version Must match version exactly
>version Must be greater than version
>=version etc
<version
<=version
~version "Approximately equivalent to version" See semver
^version "Compatible with version" See semver
1.2.x 1.2.0, 1.2.1, etc., but not 1.3.0
http://... See 'URLs as Dependencies' below
* Matches any version
"" (just an empty string) Same as *
version1 - version2 Same as >=version1 <=version2.
range1 || range2 Passes if either range1 or range2 are satisfied.
git... See 'Git URLs as Dependencies' below
user/repo See 'GitHub URLs' below
tag A specific version tagged and published as tag See npm-tag
path/path/path See Local Paths below