Skip to content

Commit 6a8744b

Browse files
committed
Comments
1 parent ed0b5b6 commit 6a8744b

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

ttu-reader/content.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function observeTitleChanges() {
22
const observer = new MutationObserver((mutations) => {
33
mutations.forEach((mutation) => {
44
if (mutation.type === "childList") {
5-
updateDiscordPresence(); // Call your function to update the presence
5+
updateDiscordPresence();
66
}
77
});
88
});
@@ -17,7 +17,7 @@ let currentBookId = null;
1717
let startTime = null;
1818

1919
function getBookIdFromUrl(url) {
20-
const match = url.match(/b\?id=(\d+)/); // Assuming book ID is always a number
20+
const match = url.match(/b\?id=(\d+)/);
2121
return match ? match[1] : null;
2222
}
2323

@@ -33,7 +33,7 @@ function updateDiscordPresence() {
3333
details = title;
3434

3535
if (newBookId !== currentBookId) {
36-
startTime = Date.now(); // Reset start time only if the book ID has changed
36+
startTime = Date.now();
3737
startTimestamp = startTime;
3838
currentBookId = newBookId;
3939
}
@@ -54,19 +54,19 @@ function updateDiscordPresence() {
5454
},
5555
body: JSON.stringify({ details, startTimestamp }),
5656
})
57-
.catch(console.error); // Handle any errors gracefully
57+
.catch(console.error);
5858
}
5959

6060
if (document.readyState === "complete" || document.readyState === "interactive") {
61-
setTimeout(observeTitleChanges, 1); // Start observing changes after the page is fully loaded
61+
setTimeout(observeTitleChanges, 1); // Start observing changes once the page is fully loaded
6262
} else {
6363
document.addEventListener("DOMContentLoaded", observeTitleChanges);
6464
}
6565

6666
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
6767
if (request.action === "resetTimer") {
68-
startTime = Date.now(); // Reset the start time to current
69-
updateDiscordPresence(); // Update the presence immediately
68+
startTime = Date.now();
69+
updateDiscordPresence();
7070
sendResponse({status: "timerReset"});
7171
}
7272
});

ttu-reader/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"manifest_version": 3,
3-
"name": "Ebook Reader Discord Presence",
3+
"name": "ttu Rich Presence",
44
"version": "1.0",
5-
"description": "Updates Discord Rich Presence based on ebook reading activity.",
5+
"description": "Adds support for Discord rich presence for ッツ Ebook Reader",
66
"permissions": ["activeTab", "scripting"],
77
"background": {
88
"service_worker": "background.js"

ttu-reader/popup.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
document.getElementById('pauseButton').addEventListener('click', function() {
22
const button = document.getElementById('pauseButton');
3-
const isPaused = button.textContent.includes("Paused"); // Check if already paused
3+
const isPaused = button.textContent.includes("Paused");
44
fetch('http://localhost:3000/clear-presence', {
55
method: 'POST',
66
headers: {
@@ -10,7 +10,7 @@ document.getElementById('pauseButton').addEventListener('click', function() {
1010
})
1111
.then(response => {
1212
if (response.ok) {
13-
button.style.backgroundColor = 'lightgrey'; // Lighter grey when paused
13+
button.style.backgroundColor = 'lightgrey';
1414
button.textContent = 'Cleared Rich Presence';
1515
console.log('Rich presence cleared.');
1616
}
@@ -19,8 +19,7 @@ document.getElementById('pauseButton').addEventListener('click', function() {
1919
});
2020

2121
document.getElementById('resetTimerButton').addEventListener('click', function() {
22-
// Send a message to content script to reset startTime
2322
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
24-
chrome.tabs.sendMessage(tabs[0].id, {action: "resetTimer"});
23+
chrome.tabs.sendMessage(tabs[0].id, {action: "resetTimer"}); // Send message to content script to reset startTime
2524
});
2625
});

ttu-server/server.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const express = require('express');
2-
const cors = require('cors'); // Import CORS module
2+
const cors = require('cors');
33
const app = express();
44
const PORT = 3000;
55
const { Client } = require('discord-rpc');
6-
const clientId = '1207008423078789140'; // Replace with your Discord Application Client ID
6+
const clientId = '1207008423078789140';
77

88
const rpc = new Client({ transport: 'ipc' });
99
let connected = false;
@@ -13,9 +13,7 @@ rpc.on('ready', () => {
1313
connected = true;
1414
});
1515

16-
// Use CORS middleware to allow all origins
1716
app.use(cors());
18-
1917
app.use(express.json());
2018

2119
app.post('/update-presence', (req, res) => {

0 commit comments

Comments
 (0)