-
Notifications
You must be signed in to change notification settings - Fork 8
/
test-action.ts
205 lines (179 loc) · 8.1 KB
/
test-action.ts
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// import useProxy from "puppeteer-page-proxy";
// import { checkForCookieBanner, checkForIssue, checkIfSuccess, clickOnButtonWithText, getIssue, wait, waitAndClick } from "./action";
// import { Stats, buildBrowser } from "./app";
// import { IpWorker, reportAlreadyUsed, reportGeoIssue } from "./ip_worker";
// import axios from "axios";
// let start = Date.now();
// const ipWorker = new IpWorker();
// function voteSuccess() {
// axios.get('https://orcalink.de/antenne-bayern-2').then(() => {
// console.log('✅ Voted successfully');
// }).catch(() => {
// console.log('❌ Could not send success to orcalink.de');
// console.log('retrying in 20 seconds');
// wait(20000).then(() => {
// axios.get('https://orcalink.de/antenne-bayern-2').then(() => {
// console.log('✅ 2nd try: Voted successfully');
// }).catch(() => {
// console.log('❌ Aborted send success after 2nd try');
// });
// });
// });
// }
// async function getOwnIp(): Promise<string> {
// const res = await axios.get('http://ip-api.com/json/');
// return res.data.query;
// }
// async function stickySession(stats: Stats) {
// const ownIp = await getOwnIp();
// console.log('Starting at', ownIp);
// const browser = await buildBrowser();
// const page = await browser.newPage();
// await ipWorker.prepareConnections(8);
// start = Date.now();
// let tor = await ipWorker.getUnusedInstance(58000);
// if (!tor.isMocked) {
// await useProxy(page, tor.proxyUrl);
// }
// await wait(1000);
// await page.goto('https://www.antenne.de/programm/aktionen/pausenhofkonzerte/schulen/10782-stdtisches-bertolt-brecht-gymnasium-mnchen', {
// waitUntil: 'load',
// timeout: 30000,
// });
// await clickOnButtonWithText(page, 'Jetzt abstimmen');
// await wait(1000);
// await page.setRequestInterception(true);
// async function waitIllCloseable(ip: string) {
// while (tor.info.ip === ip) {
// await wait(1000);
// }
// ipWorker.closeInstance(ip);
// }
// page.on('response', async (response) => {
// try {
// const url = response.url();
// if (url.includes('danke-fuer-deine-stimme')) {
// console.log('🔵 Checking for success via page...');
// await wait(1000);
// let success = await checkIfSuccess(page);
// if (success) {
// stats.totalVotes++;
// voteSuccess();
// } else {
// console.log('🔴 Checking for possible issues...');
// const REASON_GEO = 'IP-Adresse außerhalb von Deutschland';
// const REASON_ALREADY_USED = '1 Stimme innerhalb von 1 Minute';
// const possibleReasons = [
// REASON_GEO,
// REASON_ALREADY_USED,
// ];
// let detected = false;
// for (const reason of possibleReasons) {
// success = await checkForIssue(page, reason);
// if (success) {
// console.log(`❌ Issue detected: ${reason}`);
// if (reason === REASON_GEO) {
// await reportGeoIssue(tor.info.ip);
// waitIllCloseable(tor.info.ip);
// ipWorker.prepareConnections(1);
// detected = true;
// }
// if (reason === REASON_ALREADY_USED) {
// await reportAlreadyUsed(tor.info.ip);
// // flip a coin to decide if we should close the instance
// if (Math.random() > 0.5) {
// waitIllCloseable(tor.info.ip);
// await ipWorker.prepareConnections(1);
// }
// if (Math.random() > 0.7) {
// await ipWorker.prepareConnections(1);
// }
// detected = true;
// }
// break;
// }
// console.log(`▸ ${reason} is not the issue`);
// }
// if (!detected) {
// console.log('❌ Could not detect issue');
// const issue = await getIssue(page);
// const successreason = 'Wir haben deine Stimme gezählt.'
// if (issue.includes(successreason)) {
// console.log('No issues detected, html is just weird 😅');
// voteSuccess();
// stats.totalVotes++;
// return;
// }
// console.log(`❌ this might be the issue: ${issue}`);
// }
// }
// }
// } catch (error) {
// console.log('❌ Error while checking for success');
// console.log(error);
// }
// });
// page.on('dialog', async dialog => {
// console.log('❌ Dialog detected');
// console.log(dialog.message());
// await dialog.dismiss();
// });
// while (true) {
// const success = await waitAndClick(page, 'label.c-embed__optinbutton.c-button.has-clickhandler', 25000);
// if (!success) {
// await waitAndClick(page, 'button[id="voteAgainButton"]', 5000);
// await waitAndClick(page, 'label.c-embed__optinbutton.c-button.has-clickhandler', 4000);
// }
// await checkForCookieBanner(page);
// await waitAndClick(page, 'button[class="frc-button"]', 5000);
// await clickOnButtonWithText(page, 'Hier klicken zum Start');
// await checkForCookieBanner(page);
// const UNSTARTED = '.UNSTARTED';
// let value = UNSTARTED;
// let x = 0;
// while ((value === UNSTARTED || value === '.UNFINISHED' || value === '.FETCHING') && x < 80) {
// x++;
// try {
// value = await page.$eval('.frc-captcha-solution', (el) => el.getAttribute('value')) ?? UNSTARTED;
// } catch (error) {
// await checkForCookieBanner(page);
// }
// await wait(500);
// }
// wait(1000);
// await waitAndClick(page, 'button[type="submit"][id="votingButton"]', 5000);
// try {
// await page.waitForSelector('#voteAgainButton', {
// timeout: 10000,
// visible: true,
// });
// } catch (error) {
// console.log('❌ Could not find voteAgainButton');
// }
// const button = await page.$('#voteAgainButton');
// await button?.evaluate((element) => {
// element.classList.remove('disabled');
// });
// tor = await ipWorker.getUnusedInstance(58000, ownIp);
// if (!tor.isMocked) {
// await useProxy(page, tor.proxyUrl);
// }
// await waitAndClick(page, 'button[id="voteAgainButton"]', 15000);
// }
// }
// const stats: Stats = {
// totalVotes: 0,
// totalAttempts: 0,
// };
// setInterval(() => {
// const duration = Date.now() - start;
// const votesPerMinute = stats.totalVotes / (duration / 1000 / 60);
// // round with 2 digits
// const durationRounded = Math.round(duration / 1000 / 60 * 100) / 100;
// const votesPerMinuteRounded = Math.round(votesPerMinute * 100) / 100;
// console.log(`📊 Stats: ${stats.totalVotes} votes in ${durationRounded} minutes (${votesPerMinuteRounded} votes per minute)`);
// }, 10000);
// async function main() {
// stickySession(stats).catch(console.error);
// }
// main().catch(console.error);