@JSer/

Change.org bot

Nodejs

No description

fork
loading
Files
  • index.js
  • package-lock.json
  • package.json
index.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
// The petition URL
const link = encodeURI("https://www.change.org/p/民間人權陣線-civil-human-rights-front-全球聯署-反送中-民意不可欺-為香港企硬-global-signing-against-extradition-to-china");

// The petition ID (Automatically extract ID if set to undefined)
let id = undefined;

// Signing interval in ms
const interval = 200;

const express = require('express');
const app = express();

app.get('/ping', (req, res) => res.send(new Date()));

app.listen(3000);

const rp = require('request-promise');

const states = ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY'];

const userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0";

async function sign() {
  const cookieJar = rp.jar();
  const body = await rp({
    method: 'GET',
    uri: link,
    jar: cookieJar,
    headers: {
      'Referer': link,
      'User-agent': userAgent
    }
  });

  if(!id) {
    // handle two formats: "id":xxxxxxxx and "id":"xxxxxxxx"
    let idIndex = body.search(/"id":"?[0-9]+"?/);
    const from = body[idIndex + 5] == '"'? 6: 5
    id = body.substr(idIndex + from, 8);
    
    console.log("Petition id: " + id);
  }
  
  const tokenIndex = body.search(/"csrfToken":"[a-zA-Z0-9_]+"/);
  const token = body.substr(tokenIndex + 13, 32);
  

  const res = await rp({
    method: 'POST',
    headers: {
      'X-CSRF-Token': token,
      'Referer': link,
      'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0'
    },
    uri: 'https://www.change.org/api-proxy/-/signatures/14015995',
    jar: cookieJar,
    json: true,
    body: {
      "petition_id": id,
      "country_code": "US",
      "enable_human_verification": false,
      "page_context": "petitions_show",
      "briteform_token": "briteform_disabled_US_en-US",
      "first_name": "DENNY IS A LOLICON ",
      "last_name": randStr(5),
      "email": randStr(5) + "@" + randStr(5) + ".com",
      "city": "England",
      'state_code': states[~~(Math.random() * states.length)],
      'postal_code': ~~(Math.random() * 100000).toString().padStart(5, '0'),
      "marketing_comms_consent": null,
      "public": true,
    },
    resolveWithFullResponse: true
  });
  console.log("Status: " + res.statusCode);
}

sign()
setInterval(sign, interval);

function randStr(len) {
  let str = "";
  for (let i = 0; i < len; i++) str += "abcdefghijklmopqrstuvwxyz".charAt(Math.floor(Math.random() * 26));
  return str;
}