summaryrefslogtreecommitdiffstats
path: root/src/web/gui/ilove.html
blob: f82b1cfd32a35c6c6c38dbc6be0cef23f31edfd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<!DOCTYPE html>
<!-- SPDX-License-Identifier: GPL-3.0-or-later -->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>I Love SVG</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background-color: gray;
            font-family: 'Arial', sans-serif;
            display: flex;
            flex-direction: column;
            height: 100vh;
            padding: 20px;
        }

        .svg-container {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            margin-bottom: 20px;
        }

        .svg-container img {
            height: 75px;
            cursor: pointer;
        }

        .input-wrapper {
            display: flex;
            align-items: center;
            justify-content: center; /* Centers the items horizontally */
            flex-wrap: wrap; /* Allow the items to wrap if there isn't enough horizontal space */
            gap: 10px; /* Gap between the items */
        }

        .input-wrapper #labelInput {
            font-family: 'IBM Plex Sans', sans-serif;
            font-weight: bold;
            font-size: 24px;
            color: white;
            background-color: gray;
            border: none;
            cursor: default;
            padding: 10px 15px;
            margin-right: 10px;
            text-align: right;
            width: 135px;
        }

        .string-input input {
            font-family: 'IBM Plex Sans', sans-serif;
            font-weight: bold;
            font-size: 24px;
            background-color: black;
            color: white;
            border: none;
            border-radius: 8px;
            padding: 10px 15px;
            width: 100%;
            box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2);
            outline: none;
        }

        .string-input input:focus {
            box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.3);
        }

        .big-svg-container {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            overflow: hidden;
        }

        .big-svg {
            max-width: 100%;
            max-height: 95%;
            object-fit: contain;
        }

        .input-wrapper button {
            background-color: darkgray;
            color: white;
            border: none;
            border-radius: 8px;
            padding: 5px 10px;
            margin-left: 10px; /* Space between buttons */
            cursor: pointer;
            transition: background-color 0.3s; /* Smooth transition for hover effect */
        }

        .input-wrapper button:hover {
            background-color: #555; /* Darker shade on hover */
        }

        /* Style for the dropdown */
        #resolutionSelect {
            background-color: darkgray;  /* Same as button background */
            color: white;  /* Text color */
            border: none;  /* Remove border */
            border-radius: 8px;  /* Rounded corners, same as buttons */
            padding: 5px 10px;  /* Some padding for aesthetics */
            margin-left: 10px;  /* Space between dropdown and adjacent elements */
            font-family: "IBM Plex Sans", sans-serif;  /* Font from SVG */
            font-weight: bold;  /* Bold font */
            font-size: 16px;  /* Font size consistent with text box */
            cursor: pointer;  /* Hand cursor for better UX */
            appearance: none;  /* Remove default styling on some browsers */
            -webkit-appearance: none;  /* Remove default styling on WebKit browsers */
            -moz-appearance: none;  /* Remove default styling on Firefox */

            padding: 10px 20px;  /* Increase padding for more height */
            line-height: 1.5;  /* Increase line height for a taller dropdown */

            /* Arrow for the dropdown */
            background: darkgray url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M31.3 192l121.5 121.5c4.7 4.7 12.3 4.7 17 0L291.3 192c4.7-4.7 4.7-12.3 0-17l-22.6-22.6c-4.7-4.7-12.3-4.7-17 0L160 273.9 68.3 152c-4.7-4.7-12.3-4.7-17 0L28.7 174.5c-4.7 4.7-4.7 12.3 0 17.1z" fill="white"/></svg>') no-repeat right 10px center;
            padding-right: 40px;  /* Add padding to prevent text from overlapping the arrow */
        }

        /* Hover effect for the dropdown, similar to buttons */
        #resolutionSelect:hover {
            background-color: #555;  /* Darker shade on hover */
        }

        /* Arrow for the dropdown (this is a bit of a hack, but it works for adding a custom arrow) */
        #resolutionSelect::-ms-expand {
            display: none;  /* Hide default arrow for IE/Edge */
        }
        #resolutionSelect::after {
            content: '\25BC';  /* Down arrow symbol */
            position: absolute;
            top: 50%;
            right: 10px;
            transform: translateY(-50%);
            pointer-events: none;  /* Ensure dropdown still works when clicking arrow */
        }
    </style>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
</head>
<body>
<div class="svg-container">
    <!-- SVG examples will be loaded here -->
</div>

<div class="input-wrapper">
    <input type="text" value="You Love" id="labelInput" readonly>
    <div class="string-input">
        <input type="text" id="stringInput" placeholder="Enter your STRING here">
    </div>
    <select id="resolutionSelect">
        <option value="360">360p</option>
        <option value="720">720p</option>
        <option value="1080">1080p</option>
        <option value="4k">4k</option>
        <option value="8k">8k</option>
    </select>
    <button id="copyUrl"><i class="fas fa-copy"></i><br/>URL</button>
    <button id="downloadSvg"><i class="fas fa-download"></i><br/>SVG</button>
    <button id="downloadPng"><i class="fas fa-image"></i><br/>PNG</button>
    <button id="downloadWebp"><i class="fas fa-file-image"></i><br/>WEBP</button>
