Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
OblivCode authored Aug 12, 2021
1 parent b3b3747 commit 405ba70
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
62 changes: 62 additions & 0 deletions extension/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var connected = false
var ws
function start() {
if(connected) {return}
ws = new WebSocket("ws://localhost:800")

connected = true
ws.onopen = function() {
console.log('connected');
connected = true
Update()
}
ws.onmessage = function(message) {
console.log(message)
if(message == "resend") {
Update()
}
}
ws.onclose = function() {
connected = false
}
}

chrome.windows.onRemoved.addListener(function(windowid) {
if(connected) {
ws.send("closed")
ws.close(1, "window closed")
}
})

chrome.tabs.onActivated.addListener(function(activeInfo) {
Update()
})
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(connected) {
let bundle = {
"title": tab.title,
"url": tab.url
}
let jsonBundle = JSON.stringify(bundle)
console.log(jsonBundle)
ws.send(jsonBundle)
}
})

function Update() {
chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
let tab = tabs[0]
if(connected) {
let bundle = {
"title": tab.title,
"url": tab.url
}
let jsonBundle = JSON.stringify(bundle)
console.log(jsonBundle)
ws.send(jsonBundle)
}
});
}


setInterval(start, 1000)
13 changes: 13 additions & 0 deletions extension/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "OBC's RP Extension",
"description": "Browser extension for OBC's Discord Rich Presence",
"version": "1.0.0",
"manifest_version": 3,
"permissions": [
"activeTab",
"tabs"
],
"background": {
"service_worker": "background.js"
}
}

0 comments on commit 405ba70

Please sign in to comment.