BlacketDMs

a userscript to add dms to blacket v2

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         BlacketDMs
// @description  a userscript to add dms to blacket v2
// @version      1.0.1
// @icon         https://blacket.org/content/logo.png

// @author       zastix
// @namespace    https://zastix.club

// @match        *://blacket.org/*
// @match        *://blacket.xotic.org/*
// @match        *://blacket.zastix.com/*
// @match        *://dashboard.iblooket.com/*
// @match        *://b.blooketis.life/*
// @match        *://b.fart.services/*

// @grant        none
// @run-at document-idle
// ==/UserScript==
"use strict";(()=>{var f=class{dms=[];constructor(){let e=localStorage.getItem("dms");if(e)try{this.dms=JSON.parse(e)}catch(t){console.error("Error parsing dms",t),localStorage.setItem("dms",JSON.stringify(this.dms))}}saveDms(){localStorage.setItem("dms",JSON.stringify(this.dms))}async getUser(e){return new Promise((t,r)=>{window.blacket.requests.get("/worker2/user/"+e,o=>{if(o.error)return r(o.error);t(o.user)})})}getDmWithUser(e){return this.dms.find(t=>t.person==e)}closeDm(e){this.dms=this.dms.filter(t=>t.id!==e),this.saveDms()}openDm(e,t){this.dms.find(r=>r.id===e)||(this.dms.push({id:e,person:t}),this.saveDms())}getDms(){return this.dms}setDms(e){this.dms=e,this.saveDms()}getDmsObject(){return this.dms.reduce((e,t)=>(e[t.id]=t,e),{})}async getFormattedDmObject(){let e={};for(let t of this.dms){let r=window.blacket.chat.cached.users[t.person]??await this.getUser(t.person);e[t.id]={name:`[DM] ${r.username}`,date:0}}return e}};var D=["a","b","i"],l=new Map;function v(s,e,t,r,o){let n=l.get(e)?.[s];if(!n)return o?Reflect.construct(e[s],t,r):e[s].apply(r,t);for(let i of n.b.values()){let c=i.call(r,t);Array.isArray(c)&&(t=c)}let a=[...n.i.values()].reduce((i,c)=>(...g)=>c.call(r,g,i),(...i)=>o?Reflect.construct(n.o,i,r):n.o.apply(r,i))(...t);for(let i of n.a.values())a=i.call(r,t,a)??a;return a}function M(s,e,t,r){let o=l.get(s),n=o?.[e];return n?.[r].has(t)?(n[r].delete(t),D.every(a=>n[a].size===0)&&(Reflect.defineProperty(s,e,{value:n.o,writable:!0,configurable:!0})||(s[e]=n.o),delete o[e]),Object.keys(o).length==0&&l.delete(s),!0):!1}var w=s=>(e,t,r,o=!1)=>{if(typeof t[e]!="function")throw new Error(`${e} is not a function in ${t.constructor.name}`);l.has(t)||l.set(t,Object.create(null));let n=l.get(t);if(!n[e]){let c=t[e];n[e]={o:c,b:new Map,i:new Map,a:new Map};let g=(u,d,p)=>{let O=v(e,t,d,u,p);return o&&i(),O},_=new Proxy(c,{apply:(u,d,p)=>g(d,p,!1),construct:(u,d)=>g(c,d,!0),get:(u,d,p)=>d=="toString"?c.toString.bind(c):Reflect.get(u,d,p)});Reflect.defineProperty(t,e,{value:_,configurable:!0,writable:!0})||(t[e]=_)}let a=Symbol(),i=()=>M(t,e,a,s);return n[e][s].set(a,r),i};var L=w("b"),h=w("i"),k=w("a");var m=new f,j=!1,C=!1,b=!1,x=window.bb?.plugins?.active?.includes("Better Chat"),y=async()=>{if(!window.blacket||(j||(h("get",window.blacket.requests,(s,e)=>s[0]==="/worker/my-rooms"?e(s[0],async t=>t.error?s[1](t):s[1]({error:!1,rooms:{...t.rooms,...await m.getFormattedDmObject()}})):s[0].startsWith("/worker2/messages/")&&!s[0].startsWith("/worker2/messages/0")?e(s[0],async t=>t.error||t.messages.length==0?s[1](t):(t.messages.at(-1).message.content.startsWith("BDM-")&&t.messages.pop(),s[1]({error:!1,messages:t.messages}))):e(...s)),j=!0),!window.blacket.appendChat)||(C||(k("appendChat",window.blacket,async s=>{if(window.blacket.config.path==="trade"||s[0].room.name==="trade"||s[0].room.id!==window.blacket.chat.room)return;let e=$(`#message-${s[0].message.id}`),t;x?t=Object.entries(e.siblings()[1].children[0].children[0]).find(r=>r[0].includes("jQuery"))[1]:t=Object.entries(e.siblings()[1]).find(r=>r[0].includes("jQuery"))[1],k("handler",t.events.contextmenu[0],async()=>{$(".styles__contextMenuContainer___3jAmv-camelCase").append('<div class="styles__contextMenuItemContainer___m3Xa3-camelCase" id="user-context-message"><div class="styles__contextMenuItemName___vj9a3-camelCase">Message</div><i class="styles__contextMenuItemIcon___2Zq3a-camelCase fas fa-message"></i></div>').on("click","#user-context-message",async()=>{let r=window.blacket.chat.cached.users[e[0].getAttribute("data-user-id")]??await m.getUser(e[0].getAttribute("data-user-id")),o=m.getDmWithUser(r.id);if(o)return window.blacket.switchToRoom("[DM] "+r.username,parseInt(o.id));b=!0,window.blacket.createToast({title:"Info",message:"User is not in your DMs, attempting to create DM.",icon:"/content/blooks/Info.webp",time:6e3}),window.blacket.requests.post("/worker/trades/requests/send",{user:e[0].getAttribute("data-user-id")})})})}),C=!0),!window.blacket.socket.listeners["trading-requests-accepted"]||!window.blacket.socket.listeners["messages-create"]))return setTimeout(y,1);if(k("messages-create",window.blacket.socket.listeners,s=>{if(s[0].data.message.content.startsWith("BDM-")&&s[0].data.room.name==="trade"&&s[0].data.message.user!==window.blacket.user.id){let[e,t]=atob(s[0].data.message.content.split("BDM-")[1]).split("|");m.openDm(e,t)}}),h("trading-requests-accepted",window.blacket.socket.listeners,(s,e)=>{if(b){window.blacket.requests.get("/worker/trades/ongoing",t=>{m.openDm(t.trade.room.toString(),Object.keys(t.trade.users).find(r=>r!==window.blacket.user.id)),setTimeout(()=>{window.blacket.socket.emit("messages-create",{room:t.trade.room,content:`BDM-${btoa(`${t.trade.room}|${window.blacket.user.id}`)}`}),setTimeout(()=>{window.blacket.socket.emit("trading-ongoing-decline"),b=!1,window.blacket.createToast({title:"Success",message:"User accepted the trade request, DM created, reload to see the room.",icon:"/content/blooks/Success.webp",time:6e3})},1e3)},4500)});return}return e(...s)}),h("trading-requests-declined",window.blacket.socket.listeners,(s,e)=>{if(b){b=!1,window.blacket.createToast({title:"Error",message:"User declined the trade request, failed to create DM.",icon:"/content/blooks/Error.webp",time:6e3});return}return e(...s)}),window.blacket.config.path=="settings"){$(".styles__mainContainer___4TLvi-camelCase").append('<div class="styles__infoContainer___2uI-S-camelCase"><div class="styles__headerRow___1tdPa-camelCase"><i class="fas fa-message styles__headerIcon___1ykdN-camelCase" aria-hidden="true"></i><div class="styles__infoHeader___1lsZY-camelCase">BlacketDMs</div></div><div><a id="backupDmsBtn" class="styles__link___5UR6_-camelCase">Backup DMs</a></div><div><a id="importDmsBtn" class="styles__link___5UR6_-camelCase">Import DMs</a></div><div><a id="clearDmsBtn" class="styles__link___5UR6_-camelCase">Clear DMs</a></div><p style="padding: 0;margin: 0;font-size: 0.7rem;color: #c2bbbb;">made by zastix, <a href="https://zastix.club/" target="_blank">https://zastix.club/</a></p></div>');let s=async(e,t)=>{let r=new Blob([e],{type:"text/plain"}),o=URL.createObjectURL(r),n=document.createElement("a");n.href=o,n.download=t,n.click()};$("#backupDmsBtn").on("click",async()=>{let e=JSON.stringify(m.getDms());s(e,`blacketDmsBackup-${Date.now()}.json`)}),$("#importDmsBtn").on("click",async()=>{let e=document.createElement("input");e.type="file",e.accept=".json",e.click(),e.onchange=async()=>{let t=e.files?.[0];if(!t)return;let r=new FileReader;r.onload=async()=>{let o=JSON.parse(r.result);m.setDms(o),window.blacket.createToast({title:"Success",message:"DMs imported successfully, reload to see the changes.",icon:"/content/blooks/Success.webp",time:6e3})},r.readAsText(t)}}),$("#clearDmsBtn").on("click",async()=>{confirm("Are you sure you want to clear all DMs? This is irreversible")&&(m.setDms([]),window.blacket.createToast({title:"Success",message:"DMs cleared successfully, reload to see the changes.",icon:"/content/blooks/Success.webp",time:6e3}))})}};y();})();
// made by zastix