-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent-script.js
91 lines (72 loc) · 1.92 KB
/
content-script.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const IS_DEV = false
var molcar_js = {
car: {
run: "molcar-iwy-run",
find: "molcar-iwy-find"
},
init: () => {
var me = molcar_js;
me.randomly(me.createRunningcar, IS_DEV ? 100 : 30);
me.appearWhenFind();
},
randomly: (func, percent) => {
var ran = Math.floor((Math.random() * 100) + 1); // 1 ~ 100
if (percent < ran) return;
func();
},
appear: id => {
var me = molcar_js;
if (document.querySelector('#' + me.car[id])) return;
var img = document.createElement("IMG");
img.classList.add('molcar-iwy');
img.classList.add('always-enable-animations'); // fix for facebook
switch(id) {
case 'run':
img.src = chrome.runtime.getURL('./run.gif');
break;
// case 'find':
// img.src = browser.extension.getURL('./find.png');
// break;
}
img.id = me.car[id];
return img;
},
createRunningcar: () => {
var me = molcar_js;
var $car_run = me.appear('run');
if (!$car_run) return;
document.body.append($car_run);
setTimeout( () => {
$car_run.style.right = '-192px';
}, 1000)
},
appearWhenFind: () => {
var me = molcar_js;
var car = {
$body: me.appear('find'),
remove_timeout_id: null,
show: () => {
car.$body.style.bottom = 0;
document.body.append(car.$body);
car.$body.addEventListener('click', car.leave);
if (car.remove_timeout_id) clearTimeout(car.remove_timeout_id);
},
leave: () => {
car.$body.style.bottom = '-500px';
car.remove_timeout_id = setTimeout( () => {
car.$body.remove();
}, 1000);
}
}
document.addEventListener('keydown', e => {
// ctrl/command + f/g
if ((e.keyCode == 70 || e.keyCode == 71) && (e.ctrlKey || e.metaKey)) {
car.show();
}
if (e.keyCode == 27) {
car.leave();
}
})
}
};
molcar_js.init();