Skip to content

Commit

Permalink
Add Quizlet Presence
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Jun 9, 2020
1 parent 23146f7 commit dee7ec0
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 0 deletions.
22 changes: 22 additions & 0 deletions websites/Q/Quizlet/dist/metadata.json
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
}
17 changes: 17 additions & 0 deletions websites/Q/Quizlet/iframe.ts
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")
});
});
142 changes: 142 additions & 0 deletions websites/Q/Quizlet/presence.ts
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);
6 changes: 6 additions & 0 deletions websites/Q/Quizlet/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist/"
}
}

0 comments on commit dee7ec0

Please sign in to comment.