Skip to content

Commit 445b5e6

Browse files
swastikCommitsonyxjasonsaayman
authored
feat: added a button to copy the commands (#212)
Co-authored-by: onyx <[email protected]> Co-authored-by: Jay <[email protected]>
1 parent f0e1985 commit 445b5e6

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

posts/en/intro.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,48 @@ Using npm:
3636
```bash
3737
$ npm install axios
3838
```
39+
<button onclick="copyToClipboard('npm install axios')">Copy</button>
3940

4041
Using bower:
4142

4243
```bash
4344
$ bower install axios
4445
```
45-
46+
<button onclick="copyToClipboard('bower install axios')">Copy</button>
4647
Using yarn:
4748

4849
```bash
4950
$ yarn add axios
5051
```
51-
52+
<button onclick="copyToClipboard('yarn add axios')">Copy</button>
5253
Using jsDelivr CDN:
5354

5455
```html
5556
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
5657
```
58+
<button onclick="copyToClipboard('<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>')">Copy</button>
5759

5860
Using unpkg CDN:
5961

6062
```html
6163
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
6264
```
63-
65+
<button onclick="copyToClipboard('<script src="https://unpkg.com/axios/dist/axios.min.js"></script>')">Copy</button>
6466
Prebuilt CommonJS modules for direct importing with require (if your module bundler failed to resolve them automatically)
6567

6668
```js
6769
const axios = require('axios/dist/browser/axios.cjs'); // browser
6870
const axios = require('axios/dist/node/axios.cjs'); // node
6971
```
72+
<button onclick="copyToClipboard('const axios = require('axios/dist/browser/axios.cjs');
73+
const axios = require(\'axios/dist/node/axios.cjs\'); // node')">Copy</button>
74+
75+
<script>
76+
function copyToClipboard(text) {
77+
navigator.clipboard.writeText(text).then(() => {
78+
alert('Copied to clipboard!');
79+
}).catch(err => {
80+
console.error('Failed to copy: ', err);
81+
});
82+
}
83+
</script>

0 commit comments

Comments
 (0)