Skip to content

Commit

Permalink
Add Qwant Presence
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Jun 8, 2020
1 parent 7efcedc commit 06e0a24
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
23 changes: 23 additions & 0 deletions websites/Q/Qwant/dist/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://schemas.premid.app/metadata/1.0",
"author": {
"name": "Snazzah",
"id": "158049329150427136"
},
"url": [
"www.qwant.com",
"www.qwantjunior.com"
],
"description": {
"en": "Qwant is a search engine that respects your privacy and eases discovering and sharing via a social approach."
},
"service": "Qwant",
"version": "1.0.0",
"logo": "https://i.imgur.com/peAp6sZ.png",
"thumbnail": "https://i.imgur.com/nEMCic5.png",
"color": "#4BA2EA",
"tags": [
"search"
],
"category": "other"
}
93 changes: 93 additions & 0 deletions websites/Q/Qwant/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
var presence = new Presence({
clientId: "719331723560878091"
});

interface ItemMap {
[key: string]: string;
}

const browsingTimestamp = Math.floor(Date.now() / 1000);

const searchTypeMap: ItemMap = {
web: 'Searching on the web',
news: 'Searching the news',
images: 'Searching images',
videos: 'Searching videos',
social: 'Searching social media',
shopping: 'Searching for products'
}

const searchMusicTypeMap: ItemMap = {
overview: 'Searching music',
albums: 'Searching music albums',
artists: 'Searching music artists',
songs: 'Searching songs'
}

const searchJuniorTypeMap: ItemMap = {
web: 'Searching on the web',
images: 'Searching images',
videos: 'Searching videos',
education: 'Searching educational content',
}

presence.on("UpdateData", async () => {
const data: PresenceData = {
largeImageKey: "qwant",
startTimestamp: browsingTimestamp
};

let query: URLSearchParams = null;

if (location.hostname === "www.qwant.com") {
const firstPath = location.pathname.split('/')[1];
switch (firstPath) {
case "":
query = new URLSearchParams(location.search);
if (query.has('q')) {
data.details = searchTypeMap[query.get('t')];
data.state = query.get('q');
} else data.details = "Home";
break;
case "music":
if (location.pathname === "/music/search") {
query = new URLSearchParams(location.search);
data.smallImageKey = "music";
data.smallImageText = "Qwant Music";
if (query.has('q')) {
data.details = searchMusicTypeMap[query.get('t')];
data.state = query.get('q');
}
} else data.details = "Music Home";
break;
case "maps":
data.smallImageKey = "maps";
data.smallImageText = "Qwant Maps";
data.details = "Looking at maps";
break;
}
} else if (location.hostname === "www.qwantjunior.com") {
data.largeImageKey = "qwantjunior";
query = new URLSearchParams(location.search);
switch (location.pathname) {
case "/":
if (query.has('q')) {
data.details = searchJuniorTypeMap[query.get('type')] + " in Qwant Junior";
data.state = query.get('q');
} else data.details = "Junior Home";
break;
case "/news":
if (query.has('q')) {
data.details = "Searching the news on Qwant Junior";
data.state = query.get('q');
} else data.details = "Junior News Home";
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);
});
6 changes: 6 additions & 0 deletions websites/Q/Qwant/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 06e0a24

Please sign in to comment.