-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
85 lines (81 loc) · 2.36 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
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
chrome.runtime.onMessage.addListener((req, sender, sendRes) => {
let alltag = document.all;
if (req.msg === 'textcolor') {
Array.from(alltag).forEach((element) => {
element.style.color = req.txt;
});
} else if (req.msg === 'bgcolor') {
let bodys = document.body;
bodys.style.backgroundColor = req.txt;
} else if (req.msg === 'fontsize') {
Array.from(alltag).forEach((element) => {
element.style.fontSize = req.txt + 'px';
});
} else if (req.msg === 'pdfbtn') {
window.print();
} else if (req.msg === 'imagechange') {
let filename = [
'1.jpg',
'2.jpg',
'3.jpg',
'4.jpg',
'5.jpg',
'6.jpg',
'7.jpg',
'8.jpg',
'9.jpg',
'10.jpg',
];
let allimages = document.images;
Array.from(allimages).forEach((element) => {
let index = Math.floor(Math.random() * 10);
let file = 'images/' + filename[index];
let url = chrome.extension.getURL(file);
console.log(element);
element.setAttribute('src', url);
element.setAttribute('srcset', url);
console.log(index);
});
} else if (req.msg === 'effect') {
// Include CSS file
function addCSS(filename) {
var head = document.getElementsByTagName('head')[0];
var style = document.createElement('link');
style.href = filename;
style.type = 'text/css';
style.rel = 'stylesheet';
head.append(style);
}
switch (req.txt) {
case 'compress':
let path1 = chrome.extension.getURL('compress.css');
addCSS(path1);
break;
case 'flying':
let path2 = chrome.extension.getURL('flying.css');
addCSS(path2);
break;
case 'autozoominout':
let path3 = chrome.extension.getURL('autozoominout.css');
addCSS(path3);
break;
case 'rotate':
let path4 = chrome.extension.getURL('rotate.css');
addCSS(path4);
break;
case 'skew':
let path5 = chrome.extension.getURL('skew.css');
addCSS(path5);
break;
case 'vibratetext':
let path6 = chrome.extension.getURL('vibratetext.css');
addCSS(path6);
break;
}
} else if (req.msg === 'paragraphreplacer') {
let paragraph = document.getElementsByTagName('p');
Array.from(paragraph).forEach((element) => {
element.innerHTML = req.txt;
});
}
});