forked from bashir2017/medium-clap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
46 lines (32 loc) · 1.32 KB
/
content.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
//add event listener to the page
var actualCode = '(' + function(){
document.addEventListener('click', (e) => {
try {
if(e.target.childNodes[0].getAttribute('aria-label')){
let svg = e.target.childNodes[0]
let counter = 1;
let timer;
//change style of clap svg to green
svg.style.fill="green"
svg.style.stroke="green"
function triggerMouseEvent (node, eventType) {
if(counter > 100) clearInterval(timer)
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent (eventType, true, true);
node.dispatchEvent (clickEvent);
counter++;
}
timer = setInterval(() => {
triggerMouseEvent(svg, 'mousedown')
triggerMouseEvent(svg, 'mouseup')
}, 200)
}
} catch (error) {
//no need to console an error
}
})
} + ')();';
var script = document.createElement('script');
script.textContent = actualCode;
(document.head||document.documentElement).appendChild(script);
script.remove();