-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace_script.js
More file actions
55 lines (45 loc) · 1.2 KB
/
replace_script.js
File metadata and controls
55 lines (45 loc) · 1.2 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
49
50
51
52
53
54
55
var probs;
chrome.storage.sync.get({
crazyProb: null,
normalProb: null,
grayProb: null,
gifProb: null
}, function(retrievedProbs) {
probs = retrievedProbs;
imgs = document.getElementsByTagName('img');
for (i = 0; i<imgs.length; i++) {
img = imgs[i];
original = img.src;
width = img.width;
height = img.height;
if ((width > 0) && (height > 0)) {
img.src = buildAddress(original, width.toString(), height.toString());
}
}
});
function buildAddress(original, width, height) {
base = buildBaseAddress();
if (base === undefined) {
return original;
}
return base + width + "/" + height;
}
function buildBaseAddress() {
baseString = "http://www.placecage.com/";
r = parseInt(Math.random() * 100);
if (r <= probs.crazyProb) {
return baseString + "c/";
}
r = parseInt(Math.random() * 100);
if (r <= probs.normalProb) {
return baseString;
}
r = parseInt(Math.random() * 100);
if (r <= probs.grayProb) {
return baseString + "g/";
}
r = parseInt(Math.random() * 100);
if (r <= probs.gifProb) {
return baseString + "gif/";
}
}