diff --git a/src/webpage/infiniteScroller.ts b/src/webpage/infiniteScroller.ts index 655c814..7c73cfc 100644 --- a/src/webpage/infiniteScroller.ts +++ b/src/webpage/infiniteScroller.ts @@ -49,7 +49,7 @@ class InfiniteScroller { async getDiv(initialId: string): Promise { if (this.div) { - throw new Error("Div already exists, exiting."); + return this.div; } this.resetVars(); const scroll = document.createElement("div"); diff --git a/src/webpage/style.css b/src/webpage/style.css index 2bc044c..c072d74 100644 --- a/src/webpage/style.css +++ b/src/webpage/style.css @@ -2598,6 +2598,17 @@ img.bigembedimg { animation-fill-mode: forwards; animation-timing-function: cubic-bezier(0.28, 0.48, 0.24, 1.27); } + input { + width: calc(100% - 20px); + margin: 0px 10px; + margin-bottom: 10px; + box-sizing: border-box; + padding: 10px; + background: var(--secondary-bg); + border: none; + border-radius: 5px; + font-size: 14px; + } } @keyframes fade-in { 0% { diff --git a/src/webpage/user.ts b/src/webpage/user.ts index ecfce37..645d3f6 100644 --- a/src/webpage/user.ts +++ b/src/webpage/user.ts @@ -154,10 +154,12 @@ class User extends SnowFlake { } static contextmenu = new Contextmenu("User Menu"); - async opendm() { + async opendm(message?: string) { for (const dm of (this.localuser.guildids.get("@me") as Direct).channels) { - if (dm.type === 1 && dm.users[0].id === this.id) { + if ((dm.type === 1 || dm.type === undefined) && dm.users[0].id === this.id) { this.localuser.goToChannel(dm.id); + if (message) + dm.sendMessage(message, {attachments: [], embeds: [], replyingto: null, sticker_ids: []}); return; } } @@ -171,6 +173,22 @@ class User extends SnowFlake { .then((json) => { this.localuser.goToChannel(json.id); }); + if (message) { + while (true) { + for (const dm of (this.localuser.guildids.get("@me") as Direct).channels) { + if ((dm.type === 1 || dm.type === undefined) && dm.users[0].id === this.id) { + dm.sendMessage(message, { + attachments: [], + embeds: [], + replyingto: null, + sticker_ids: [], + }); + return; + } + } + await new Promise((res) => setTimeout(res, 100)); + } + } return; } async changeRelationship(type: 0 | 1 | 2 | 3 | 4 | 5) { @@ -1111,9 +1129,20 @@ class User extends SnowFlake { } }); + const send = document.createElement("input"); + div.append(send); + send.placeholder = I18n.user.sendMessage(this.name); + send.onkeyup = (e) => { + if (e.key === "Enter") { + this.opendm(send.value); + div.remove(); + } + }; + if (guild) { membres.then((member) => { if (!member) return; + send.placeholder = I18n.user.sendMessage(member.name); usernamehtml.textContent = member.name; if (this.bot) { const username = document.createElement("span"); @@ -1139,6 +1168,7 @@ class User extends SnowFlake { userbody.append(roles); }); } + if (x !== -1) { Contextmenu.declareMenu(div); document.body.appendChild(div); diff --git a/translations/en.json b/translations/en.json index e3eff44..31070c2 100644 --- a/translations/en.json +++ b/translations/en.json @@ -191,7 +191,7 @@ "searchGifs": "Search Tenor", "muteDuration":"Unmute in:", "channel": { - "typebox":"Message in $1", + "typebox":"Message in $1", "creating": "Creating channel", "name": "Channel", "copyId": "Copy channel id", @@ -622,6 +622,7 @@ "name": "Direct Messages" }, "user": { + "sendMessage":"Message @$1", "copyId": "Copy user ID", "online": "Online", "offline": "Offline",