Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
165 lines (143 loc) · 4.65 KB
/
Copy pathindex.js
File metadata and controls
165 lines (143 loc) · 4.65 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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
console.log("Extension ran!");
// news feed parsing
var newsfeed = $("div[id^='feed_stream']").get(0);
var processed_stories = [];
var ads = ['compnerd.jpg', 'doge_ad.jpg', 'getprohockey.gif', 'getproshakew8.gif', 'hillary_server.jpg'];
var image_styling1 = {
width: 300 + 'px',
height: 'auto',
position: 'absolute',
'z-index': 10,
left: 10 + 'px',
}
var image_styling2 = {
width: 300 + 'px',
height: 'auto',
position: 'absolute',
'z-index': 10,
right: 150 + 'px',
}
// currently, the observer will find all news feed stories
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
var mutation_dom_id = mutation.target.id;
if (mutation_dom_id && mutation_dom_id.startsWith("hyperfeed_story")) {
if (processed_stories.includes(mutation_dom_id) == false) {
process_story(mutation.target);
}
}
});
});
var config = { attributes: true, childList: true, characterData: true, subtree: true};
observer.observe(newsfeed, config);
//observer.disconnect();
function process_story(story_elem) {
var story = $(story_elem);
var story_content = story.find(".userContent");
if (story_content.length == 0) {
// if there is no userContent div, then the story is empty or not loaded
return;
}
var story_height = story.height()
processed_stories.push(story_elem.id);
story.css('filter', 'blur(5px)');
var captcha_id = Math.round(Math.random() * 1000000000);
var captcha_elem = $("<button>Solve Captcha</button>");
captcha_elem.css({
position: 'relative',
top: - story_height/2 - 50 + 'px',
left: 164 + 'px',
'z-index': 100,
'text-align': 'center',
width: 'auto',
padding: 15 + 'px',
'font-size': 1.5 + 'em',
background: 'RGBA(74, 170, 165, 1.00)',
border: 'RGBA(74, 170, 165, 1.00)',
'border-radius': 3 + 'px',
cursor: 'pointer',
color: '#fff',
'font-weight': 700
})
captcha_elem.attr("id", "captcha_" + captcha_id);
captcha_elem.click(function() {
var init_captcha_event = new CustomEvent('init_captcha', { 'detail': this.id });
document.dispatchEvent(init_captcha_event);
});
var captcha_img1 = $("<img src=" + chrome.extension.getURL('acer-ad/pics/' + genAdImg()) + "></div>");
image_styling1['margin-top'] = - story_height/2 - 150 + 'px'
captcha_img1.css(image_styling1);
var captcha_img2 = $("<img src=" + chrome.extension.getURL('acer-ad/pics/' + genAdImg()) + "></div>");
image_styling2['margin-top'] = - story_height/2 + 'px'
captcha_img2.css(image_styling2);
story.after(captcha_elem);
story.after(captcha_img1);
story.after(captcha_img2);
}
document.addEventListener('init_captcha', function(e) {
var captcha_button_id = e.detail;
var captcha_id = captcha_button_id.split("_")[1];
var captcha_button = $('#' + captcha_button_id);
var captcha_elem;
var story_height = captcha_button.prev().prev().prev().height()
if (captcha_id % 2 == 0) {
captcha_elem = $("<iframe src='https://zlwaterfield.github.io/pic_captcha/'></div>");
captcha_elem.css({
position: 'relative',
top: -story_height/2 - 120 + 'px',
left: 65 + 'px',
width: 350 + 'px',
border: 0,
height: 200 + 'px',
'z-index': 11
});
} else {
captcha_elem = $("<iframe src='https://zlwaterfield.github.io/simon_says/'></div>");
captcha_elem.css({
position: 'relative',
top: -story_height/2 - 170 + 'px',
left: 65 + 'px',
width: 350 + 'px',
border: 0,
height: 380 + 'px',
'z-index': 11
});
}
captcha_elem.attr("id", "captcha_" + captcha_id);
captcha_button.after(captcha_elem);
var captcha_dom_elem = captcha_elem[0];
captcha_dom_elem.addEventListener("load", function() {
captcha_dom_elem.contentWindow.postMessage(captcha_id, "*");
});
captcha_button.remove();
});
window.addEventListener("message", receiveMessage, false);
function receiveMessage(event)
{
var origin = event.origin || event.originalEvent.origin; // For Chrome, the origin property is in the event.originalEvent object.
if (origin !== "https://zlwaterfield.github.io")
return;
captcha_success(event.data);
}
function captcha_success(captcha_winner_id) {
console.log("Winner winner chicken dinner for " + captcha_winner_id);
var captcha_iframe_elem = $('#captcha_' + captcha_winner_id);
var story_elem = captcha_iframe_elem.prev().prev().prev();
story_elem.css('filter', 'blur(0px)');
captcha_iframe_elem.prev().prev().remove();
captcha_iframe_elem.prev().remove();
captcha_iframe_elem.remove();
}
var prev = 0
function genAdImg() {
var ran = Math.floor(Math.random() * (ads.length))
if (ran == prev) {
if (ran === 4) {
ran = 0
} else {
ran++
}
prev = ran
}
return ads[ran]
}