188188/* Copy Button */
189189.copy-button {
190190 position: fixed;
191- top: 90px;
192191 right: 7%;
193192 padding: 12px 20px;
194193 background-color: rgba(0, 255, 0, 0.2);
297296 }
298297
299298 .copy-button {
300- top: 80px;
301299 right: 5%;
302300 padding: 10px 15px;
303301 font-size: 16px;
304302 }
303+
304+ .copy-button:nth-child(2) {
305+ top: 80px;
306+ }
307+
308+ .copy-button:nth-child(3) {
309+ top: 135px;
310+ }
305311}
306312
307313{{ pygments_css | safe }}
323329 </ a >
324330 < div style ="width: 50px; "> </ div >
325331 </ div >
326- < button id ="copyButton " class ="copy-button " onclick ="copyAllText() ">
332+ < button id ="copyButton " class ="copy-button " onclick ="copyAllText() " style =" top: 90px; " >
327333 < i class ="fas fa-copy "> </ i > COPY CODE
328334 </ button >
335+ < button id ="copyLinkButton " class ="copy-button " onclick ="copyLink() " style ="top: 145px; ">
336+ < i class ="fas fa-link "> </ i > COPY LINK
337+ </ button >
329338 < div class ="code ">
330339 {{ highlighted_code | safe }}
331340 </ div >
408417 }, 2000);
409418 }
410419
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+
411472{% endblock %}
0 commit comments