|
1 | 1 | <!DOCTYPE html>
|
2 | 2 | <html>
|
3 |
| - <head> |
4 |
| - <title>Coding Hut Orders API</title> |
5 |
| - <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
6 |
| - <style> |
7 |
| - body { |
8 |
| - overflow-x: hidden; |
9 |
| - font-family: Sans-Serif; |
10 |
| - margin: 0; |
11 |
| - } |
12 |
| -<link href='https://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet'> |
13 |
| -<style> |
14 |
| -body { |
15 |
| - font-family: 'Comfortaa';font-size: 22px; |
16 |
| -} |
| 3 | +<head> |
| 4 | + <title>Coding Hut Orders API</title> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <script type="text/javascript"> |
| 7 | + function getParameterByName(name, url = window.location.href) { |
| 8 | + name = name.replace(/[\[\]]/g, "\\$&"); |
| 9 | + const regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"); |
| 10 | + const results = regex.exec(url); |
| 11 | + if (!results) return null; |
| 12 | + if (!results[2]) return ''; |
| 13 | + return decodeURIComponent(results[2].replace(/\+/g, " ")); |
| 14 | + } |
17 | 15 |
|
18 |
| -.dynamic-content { |
19 |
| - display:none; |
20 |
| -} |
21 |
| -</style> |
22 |
| - |
23 |
| -<!-- This is for the coding hut api --> |
| 16 | + const username = getParameterByName('username'); |
24 | 17 |
|
25 |
| -<!-- Default Dynamic Section --> |
26 |
| -<div id="default-content" class="dynamic-content"> |
27 |
| -{"status": 400, "error": "Invaild Request - Username does not exist in orders database"} |
28 |
| -</div> |
29 |
| -<!-- MyScratchedAccount's Completed Orders --> |
30 |
| -<div id="MyScratchedAccount" class="dynamic-content"> |
31 |
| -{"status": 500, "completed-orders": 6, "pending-orders": 0} |
32 |
| -<br> |
33 |
| -</div> |
34 |
| -<!-- Dynamic Section 2 --> |
35 |
| -<div id="kRxZy_kRxZy" class="dynamic-content"> |
36 |
| -{"status": 500, "completed-orders": 2, "pending-orders": 0} |
37 |
| -<br> |
38 |
| -</div> |
39 |
| -<!-- Dynamic Section 3 --> |
40 |
| -<div id="staff3" class="dynamic-content"> |
41 |
| -<h2>Staff3</h2> |
42 |
| -<br> |
43 |
| -DESCRIPTION HERE |
44 |
| -</div> |
| 18 | + let jsonResponse; |
45 | 19 |
|
46 |
| -<script> |
47 |
| - function toggleMenu() { |
48 |
| - var menu = document.querySelector('.menu'); |
49 |
| - menu.style.display = menu.style.display === 'flex' ? 'none' : 'flex'; |
50 |
| - } |
51 |
| -</script> |
| 20 | + switch (username) { |
| 21 | + case 'MyScratchedAccount': |
| 22 | + jsonResponse = { |
| 23 | + status: 500, |
| 24 | + "completed-orders": 6, |
| 25 | + "pending-orders": 0 |
| 26 | + }; |
| 27 | + break; |
| 28 | + case 'kRxZy_kRxZy': |
| 29 | + jsonResponse = { |
| 30 | + status: 500, |
| 31 | + "completed-orders": 2, |
| 32 | + "pending-orders": 0 |
| 33 | + }; |
| 34 | + break; |
| 35 | + case 'staff3': |
| 36 | + jsonResponse = { |
| 37 | + status: 200, |
| 38 | + user: "staff3", |
| 39 | + description: "Staff account" |
| 40 | + }; |
| 41 | + break; |
| 42 | + default: |
| 43 | + jsonResponse = { |
| 44 | + status: 400, |
| 45 | + error: "Invalid Request - Username does not exist in orders database" |
| 46 | + }; |
| 47 | + } |
52 | 48 |
|
53 |
| -<script src="//code.jquery.com/jquery-1.12.0.min.js"></script> |
54 |
| -<script type="text/javascript"> |
55 |
| - // Parse the URL parameter |
56 |
| - function getParameterByName(name, url) { |
57 |
| - if (!url) url = window.location.href; |
58 |
| - name = name.replace(/[\[\]]/g, "\\$&"); |
59 |
| - var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), |
60 |
| - results = regex.exec(url); |
61 |
| - if (!results) return null; |
62 |
| - if (!results[2]) return ''; |
63 |
| - return decodeURIComponent(results[2].replace(/\+/g, " ")); |
64 |
| - } |
65 |
| - // Give the parameter a variable name |
66 |
| - var dynamicContent = getParameterByName('username'); |
67 |
| - |
68 |
| - $(document).ready(function() { |
69 |
| - |
70 |
| - // Check if the URL parameter is apples |
71 |
| - if (dynamicContent == 'MyScratchedAccount') { |
72 |
| - $('#MyScratchedAccount').show(); |
73 |
| - } |
74 |
| - // Check if the URL parameter is oranges |
75 |
| - else if (dynamicContent == 'kRxZy_kRxZy') { |
76 |
| - $('kRxZy_kRxZy').show(); |
77 |
| - } |
78 |
| - // Check if the URL parameter is bananas |
79 |
| - else if (dynamicContent == 'staff3') { |
80 |
| - $('#staff3').show(); |
81 |
| - } |
82 |
| - // Check if the URL parmeter is empty or not defined, display default content |
83 |
| - else { |
84 |
| - $('#default-content').show(); |
85 |
| - } |
86 |
| - }); |
87 |
| -</script> |
| 49 | + // Clear and return JSON as plain text |
| 50 | + document.addEventListener('DOMContentLoaded', () => { |
| 51 | + document.body.innerText = JSON.stringify(jsonResponse, null, 2); |
| 52 | + }); |
| 53 | + </script> |
| 54 | +</head> |
| 55 | +<body> |
| 56 | +</body> |
| 57 | +</html> |
0 commit comments