forked from PreMiD/Presences
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"$schema": "https://schemas.premid.app/metadata/1.0", | ||
"author": { | ||
"name": "Snazzah", | ||
"id": "158049329150427136" | ||
}, | ||
"url": "quizlet.com", | ||
"description": { | ||
"en": "Quizlet makes simple learning tools that let you study anything. Start learning today with flashcards, games and learning tools — all for free." | ||
}, | ||
"service": "Quizlet", | ||
"version": "1.0.0", | ||
"logo": "https://i.imgur.com/5K8iXcX.png", | ||
"thumbnail": "https://i.imgur.com/Bnxt3z4.png", | ||
"color": "#4257B2", | ||
"tags": [ | ||
"learn", | ||
"study" | ||
], | ||
"category": "other", | ||
"iframe": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const iframe = new iFrame(); | ||
|
||
interface QuizletWindow { | ||
dataLayer?: Array<{ | ||
event: string; | ||
}>; | ||
} | ||
|
||
iframe.on("UpdateData", async () => { | ||
const quizlet = (window as QuizletWindow); | ||
if (!quizlet.dataLayer) return; | ||
|
||
iframe.send({ | ||
layer: quizlet.dataLayer.find(layer => layer.event === "dataLayer-initialized"), | ||
searchLayer: quizlet.dataLayer.find(layer => layer.event === "Search") | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
const presence = new Presence({ | ||
clientId: "719784356725653504" | ||
}); | ||
|
||
interface QuizletData { | ||
layer?: { | ||
path?: string; | ||
event: string; | ||
|
||
studyableTitle?: string; | ||
studyableType?: string; | ||
}; | ||
searchLayer?: { | ||
search_term: string; | ||
} | ||
} | ||
|
||
let qzData: QuizletData = null; | ||
let actionTimestamp: number = null; | ||
|
||
presence.on("UpdateData", async () => { | ||
const data: PresenceData = { | ||
largeImageKey: "quizlet" | ||
}; | ||
|
||
if (qzData && qzData.layer) { | ||
const pathSplits = qzData.layer.path.split('/'); | ||
switch (pathSplits[0]) { | ||
case "StudyFeed": | ||
data.details = "Dashboard"; | ||
actionTimestamp = null; | ||
break; | ||
case "Settings": | ||
data.details = "Settings"; | ||
actionTimestamp = null; | ||
break; | ||
case "Profile": | ||
data.details = "Viewing profile"; | ||
data.state = document.querySelector('.ProfileHeader-username').textContent; | ||
actionTimestamp = null; | ||
break; | ||
case "Topic": | ||
data.details = "Browsing sets on"; | ||
data.state = document.querySelector('h1').textContent; | ||
actionTimestamp = null; | ||
break; | ||
case "Search": | ||
data.smallImageKey = "search"; | ||
data.smallImageText = "Searching"; | ||
data.details = "Searching"; | ||
data.state = qzData.searchLayer.search_term; | ||
actionTimestamp = null; | ||
break; | ||
case "Sets": | ||
switch (pathSplits[1]) { | ||
case "show": | ||
if (!actionTimestamp) | ||
actionTimestamp = Date.now(); | ||
data.details = "Viewing a set"; | ||
data.state = qzData.layer.studyableTitle; | ||
break; | ||
case "new": | ||
data.details = "Creating a set"; | ||
actionTimestamp = null; | ||
break; | ||
} | ||
break; | ||
case "Gravity": // Set > Gravity | ||
if (!actionTimestamp) | ||
actionTimestamp = Date.now(); | ||
data.smallImageKey = "gravity"; | ||
data.smallImageText = "Gravity"; | ||
data.details = "Playing Gravity"; | ||
data.state = `with "${qzData.layer.studyableTitle}" set`; | ||
break; | ||
case "Match": // Set > Match | ||
if (!actionTimestamp) | ||
actionTimestamp = Date.now(); | ||
data.smallImageKey = "match"; | ||
data.smallImageText = "Match"; | ||
data.details = "Playing Match"; | ||
data.state = `with "${qzData.layer.studyableTitle}" set`; | ||
break; | ||
case "LiveGame": // Set > Live | ||
if (!actionTimestamp) | ||
actionTimestamp = Date.now(); | ||
data.smallImageKey = "live"; | ||
data.smallImageText = "Quizlet Live"; | ||
data.details = "Hosting a live game"; | ||
data.state = `with "${qzData.layer.studyableTitle}" set`; | ||
break; | ||
case "Assistant": // Set > Learn | ||
if (!actionTimestamp) | ||
actionTimestamp = Date.now(); | ||
data.smallImageKey = "learn"; | ||
data.smallImageText = "Learn"; | ||
data.details = "Learning set"; | ||
data.state = qzData.layer.studyableTitle; | ||
break; | ||
case "Cards": // Set > Flashcards | ||
if (!actionTimestamp) | ||
actionTimestamp = Date.now(); | ||
data.smallImageKey = "flashcards"; | ||
data.smallImageText = "Flashcards"; | ||
data.details = "Reviewing flashcards"; | ||
data.state = `on ${qzData.layer.studyableTitle}`; | ||
break; | ||
case "Test": // Set > Test | ||
if (!actionTimestamp) | ||
actionTimestamp = Date.now(); | ||
data.smallImageKey = "test"; | ||
data.smallImageText = "Test"; | ||
data.details = "Testing"; | ||
data.state = `on ${qzData.layer.studyableTitle}`; | ||
break; | ||
case "Learn": // Set > Write | ||
if (!actionTimestamp) | ||
actionTimestamp = Date.now(); | ||
data.smallImageKey = "write"; | ||
data.smallImageText = "Writing"; | ||
data.details = "Writing"; | ||
data.state = `on ${qzData.layer.studyableTitle}`; | ||
break; | ||
case "Spell": // Set > Spell | ||
if (!actionTimestamp) | ||
actionTimestamp = Date.now(); | ||
data.smallImageKey = "spell"; | ||
data.smallImageText = "Spell"; | ||
data.details = "Spelling"; | ||
data.state = `on ${qzData.layer.studyableTitle}`; | ||
break; | ||
} | ||
} | ||
|
||
// If data doesn't exist clear else set activity to the presence data | ||
if (data.details == null) { | ||
presence.setTrayTitle(); // Clear tray | ||
presence.setActivity(); // Clear activity | ||
} else presence.setActivity(data); | ||
}); | ||
|
||
presence.on("iFrameData", (data: QuizletData) => qzData = data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist/" | ||
} | ||
} |