· 7 years ago · Dec 16, 2018, 06:58 PM
1(function (exports, require, module, __filename, __dirname) { const request = require('request-promise');
2const requestSt = require('request');
3const fs = require('fs');
4process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
5const jar = request.jar();
6
7function getHiddenInputValue(body, name) {
8 try {
9 return body
10 .replace('\n', '')
11 .match(new RegExp(`<input type="hidden" name="${name}" value="(.*?)">`, 'igm'))[0]
12 .match(/value="(.*?)">/)[1]
13 .split('"')[0].trim();
14 } catch(e) {
15 return null
16 }
17}
18function randomString(len) {
19 const charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
20 let randomString = '';
21 for (let i = 0; i < len; ++i) {
22 const randomPoz = Math.floor(Math.random() * charSet.length);
23 randomString += charSet.substring(randomPoz, randomPoz + 1);
24 }
25 return randomString;
26}
27
28const target_url = 'https://shikimori.org/animes/37991-jojo-no-kimyou-na-bouken-ougon-no-kaze';
29const target_id = 37991;
30const target_type = 'Anime';
31const user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36';
32
33
34
35const arr = fs.readFileSync('./data').toString()
36 .split('\n')
37 .map(i => i.trim())
38 .filter(i => i.length > 0)
39 .map(i => i.split(' '));
40
41async function start() {
42 for (const [username, email, pass] of arr) {
43 try {
44 const res = await doIt(username, email, pass);
45 await new Promise((r, rj) => {
46 setTimeout(() => { r(); }, 2000);
47 });
48 } catch(e) {
49 console.log(e);
50 }
51 }
52}
53start()
54 .catch(function (err) {
55 console.log(err);
56 });
57function doIt(username, email, pass) {
58 return request.get({
59 jar,
60 url: 'https://shikimori.org/users/sign_up'
61 })
62 .then(body => {
63 const authenticity_token = getHiddenInputValue(body, 'authenticity_token');
64 let login = randomString(15);
65 let pass = randomString(Math.floor(Math.random() * 5) + 10);
66 // console.log(`Login: ${login}\nPassword: ${pass}`);
67 // return new Promise((r, rj) => {
68 // requestSt.post({
69 // url: 'https://shikimori.org/users',
70 // jar,
71 // headers: {
72 // 'User-Agent': user_agent
73 // },
74 // form: {
75 // 'utf8': "✓",
76 // authenticity_token,
77 // 'user[nickname]': login,
78 // 'user[email]': login + '@gmail.com',
79 // 'user[password]': pass
80 // },
81 // },
82 // function (error, response, body) {
83 // r(body);
84 // });
85 // })
86 // Login
87 return new Promise((r, rj) => {
88 requestSt.post({
89 url: 'https://shikimori.org/users/sign_in',
90 jar,
91 headers: {
92 'User-Agent': user_agent
93 },
94 followAllRedirects: true,
95 form: {
96 'utf8': "✓",
97 authenticity_token,
98 'user[nickname]': 'skdkajsldjlasdjl',
99 'user[password]': '12345678'
100 },
101 },
102 function (error, response, body) {
103 r(body);
104 });
105 })
106 })
107 .then(() => {
108 return request.get({
109 url: 'https://shikimori.org',
110 jar,
111 headers: {
112 'User-Agent': user_agent
113 },
114 })
115 })
116 .then(() => {
117 return request.get({
118 url: 'https://shikimori.org/contests/112-luchshee-bozhestvo/rounds/4/match/80558',
119 jar,
120 headers: {
121 'User-Agent': user_agent
122 },
123 })
124 })
125 .then(body => {
126 const token = body.replace('\n', '').match(new RegExp(`<meta name="csrf-token" content="(.*?)"`, 'igm'))[0].match(/content="(.*?)"/)[1]
127
128
129 // const user_id = +body.match(/\["\/user-([0-9]+)"\]/igm)[0].match(/\["\/user-([0-9]+)"\]/)[1];
130 // return request.post({
131 // url: 'https://shikimori.org/api/v2/user_rates',
132 // jar,
133 // form: {
134 // 'frontend': 1,
135 // 'user_rate[user_id]': user_id,
136 // 'user_rate[target_id]': target_id,
137 // 'user_rate[target_type]': target_type,
138 // 'user_rate[status]': 'completed',
139 // 'user_rate[score]': 10
140 // }
141 // })
142 return request.post({
143 url: 'https://shikimori.org/votes?votable_id=80558&votable_type=ContestMatch&vote=no',
144 jar,
145 headers: {
146 'User-Agent': user_agent,
147 'Content-Type': 'application/x-www-form-urlencoded',
148 'x-csrf-token': token
149 },
150 form: {
151 'votable_id': 80558,
152 'votable_type': 'ContestMatch',
153 'vote': 'no'
154 }
155 })
156 })
157 .then(body => {
158 console.log(body)
159 })
160}
161});