File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ < title > Perchance Generator Integration</ title >
5+ < style >
6+ body { font-family : Arial, sans-serif; max-width : 800px ; margin : 0 auto; padding : 20px ; }
7+ # output { padding : 15px ; border : 1px solid # ddd ; min-height : 50px ; margin : 15px 0 ; }
8+ button { padding : 8px 16px ; cursor : pointer; }
9+ html { color-scheme : light dark; }
10+ </ style >
11+ </ head >
12+ < body >
13+ < h1 > Perchance Generator</ h1 >
14+
15+ < label for ="generatorInput "> Generator Name:</ label >
16+ < input type ="text " id ="generatorInput " value ="fantasy-character ">
17+
18+ < div id ="output "> Results will appear here...</ div >
19+ < button onclick ="fetchFromPerchance() "> Generate</ button >
20+
21+ < script >
22+ async function fetchFromPerchance ( ) {
23+ const generatorName = document . getElementById ( "generatorInput" ) . value ;
24+ const count = 1 ;
25+
26+ try {
27+ document . querySelector ( "button" ) . textContent = "Loading..." ;
28+ const response = await fetch ( `https://perchance.org/api/generateList.php?generator=${ generatorName } &count=${ count } ` ) ;
29+
30+ if ( ! response . ok ) {
31+ throw new Error ( `HTTP error! Status: ${ response . status } ` ) ;
32+ }
33+
34+ const data = await response . json ( ) ;
35+
36+ if ( data && data . length > 0 ) {
37+ document . getElementById ( "output" ) . textContent = data [ 0 ] ;
38+ } else {
39+ document . getElementById ( "output" ) . textContent = "No results returned." ;
40+ }
41+ } catch ( error ) {
42+ console . error ( "Error fetching from Perchance:" , error ) ;
43+ document . getElementById ( "output" ) . textContent = "Error fetching from Perchance. Check console for details." ;
44+ } finally {
45+ document . querySelector ( "button" ) . textContent = "Generate" ;
46+ }
47+ }
48+ </ script >
49+ </ body >
50+ </ html >
You can’t perform that action at this time.
0 commit comments