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.
feat(Craiyon): add presence (PreMiD#6747)
- Loading branch information
Showing
3 changed files
with
92 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,18 @@ | ||
{ | ||
"$schema": "https://schemas.premid.app/metadata/1.7", | ||
"author": { | ||
"name": "theusaf", | ||
"id": "193714715631812608" | ||
}, | ||
"service": "Craiyon", | ||
"description": { | ||
"en": "Craiyon is an AI model that can draw images from any text prompt!" | ||
}, | ||
"url": "www.craiyon.com", | ||
"version": "1.0.0", | ||
"logo": "https://i.imgur.com/uCqmcTv.png", | ||
"thumbnail": "https://i.imgur.com/cDreT5W.png", | ||
"color": "#ea580c", | ||
"category": "other", | ||
"tags": ["ai", "dalle", "image", "generation"] | ||
} |
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,68 @@ | ||
const presence = new Presence({ | ||
clientId: "1015402986534608948", | ||
}); | ||
|
||
type State = "start" | "generation" | "results"; | ||
|
||
let browsingTimestamp: number = Date.now() / 1000, | ||
oldPrompt: string = null, | ||
activityState: State = "start"; | ||
|
||
presence.on("UpdateData", () => { | ||
const presenceData: PresenceData = { | ||
largeImageKey: "https://i.imgur.com/uCqmcTv.png", | ||
startTimestamp: browsingTimestamp, | ||
}, | ||
{ pathname } = window.location; | ||
switch (pathname) { | ||
case "/": { | ||
const input = document.querySelector<HTMLDivElement>("#prompt"), | ||
container = document.querySelector( | ||
".h-full.w-full > .relative > div > div" | ||
); | ||
presenceData.state = input.textContent | ||
? `"${input.textContent}"` | ||
: "Waiting for input..."; | ||
if (container.querySelector("svg.text-gray-300")) | ||
presenceData.details = "Thinking of a prompt"; | ||
else if ( | ||
input.nextElementSibling | ||
.querySelector("img") | ||
.classList.contains("animate-wiggle") | ||
) { | ||
if (activityState !== "generation") { | ||
presenceData.startTimestamp = browsingTimestamp = Date.now() / 1000; | ||
oldPrompt = input.textContent; | ||
activityState = "generation"; | ||
} | ||
presenceData.details = "Generating images"; | ||
presenceData.state = `"${oldPrompt}"`; | ||
} else { | ||
if (activityState !== "results") { | ||
presenceData.startTimestamp = browsingTimestamp = Date.now() / 1000; | ||
activityState = "results"; | ||
} | ||
if (document.activeElement === input && input.textContent !== oldPrompt) | ||
presenceData.details = "Thinking of a new prompt"; | ||
else if (container.childElementCount > 3) { | ||
presenceData.details = "Viewing results"; | ||
presenceData.state = `"${oldPrompt}"`; | ||
} else { | ||
presenceData.details = "Viewing a generated image"; | ||
presenceData.state = `"${oldPrompt}"`; | ||
} | ||
} | ||
break; | ||
} | ||
case "/privacy": { | ||
presenceData.details = "Reading privacy policy"; | ||
break; | ||
} | ||
case "/terms": { | ||
presenceData.details = "Reading terms and conditions"; | ||
break; | ||
} | ||
} | ||
if (presenceData.details) presence.setActivity(presenceData); | ||
else presence.setActivity(); | ||
}); |
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/" | ||
} | ||
} |