Skip to content

Commit 4b1cf3e

Browse files
authored
Merge pull request #4 from rahulv07/frontend
Websocket URL change from local to live server in Glitch
2 parents 68b51b5 + e713f31 commit 4b1cf3e

File tree

4 files changed

+64
-9
lines changed

4 files changed

+64
-9
lines changed

app.js

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,37 @@ chrome.identity.getProfileUserInfo(function(browserUser){
55
document.getElementsByClassName("browserID")[0].textContent = "ID: " + sourceID;
66
});
77

8+
document.getElementsByTagName("i")[0].addEventListener("click",(event)=>{
9+
const sinkBrowserID = prompt("Enter the browser ID");
10+
if(sinkBrowserID != null){
11+
const nickName = prompt("Enter nickname for browser " + sinkBrowserID);
12+
if(nickName != null){
13+
chrome.storage.local.get({lyncSavedSources:[]},(result) => {
14+
var lyncSavedSources = result.lyncSavedSources;
15+
lyncSavedSources.push({sourceID:sinkBrowserID,nickName:nickName});
16+
chrome.storage.local.set({lyncSavedSources:lyncSavedSources},()=>{
17+
window.close();
18+
});
19+
});
20+
}
21+
}
22+
});
23+
24+
function removeBrowser(browserID){
25+
chrome.storage.local.get({lyncSavedSources:[]},(result) => {
26+
var lyncSavedSources = result.lyncSavedSources;
27+
for(var b in lyncSavedSources){
28+
if(lyncSavedSources[b].sourceID == browserID){
29+
lyncSavedSources.splice(b,1);
30+
break;
31+
}
32+
}
33+
chrome.storage.local.set({lyncSavedSources:lyncSavedSources},()=>{
34+
window.close();
35+
})
36+
});
37+
}
38+
839
function loadSinkNames(){
940
var currentDiv = document.getElementsByClassName("paired")[0];
1041

@@ -15,13 +46,25 @@ function loadSinkNames(){
1546
const sinkDiv = document.createElement("div");
1647
sinkDiv.setAttribute("class","sinks");
1748

18-
const sinkName = document.createElement("p").appendChild(document.createTextNode(lyncSavedSources[i].nickName));
19-
sinkDiv.appendChild(sinkName);
49+
const sinkNameSpan = document.createElement("span");
50+
sinkNameSpan.setAttribute("class","sinkName");
51+
sinkNameSpan.appendChild(document.createElement("p").appendChild(document.createTextNode(lyncSavedSources[i].nickName)));
52+
sinkDiv.appendChild(sinkNameSpan);
53+
54+
const trashIconSpan = document.createElement("span");
55+
const trashIcon = document.createElement("i");
56+
trashIcon.setAttribute("class","trashIcon fa-solid fa-trash");
57+
trashIconSpan.appendChild(trashIcon);
58+
sinkDiv.appendChild(trashIconSpan);
2059

21-
sinkDiv.addEventListener("click",(event) => {
60+
sinkNameSpan.addEventListener("click",(event) => {
2261
sendLink(sourceID,lyncSavedSources[i].sourceID);
2362
});
2463

64+
trashIcon.addEventListener("click",(event) => {
65+
removeBrowser(lyncSavedSources[i].sourceID);
66+
});
67+
2568
currentDiv.after(sinkDiv);
2669
currentDiv = sinkDiv;
2770
}
@@ -42,7 +85,7 @@ function sendLink(sourceID,sinkID) {
4285

4386
chrome.runtime.sendMessage(data,(res)=>{
4487
if(res.status == "SUCCESS"){
45-
alert("Link Sent!");
88+
window.close();
4689
}
4790
else{
4891
alert("Error sending the link!");

background.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ chrome.identity.getProfileUserInfo(function(browserUser){
55
sourceID = browserUser.id;
66
});
77

8-
connection = new WebSocket("ws://localhost:8080");
8+
connection = new WebSocket("wss://lync-api.glitch.me");
99

1010
connection.onopen = (event) => {
1111
console.log("Connected to server.");

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
<h3 class="title">Lync</h3>
1414
<p class="browserID">ID: </p>
1515
<div class="paired">
16-
<p>Paired <i class="fa-regular fa-square-plus"></i></p>
16+
Paired <i class="plusIcon fa-regular fa-square-plus"></i>
1717
</div>
18+
<div class="bottomSpace"></div>
1819

1920
<script src="app.js"></script>
2021
</body>

styles.css

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@ p.browserID{
1717
margin-bottom: 4%;
1818
}
1919

20-
div.paired > p{
20+
div.paired{
2121
padding-left: 8%;
2222
padding-right: 8%;
23-
margin: 0%;
23+
margin-bottom: 3%;
2424
color: grey;
2525
font-size: 17px;
2626
}
2727

2828
div.sinks{
29-
padding: 8%;
29+
display: flex;
30+
justify-content: space-between;
31+
padding-left: 8%;
32+
padding-right: 8%;
3033
font-size: 13px;
3134
}
3235

@@ -36,4 +39,12 @@ div.sinks:hover{
3639

3740
i{
3841
color: black;
42+
}
43+
44+
span.sinkName{
45+
width: 90%;
46+
}
47+
48+
div.bottomSpace{
49+
padding: 3%;
3950
}

0 commit comments

Comments
 (0)