File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 1+ const shortenUrl = async ( ) => {
2+ const longUrl = document . getElementById ( 'long-url' ) . value ;
3+ const response = await fetch ( `https://api.shrtco.de/v2/shorten?url=${ longUrl } ` ) ;
4+ const data = await response . json ( ) ;
5+ const shortUrl = data . result . full_short_link ;
6+
7+ const shortUrlContainer = document . getElementById ( 'short-url-container' ) ;
8+ const shortUrlLink = document . getElementById ( 'short-url' ) . querySelector ( 'a' ) ;
9+ shortUrlLink . href = shortUrl ;
10+ shortUrlLink . textContent = shortUrl ;
11+ shortUrlContainer . style . display = 'block' ;
12+
13+ const copyBtn = document . getElementById ( 'copy-btn' ) ;
14+ copyBtn . addEventListener ( 'click' , ( ) => {
15+ navigator . clipboard . writeText ( shortUrl ) . then ( ( ) => {
16+ alert ( 'Copied to clipboard!' ) ;
17+ } ) ;
18+ } ) ;
19+ } ;
20+
21+ const shortenBtn = document . getElementById ( 'shorten-btn' ) ;
22+ shortenBtn . addEventListener ( 'click' , shortenUrl ) ;
You can’t perform that action at this time.
0 commit comments