</div>

<div class="big-svg-container">
    <img src="" alt="Big SVG Image" id="bigSvg" class="big-svg">
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const examples = ["TROUBLE", "3AM", "BUGS", "ML", "AI", "CODE", "DEV", "DevOps", "Observability", "Telemetry", "Dashboards", "Automation", "K8s", "Docker", "PostgreSQL", "NightShifts", "OnCall", "Linux", "Debian", "Ubuntu", "Arch", "Manjaro", "CentOS", "AWS"];
        const svgContainer = document.querySelector('.svg-container');
        const bigSvg = document.getElementById('bigSvg');
        const stringInput = document.getElementById('stringInput');

        // Calculate the API endpoint
        const currentUrl = new URL(window.location.href);
        const apiEndpoint = `${currentUrl.origin}${currentUrl.pathname.replace('ilove.html', '')}api/v2/ilove.svg?love=`;

        // Load examples
        examples.forEach(example => {
            const img = document.createElement('img');
            img.src = `${apiEndpoint}${example}`;
            img.addEventListener('click', function() {
                stringInput.value = example;
                updateBigSvg();
            });
            svgContainer.appendChild(img);
        });

        // Set the default value of the text box to the first word from the examples
        stringInput.value = examples[0];
        updateBigSvg();

        // Update the big SVG when the input changes
        stringInput.addEventListener('input', updateBigSvg);

        function updateBigSvg() {
            const encodedValue = encodeURIComponent(stringInput.value);
            bigSvg.src = `${apiEndpoint}${encodedValue}`;
        }

        // Copy URL functionality
        document.getElementById('copyUrl').addEventListener('click', function() {
            const tempTextArea = document.createElement('textarea');
            tempTextArea.value = bigSvg.src;
            document.body.appendChild(tempTextArea);
            tempTextArea.select();
            document.execCommand('copy');
            document.body.removeChild(tempTextArea);

            // Update button icon and text temporarily
            const btn = this;  // 'this' refers to the clicked element (in this case, the 'copyUrl' button)
            const originalIcon = btn.querySelector('i');
            const breakElement = btn.querySelector('br');

            // Replace the icon and text
            originalIcon.className = "fas fa-check";  // Change to checkmark icon
            btn.textContent = '';  // Clear the button text
            btn.appendChild(originalIcon);  // Add the checkmark icon
            btn.appendChild(breakElement);  // Add the break element
            btn.appendChild(document.createTextNode('Copied'));  // Add the "Copied" text

            setTimeout(() => {
                originalIcon.className = "fas fa-copy";  // Revert back to copy icon
                btn.textContent = '';  // Clear the button text
                btn.appendChild(originalIcon);  // Add the copy icon
                btn.appendChild(breakElement);  // Add the break element
                btn.appendChild(document.createTextNode('URL'));  // Add the "URL" text
            }, 2000);  // Revert back after 2 seconds
        });

        // Download SVG
        document.getElementById('downloadSvg').addEventListener('click', function() {
            const filename = `I love ${stringInput.value}.svg`;
            triggerDownload(bigSvg.src, filename);
        });

        // Download PNG
        document.getElementById('downloadPng').addEventListener('click', function() {
            convertSvgToImage('png');
        });

        // Download WEBP
        document.getElementById('downloadWebp').addEventListener('click', function() {
            convertSvgToImage('webp');
        });

        function convertSvgToImage(format) {
            const image = new Image();
            image.src = bigSvg.src;
            image.onload = function() {
                const resolution = getResolutionDimensions();

                // Calculate the scaling factor based on the resolution width
                const scaleFactor = resolution.width / image.width;

                // Set canvas dimensions based on SVG's aspect ratio
                const canvas = document.createElement('canvas');
                canvas.width = image.width * scaleFactor;
                canvas.height = image.height * scaleFactor;

                const ctx = canvas.getContext('2d');
                ctx.drawImage(image, 0, 0, canvas.width, canvas.height);

                const filename = `I love ${stringInput.value}.${format}`;
                triggerDownload(canvas.toDataURL(`image/${format}`), filename);
            };
        }

        function getResolutionDimensions() {
            const resolution = document.getElementById('resolutionSelect').value;
            switch(resolution) {
                case "360": return { width: 640, height: 360 };
                case "720": return { width: 1280, height: 720 };
                case "1080": return { width: 1920, height: 1080 };
                case "4k": return { width: 3840, height: 2160 };
                case "8k": return { width: 7680, height: 4320 };
                default: return { width: 640, height: 360 };  // Default to 360p
            }
        }

        function triggerDownload(url, filename) {
            const downloadLink = document.createElement('a');
            downloadLink.href = url;
            downloadLink.download = filename;
            document.body.appendChild(downloadLink);
            downloadLink.click();
            document.body.removeChild(downloadLink);
        }

    });
</script>
</body>
</html>