188
188
/* Copy Button */
189
189
.copy-button {
190
190
position: fixed;
191
- top: 90px;
192
191
right: 7%;
193
192
padding: 12px 20px;
194
193
background-color: rgba(0, 255, 0, 0.2);
297
296
}
298
297
299
298
.copy-button {
300
- top: 80px;
301
299
right: 5%;
302
300
padding: 10px 15px;
303
301
font-size: 16px;
304
302
}
303
+
304
+ .copy-button:nth-child(2) {
305
+ top: 80px;
306
+ }
307
+
308
+ .copy-button:nth-child(3) {
309
+ top: 135px;
310
+ }
305
311
}
306
312
307
313
{{ pygments_css | safe }}
323
329
</ a >
324
330
< div style ="width: 50px; "> </ div >
325
331
</ div >
326
- < button id ="copyButton " class ="copy-button " onclick ="copyAllText() ">
332
+ < button id ="copyButton " class ="copy-button " onclick ="copyAllText() " style =" top: 90px; " >
327
333
< i class ="fas fa-copy "> </ i > COPY CODE
328
334
</ button >
335
+ < button id ="copyLinkButton " class ="copy-button " onclick ="copyLink() " style ="top: 145px; ">
336
+ < i class ="fas fa-link "> </ i > COPY LINK
337
+ </ button >
329
338
< div class ="code ">
330
339
{{ highlighted_code | safe }}
331
340
</ div >
408
417
}, 2000);
409
418
}
410
419
420
+ function copyLink() {
421
+ const currentUrl = window.location.href;
422
+
423
+ if (navigator.clipboard) {
424
+ navigator.clipboard.writeText(currentUrl).then(() => {
425
+ const copyLinkButton = document.getElementById('copyLinkButton');
426
+ const originalText = copyLinkButton.innerHTML;
427
+ copyLinkButton.innerHTML = '< i class ="fas fa-check "> </ i > LINK COPIED!';
428
+
429
+ setTimeout(() => {
430
+ copyLinkButton.innerHTML = originalText;
431
+ }, 2000);
432
+ }).catch(() => {
433
+ fallbackCopyLink(currentUrl);
434
+ });
435
+ } else {
436
+ fallbackCopyLink(currentUrl);
437
+ }
438
+ }
439
+
440
+ function fallbackCopyLink(text) {
441
+ const textArea = document.createElement("textarea");
442
+ textArea.value = text;
443
+ textArea.style.position = "fixed";
444
+ textArea.style.left = "-999999px";
445
+ textArea.style.top = "-999999px";
446
+ document.body.appendChild(textArea);
447
+ textArea.focus();
448
+ textArea.select();
449
+
450
+ try {
451
+ document.execCommand('copy');
452
+ const copyLinkButton = document.getElementById('copyLinkButton');
453
+ const originalText = copyLinkButton.innerHTML;
454
+ copyLinkButton.innerHTML = '< i class ="fas fa-check "> </ i > LINK COPIED!';
455
+
456
+ setTimeout(() => {
457
+ copyLinkButton.innerHTML = originalText;
458
+ }, 2000);
459
+ } catch (err) {
460
+ const copyLinkButton = document.getElementById('copyLinkButton');
461
+ const originalText = copyLinkButton.innerHTML;
462
+ copyLinkButton.innerHTML = '< i class ="fas fa-times "> </ i > COPY FAILED';
463
+
464
+ setTimeout(() => {
465
+ copyLinkButton.innerHTML = originalText;
466
+ }, 2000);
467
+ }
468
+
469
+ document.body.removeChild(textArea);
470
+ }
471
+
411
472
{% endblock %}
0 commit comments