-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_scripts.js
More file actions
48 lines (39 loc) · 1.36 KB
/
content_scripts.js
File metadata and controls
48 lines (39 loc) · 1.36 KB
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
const DIFF_HORIZON = 50;
const DIFF_VERTICAL = 50;
const BIG_SIZE = "200px";
//aタグにホバー中かどうかの判別フラグ
let hovFlag = false;
// happy-catの表示タグ
const body = document.body;
const stalker = document.createElement('img');
const url = chrome.runtime.getURL("resources/happy.gif");
stalker.src = url;
stalker.id = "stalker";
// imgタグをマウスに追従させる処理
document.addEventListener('mousemove', function (e) {
stalker.style.position = 'fixed';
stalker.style.top = e.clientY - DIFF_VERTICAL + 'px';
stalker.style.left = e.clientX - DIFF_HORIZON + 'px';
});
//リンクへ吸い付く処理
const linkElem = document.querySelectorAll('a:not(.no_stick_)');
for (let i = 0; i < linkElem.length; i++) {
//マウスホバー時
linkElem[i].addEventListener('mouseover', function (e) {
hovFlag = true;
//マウスストーカーにクラスをつける
stalker.classList.add('hov_');
if (stalker.classList.contains('hov_')) {
stalker.style.top = e.clientY - DIFF_VERTICAL*2 + 'px';
stalker.style.left = e.clientX - DIFF_HORIZON*2 + 'px';
}
});
//マウスホバー解除時
linkElem[i].addEventListener('mouseout', function (e) {
hovFlag = false;
stalker.classList.remove('hov_');
});
}
if (body) {
body.appendChild(stalker);
}