Skip to content

Commit d75b1e8

Browse files
committed
Add anchor click link copy + Notification
1 parent 0ef7336 commit d75b1e8

File tree

2 files changed

+70
-8
lines changed

2 files changed

+70
-8
lines changed

docs/css/styles.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,25 @@ code {
527527
pre {
528528
font-family: "Source Code Pro", monospace;
529529
}
530+
531+
#notification-box {
532+
background-color: rgb(36, 36, 36);
533+
border-radius: 15px;
534+
box-shadow: 0px 3px 10px 0px rgba(0, 0, 0, .2);
535+
text-align: center;
536+
color: rgb(40, 236, 40);
537+
font-weight: bold;
538+
transition: all .2s;
539+
/*transition-delay: .3s;*/
540+
opacity: 0;
541+
position: fixed;
542+
left: 50%;
543+
top: 92%;
544+
padding: 10px;
545+
transform: translate(-50%, -50%);
546+
}
547+
548+
.activate-notification {
549+
opacity: 1 !important;
550+
transform: translateY(-20px);
551+
}

docs/js/main.js

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ if (noLeftPanel != null)
3939

4040
// <> Magic Text
4141
function getRandomChar() {
42-
chars = "ÂÃÉÊÐÑÙÚÛÜéêëãòóôēĔąĆćŇň1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()-=_+{}[";
43-
return chars.charAt(Math.floor(Math.random() * chars.length) + 1)
42+
chars = "ÂÃÉÊÐÑÙÚÛÜéêëãòóôēĔąĆćŇň1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()-=_+{}[";
43+
return chars.charAt(Math.floor(Math.random() * chars.length) + 1)
4444
}
4545

4646
function magicTextGen(element) {
4747
var msg = element.textContent;
48-
var length = msg.length;
48+
var length = msg.length;
4949

50-
setInterval(() => {
50+
setInterval(() => {
5151
var newMsg = "";
5252
for (i = 0; i <= length; i++) {
5353
newMsg += getRandomChar(msg.charAt(i));
@@ -58,17 +58,17 @@ function magicTextGen(element) {
5858
}
5959

6060
function renderMagicText() {
61-
document.querySelectorAll('.magic-text').forEach( (e) => {
62-
magicTextGen(e);
63-
})
61+
document.querySelectorAll('.magic-text').forEach((e) => {
62+
magicTextGen(e);
63+
})
6464
}
6565
renderMagicText();
6666

6767
// Magic Text </>
6868

6969
// <> Mobile anchor correction due to doubled size header)
7070
function offsetAnchor(event, element) {
71-
if (window.innerWidth <= 768 ) {
71+
if (window.innerWidth <= 768) {
7272
event.preventDefault();
7373
content = document.querySelectorAll("#content")[0];
7474
actualElement = document.getElementById(element.getAttribute("href").replace("#", ""));
@@ -82,3 +82,43 @@ document.querySelectorAll("#nav-contents a").forEach((e) => {
8282
});
8383
})
8484
// Mobile anchor correction </>
85+
86+
// <> Anchor click copy link
87+
function copyToClipboard() {
88+
setTimeout(() => {
89+
var cb = document.body.appendChild(document.createElement("input"));
90+
cb.value = window.location.href;
91+
cb.focus();
92+
cb.select();
93+
document.execCommand('copy');
94+
cb.parentNode.removeChild(cb);
95+
}, 50)
96+
}
97+
function showNotification(text, bgColor, color) {
98+
var noti = document.body.appendChild(document.createElement("span"));
99+
noti.id = "notification-box";
100+
101+
setTimeout(() => {
102+
noti.textContent = text;
103+
if (bgColor)
104+
noti.styles.backgroundColor = bgColor;
105+
if (color)
106+
noti.styles.backgroundColor = color;
107+
noti.classList.add("activate-notification");
108+
setTimeout(() => {
109+
noti.classList.remove("activate-notification");
110+
setTimeout(() => {
111+
noti.parentNode.removeChild(noti);
112+
}, 200);
113+
}, 1500);
114+
}, 50);
115+
}
116+
117+
const currentPageLink = window.location.toString().replaceAll(/(.+?.html)(.*)/gi, '$1');
118+
document.querySelectorAll(".item-title > a").forEach((e) => {
119+
e.addEventListener("click", (event) => {
120+
copyToClipboard();
121+
showNotification("✅ Link copied successfully.")
122+
});
123+
})
124+
// Anchor click copy link </>

0 commit comments

Comments
 (0)