Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
obsfx committed Jun 10, 2020
0 parents commit e6e9df0
Show file tree
Hide file tree
Showing 10 changed files with 358 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2004 Sam Hocevar <[email protected]>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# itch.io bundle claimer

[Bundle for Racial Justice and Equality](https://itch.io/b/520/bundle-for-racial-justice-and-equality)

A simple script that is using `selenium` to help you for adding all bundle items
to your library by clicking all download buttons in place of you.

![](https://raw.githubusercontent.com/obsfx/itchio-bundle-claimer/master/media/demo.gif)

### Prerequisites

1. Download appropriate chrome driver for your operating system and add it to the PATH.
2. Add chrome to the PATH. It should be accessible as 'google-chrome'.
3. And of course nodejs and npm.

### Usage

1. Clone the repo

```
git clone https://github.com/obsfx/itchio-bundle-claimer.git
cd itchio_bundle_claimer
npm install
```

2. Run chrome in remote debugging mode

(port '9000' must be available)

```
npm run run-chrome
```

3. Open a new chrome window and type `127.0.0.1:9000` at the address bar.

![](https://raw.githubusercontent.com/obsfx/itchio-bundle-claimer/master/media/1.png)

4. Click that the `about:blank`

5. Type and go to `itch.io` by using that sub address bar.

![](https://raw.githubusercontent.com/obsfx/itchio-bundle-claimer/master/media/2.png)

6. Login by defeating that annoying captcha. After you logged in you can close the browser.

7. Run the script.

```
node index.js --pages=<specify the page count> --url=<specify the bundle page url that listed all download buttons>
e.g.: node index.js --pages=48 --url=https://itch.io/bundle/download/sakfjasfkhaslkjfhlkajsfhgjkhlasf
```
Binary file added chromedriver_linux64.zip
Binary file not shown.
76 changes: 76 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const minimist = require('minimist');

const { Builder, By, until } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

const options = new chrome.Options();

// setting 'debuggerAddress'
// reference: https://stackoverflow.com/a/42095309
options.options_['debuggerAddress'] = '127.0.0.1:9000';

const argv = minimist(process.argv.slice(2));

if (typeof argv.pages != 'number' || typeof argv.url != 'string') {
console.log('please be sure you passed parameters correct.');
return process.exit(0);
}

const PAGE_COUNT = Number(argv.pages) || 0;
const BUNDLE_DOWNLOAD_URL = argv.url || '';

const ANCHOR_DOWNLOAD_CLASSNAME = 'button game_download_btn';
const BTN_DOWNLOAD_SELECTOR = 'button[value=claim]';
const AFTER_CLICK_LOAD_CLASSNAME = 'nav_btn return_link';
const GAME_NAME_SELECTOR = '.stat_header_widget .text_container .object_title';

let state = {
counter: 0,
downloadBtns: [],
}

const getDownloadBtns = async driver => {

let anchorDownloads = await driver.findElements(By.className(ANCHOR_DOWNLOAD_CLASSNAME));
let buttonDownloads = await driver.findElements(By.css(BTN_DOWNLOAD_SELECTOR));

return [ ...anchorDownloads, ...buttonDownloads ];
}

(async () => {
const driver = await new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();

for (let i = 1; i <= PAGE_COUNT; i++) {
let URL = `${BUNDLE_DOWNLOAD_URL}?page=${i}`;

await driver.get(URL);

console.log('PAGE: ', i);
console.log('current url:', await driver.getCurrentUrl());
console.log('-----------------------------------------')

state.allDownloadBtns = await getDownloadBtns(driver);

for (let j = 0; j < state.allDownloadBtns.length; j++) {

await driver.executeScript('arguments[0].click();', state.allDownloadBtns[j]);

await driver.wait(
until.elementLocated(By.className(AFTER_CLICK_LOAD_CLASSNAME)),
5000);

let head = await driver
.findElement(By.css(GAME_NAME_SELECTOR))
.getText();

console.log(++state.counter, head);

await driver.get(URL);
state.allDownloadBtns = await getDownloadBtns(driver);
}
}

})();
Binary file added media/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
202 changes: 202 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "itchio_bundle_claimer",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"prepare-chromedriver": "unzip ./chromedriver_linux64.zip && sudo mv ./chromedriver /usr/bin/chromedriver",
"run-chrome": "google-chrome --remote-debugging-port=9000 --headless --no-sandbox --disable-setuid-sandbox --disable-gpu"
},
"author": "obsfx",
"license": "WTFPL",
"dependencies": {
"minimist": "^1.2.5",
"selenium-webdriver": "^4.0.0-alpha.7"
}
}

0 comments on commit e6e9df0

Please sign in to comment.