Skip to content

Commit ce70aae

Browse files
committed
clipboard copied 🎄
1 parent 5f7b469 commit ce70aae

File tree

3 files changed

+68
-7
lines changed

3 files changed

+68
-7
lines changed

dist/Responses/newscript.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
require("dotenv").config();
2-
const ShortenerURL = process.env.HOME_URL;
1+
const ShortenerURL = "https://creative-greets.netlify.app/.netlify/functions/server/";
32

43
// https://stackoverflow.com/questions/6396101/pure-javascript-send-post-data-without-a-form
54
// Backend code was taken from "WebDevSimplified" !
65
function get_short_url() {
76
let data = { "fullUrl":`${window.location.href}&shared=True` };
8-
7+
var span_popup=document.querySelector(".popuptext");
8+
span_popup.classList.remove("show");
99
fetch(`${ShortenerURL}shortUrls`, {
1010
method: "POST",
1111
headers: { "Content-Type": "application/json" },
@@ -14,7 +14,9 @@ function get_short_url() {
1414
return res.json();
1515
}).then(response=>{
1616
console.log(ShortenerURL+response.url)
17-
return ShortenerURL+response.url
17+
let shortURL=ShortenerURL+response.url;
18+
span_popup.classList.add("show");
19+
navigator.clipboard.writeText(shortURL);
1820
})
1921
.catch(err=>{
2022
return err;

dist/Responses/script.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,19 @@ console.log(queryDict2);
2626
// check if the rendered page is shared by others or created to share
2727
if(!(d1=="shared" && d2=="True")){
2828
let button_div=document.querySelector(".bclass");
29-
// <button onclick="get_short_url()">Share with friends !</button>
29+
/*
30+
<button onclick="get_short_url()" class="share_btn">Share with friends !
31+
<span class="popuptext">Sharable URL Copied !</span>
32+
</button>
33+
*/
3034
var button=document.createElement("button")
3135
button.setAttribute("onclick","get_short_url()");
36+
button.setAttribute("class","share_btn");
3237
button.appendChild(document.createTextNode("Share with Friends !"));
38+
var span_popup=document.createElement("span");
39+
span_popup.setAttribute("class","popuptext");
40+
span_popup.appendChild(document.createTextNode("Shareble URL Copied !"));
41+
button.appendChild(span_popup);
3342
button_div.appendChild(button);
3443
}
3544

@@ -156,7 +165,6 @@ for(i=0; i<queryDict1.length; i++){
156165
}
157166
var replaced=queryDict2[i][0].split('+').join(' ');
158167
var replaced="<h1>"+replaced+"</h1>";
159-
console.log("Replaced"+replaced);
160168
// code for not to apply styling to the emojis to maintain the original color
161169
if(replaced.search(regexExp)!=-1){
162170
const found=replaced.match(regexExp); // returns array of all matches of emoji
@@ -170,7 +178,6 @@ if(replaced.search(regexExp)!=-1){
170178
}
171179
}
172180
}
173-
console.log(replaced);
174181
message.innerHTML=replaced
175182
greet.innerHTML="From: "+queryDict2[i-1][0].split('+').join(' ');
176183
// "<br>To: "+queryDict2[i-1][0];

dist/Responses/style.css

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,55 @@ p{
257257
opacity:0;
258258
}
259259
}
260+
261+
262+
/* */
263+
.share_btn {
264+
cursor: pointer;
265+
user-select: none;
266+
}
267+
/* The actual popup */
268+
.share_btn .popuptext {
269+
visibility: hidden;
270+
width: 160px;
271+
background-color: #555;
272+
color: #fff;
273+
text-align: center;
274+
border-radius: 6px;
275+
padding: 8px 0;
276+
position: absolute;
277+
z-index: 1;
278+
bottom: 25%;
279+
left: 50%;
280+
margin-left: -80px;
281+
}
282+
283+
/* Popup arrow */
284+
.share_btn .popuptext::after {
285+
content: "";
286+
position: absolute;
287+
top: 100%;
288+
left: 50%;
289+
margin-left: -5px;
290+
border-width: 5px;
291+
border-style: solid;
292+
border-color: #555 transparent transparent transparent;
293+
}
294+
295+
/* Toggle this class - hide and show the popup */
296+
.share_btn .show {
297+
visibility: visible;
298+
animation: fadeIn 2s;
299+
animation-fill-mode: forwards;
300+
}
301+
302+
/* Add animation (fade in the popup) */
303+
@keyframes fadeIn {
304+
0% {opacity: 0;}
305+
20% {opacity: 1;}
306+
80% {opacity: 1;}
307+
100% {
308+
opacity: 0;
309+
visibility: hidden;
310+
}
311+
}

0 commit comments

Comments
 (0)