@@ -3,7 +3,7 @@ import ditto from '../data/ditto.json'
33const dittoJson = JSON .stringify (ditto )
44const pokeUrl = ' https://pokeapi.co/api/v2/ '
55
6- import { Aside } from ' @astrojs/starlight/components'
6+ import { Aside , Icon } from ' @astrojs/starlight/components'
77---
88
99<
link is:raw rel =" stylesheet" href =" https://cdn.jsdelivr.net/gh/williamtroup/[email protected] /dist/jsontree.js.min.css" > @@ -81,27 +81,43 @@ import { Aside } from '@astrojs/starlight/components'
8181 md:w-auto
8282 "
8383 >{pokeUrl}</span>
84- <input
85- class="
86- w-auto
87- text-center
88- p-3 rounded-md
89- bg-(--sl-color-gray-5)
90- md:grow
91- md:mx-4
92- md:text-left
93- "
94- type="text"
95- name="pokeapi-path"
96- id="pokeapi-path"
97- placeholder="path/segment"
98- required
99- title="no"
100- value="pokemon/ditto"
101- pattern="(\w|\d|-)+( |(/(\w|\d|-)+)+)"
102- minlength="1"
103- onkeypress="if(event.key === 'Enter') sendRequest()"
104- >
84+ <div class="flex md:grow md:mr-4">
85+ <input
86+ class="
87+ w-auto
88+ text-center
89+ p-3 rounded-md
90+ bg-(--sl-color-gray-5)
91+ grow
92+ md:ml-4
93+ md:text-left
94+ "
95+ type="text"
96+ name="pokeapi-path"
97+ id="pokeapi-path"
98+ placeholder="path/segment"
99+ required
100+ title="no"
101+ value="pokemon/ditto"
102+ pattern="(\w|\d|-)+( |(/(\w|\d|-)+)+)"
103+ minlength="1"
104+ onkeypress="if(event.key === 'Enter') sendRequest()"
105+ >
106+ <button
107+ id="copy-url-to-clipboard"
108+ class="
109+ font-semibold
110+ p-3 rounded-md
111+ ml-2
112+ cursor-pointer
113+ flex
114+ align-middle
115+ justify-center
116+ "
117+ >
118+ <Icon name="document" size="24px" class="m-auto" />
119+ </button >
120+ </div >
105121 </label >
106122 <button
107123 id =" sendRequestSubmit"
@@ -153,6 +169,21 @@ import { Aside } from '@astrojs/starlight/components'
153169
154170 kokiInit(ditto, jsonContainer, 'Resource for ditto')
155171
172+ function copyToClipboard(text) {
173+ navigator.clipboard.writeText(text)
174+ .then(() => console.log('Text copied to clipboard'))
175+ .catch((err) => console.error('Failed to copy: ', err))
176+ }
177+
178+ let copyToUrlClipboardButton = document.getElementById('copy-url-to-clipboard')
179+
180+ copyToUrlClipboardButton.addEventListener('click', function () {
181+ pokeApiPath = pokeapiPathInput.value
182+ const url = pokeUrl + pokeApiPath
183+
184+ copyToClipboard(url)
185+ })
186+
156187 async function sendRequest() {
157188 pokeApiPath = pokeapiPathInput.value
158189 const url = pokeUrl + pokeApiPath
0 commit comments