Skip to content

Commit 95fb0dc

Browse files
committed
chore: update the examples
1 parent cce3b2c commit 95fb0dc

4 files changed

Lines changed: 57 additions & 26 deletions

File tree

README.md

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,52 @@
2424

2525
---
2626

27-
## 📦 Installation
27+
## 📦 Getting Started
2828

29-
### As a Userscript (Recommended)
29+
### Using diepAPI in Your Scripts (Recommended)
3030

31-
**Requirements:** [Tampermonkey](https://www.tampermonkey.net/) or [Violentmonkey](https://violentmonkey.github.io/)
32-
33-
1. Install Tampermonkey or Violentmonkey in your browser
34-
2. Download the latest `diepAPI.user.js` from [Releases](https://github.com/Cazka/diepAPI/releases)
35-
3. Your userscript manager will prompt you to install it
36-
4. Navigate to [diep.io](https://diep.io) and start using the API!
31+
You don't need to install diepAPI separately! Just add a `@require` directive to your userscript, and your userscript manager will automatically load diepAPI for you.
3732

38-
### Using diepAPI in Your Scripts
39-
40-
Once installed, create a new userscript with diepAPI as a dependency:
33+
Create a new userscript in Tampermonkey/Violentmonkey with:
4134

4235
```javascript
4336
// ==UserScript==
4437
// @name My Awesome Bot
38+
// @description My custom diep.io bot
4539
// @match https://diep.io/*
46-
// @require https://github.com/Cazka/diepAPI/releases/download/latest/diepAPI.user.js
40+
// @require https://github.com/Cazka/diepAPI/releases/latest/download/diepAPI.user.js
4741
// @grant none
4842
// ==/UserScript==
4943

50-
// Your code here - diepAPI is available as window.diepAPI
44+
// diepAPI is automatically loaded and available here!
45+
const { game, player } = diepAPI.apis;
46+
47+
game.on('ready', () => {
48+
console.log('Bot started!');
49+
player.spawn('MyBot');
50+
});
5151
```
5252

53+
That's it! The `@require` line automatically downloads and loads diepAPI before your script runs.
54+
55+
**Requirements:** [Tampermonkey](https://www.tampermonkey.net/) or [Violentmonkey](https://violentmonkey.github.io/)
56+
57+
---
58+
59+
### Install Standalone (Optional)
60+
61+
If you want to experiment with diepAPI directly in the browser console without writing a script:
62+
63+
1. Install [Tampermonkey](https://www.tampermonkey.net/) or [Violentmonkey](https://violentmonkey.github.io/)
64+
2. Download `diepAPI.user.js` from [Releases](https://github.com/Cazka/diepAPI/releases)
65+
3. Install it in your userscript manager
66+
4. Navigate to [diep.io](https://diep.io)
67+
5. Open browser console and use `window.diepAPI`
68+
69+
This method is mainly for testing and experimentation. For building bots, use the `@require` method above.
70+
71+
---
72+
5373
### Building from Source
5474

5575
See the [Building from Source](#-building-from-source) section below.
@@ -58,9 +78,17 @@ See the [Building from Source](#-building-from-source) section below.
5878

5979
## 🚀 Quick Start
6080

61-
Here's a simple script to get you started. This example spawns your tank and logs your position every frame:
81+
Here's a complete, ready-to-use example. Copy this entire code block and create a new userscript in your userscript manager:
6282

6383
```javascript
84+
// ==UserScript==
85+
// @name Position Logger
86+
// @description Logs player position every frame
87+
// @match https://diep.io/*
88+
// @require https://github.com/Cazka/diepAPI/releases/latest/download/diepAPI.user.js
89+
// @grant none
90+
// ==/UserScript==
91+
6492
// Access the APIs you need
6593
const { game, player } = diepAPI.apis;
6694

@@ -81,7 +109,14 @@ game.on('frame', () => {
81109
});
82110
```
83111

84-
That's it! You now have access to real-time game data. Let's explore what else you can do.
112+
**How to use:**
113+
1. Copy the code above
114+
2. In Tampermonkey/Violentmonkey, click "Create new script"
115+
3. Paste the code and save
116+
4. Navigate to [diep.io](https://diep.io)
117+
5. Open browser console (F12) to see the logs
118+
119+
The `@require` directive automatically downloads diepAPI - no separate installation needed!
85120

86121
---
87122

@@ -178,13 +213,11 @@ Keep your tank stationary at its current position. Press Q to toggle AFK mode on
178213
// @version 0.0.5
179214
// @author Cazka
180215
// @match https://diep.io/*
216+
// @require https://github.com/Cazka/diepAPI/releases/latest/download/diepAPI.user.js
181217
// @icon https://www.google.com/s2/favicons?domain=diep.io
182218
// @grant none
183219
// ==/UserScript==
184220

185-
// Check if diepAPI is installed
186-
if (!window.diepAPI) return window.alert('Please install diepAPI to use this script');
187-
188221
const { Vector } = window.diepAPI.core;
189222
const { player, game } = window.diepAPI.apis;
190223

@@ -234,13 +267,11 @@ Automatically aims at nearby shapes and shoots them. Press P to toggle farming m
234267
// @version 0.0.7
235268
// @author Cazka
236269
// @match https://diep.io/*
270+
// @require https://github.com/Cazka/diepAPI/releases/latest/download/diepAPI.user.js
237271
// @icon https://www.google.com/s2/favicons?domain=diep.io
238272
// @grant none
239273
// ==/UserScript==
240274

241-
// Check if diepAPI is installed
242-
if (!window.diepAPI) return window.alert('Please install diepAPI to use this script');
243-
244275
const { Vector } = window.diepAPI.core;
245276
const { player, game } = window.diepAPI.apis;
246277
const { entityManager } = window.diepAPI.extensions;
@@ -387,13 +418,13 @@ npm install
387418
npm run build
388419
```
389420

390-
**Output:** `diepAPI.user.js` in the root directory
421+
**Output:** `dist/diepAPI.user.js`
391422

392423
### Development Workflow
393424

394425
1. Make changes to files in `src/`
395426
2. Run `npm run build` to compile
396-
3. Install `diepAPI.user.js` in Tampermonkey
427+
3. Install `dist/diepAPI.user.js` in Tampermonkey
397428
4. Test your changes at [diep.io](https://diep.io)
398429
5. Iterate!
399430

examples/afk.user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
// @version 0.0.5
55
// @author Cazka
66
// @match https://diep.io/*
7+
// @require https://github.com/Cazka/diepAPI/releases/latest/download/diepAPI.user.js
78
// @icon https://www.google.com/s2/favicons?domain=diep.io
89
// @namespace https://greasyfork.org/users/541070
910
// @grant none
1011
// ==/UserScript==
11-
if (!window.diepAPI) return window.alert('Please install diepAPI to use this script');
1212

1313
const { Vector } = window.diepAPI.core;
1414
const { player, game } = window.diepAPI.apis;

examples/farmer.user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
// @version 0.0.7
55
// @author Cazka
66
// @match https://diep.io/*
7+
// @require https://github.com/Cazka/diepAPI/releases/latest/download/diepAPI.user.js
78
// @icon https://www.google.com/s2/favicons?domain=diep.io
89
// @namespace https://greasyfork.org/users/541070
910
// @grant none
1011
// ==/UserScript==
11-
if (!window.diepAPI) return window.alert('Please install diepAPI to use this script');
1212

1313
const { Vector } = window.diepAPI.core;
1414
const { player, game } = window.diepAPI.apis;

examples/press_o.user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
// @version 0.0.2
55
// @author Cazka
66
// @match https://diep.io/*
7+
// @require https://github.com/Cazka/diepAPI/releases/latest/download/diepAPI.user.js
78
// @icon https://www.google.com/s2/favicons?domain=diep.io
89
// @namespace https://greasyfork.org/users/541070
910
// @grant none
1011
// ==/UserScript==
11-
if (!window.diepAPI) return window.alert('Please install diepAPI to use this script');
1212

1313
const { player } = window.diepAPI.apis;
1414

0 commit comments

Comments
 (0)