pianoverse_client/extra.js

65 lines
No EOL
2.5 KiB
JavaScript

if(window.PvInternals.services_client) {
console.log("pv.me has loaded correctly")
}
// custom rules
(() => {
const pv = window.PvInternals;
class PvmeRulesModal extends pv.components_pv_popup_pv_popup {
constructor() {
super();
this.innerHTML = `<dialog blocking class=popup modal><div class=header><div class=title style=margin-right:20px><i class="fas fa-info-circle"></i> Rules</div><div class=x><i class="fas fa-xmark"></i></div></div><div class=content><div class=message><b>pianoverse.me rules are very simple.</b><ul><li>Don't be annoying<li>Don't be racist<li>Do not argue punishments</ul>That's it! :)</div></div></dialog>`;
}
}
customElements.define("pvme-rules-modal", PvmeRulesModal);
pv.Modal.RULES = "pvme-rules-modal";
let oldOpen = pv.PopupManager.open;
pv.PopupManager.open = (e, ...t) => {
if(pv.Modal.RULES == e) {
let i = new PvmeRulesModal();
if (i == document.querySelector(e) && !i.querySelector("dialog").hasAttribute("closing"))
return i.close();
document.body.append(i)
i.open(...t)
return i;
} else {
return oldOpen(e, ...t)
}
}
class PvmeRules extends HTMLElement {}
customElements.define("pvme-rules", PvmeRules);
let g = document.querySelector("body > pv-header > div.left");
{ let a = document.createElement("div"); a.className = "divider"; a.style.marginLeft = "20px"; g.appendChild(a); }
{
let a = document.createElement("pvme-rules");
a.innerHTML = `<div class="icon" aria-label="Rules" data-tooltip="Rules"><i class="fas fa-scale-balanced"></i></div>`;
a.addEventListener("click", () => {
pv.PopupManager.open(pv.Modal.RULES, null);
})
g.appendChild(a);
}
})();
// change title
(() => {
const pv = window.PvInternals;
document.querySelector("pv-room").updateBrowserTab = function () {
if(pv.services_client.room.id) {
if(pv.services_client.isConnected()) {
document.title = `pv.me - ${pv.services_client.room.id} (${1 + pv.services_client.users.length})`
} else {
document.title = `pv.me - ${pv.services_client.room.id}`
}
} else {
document.title = "pv.me"
}
}
document.querySelector("body > pv-header > div.left > div.pianoverse > span").innerText = "pv.me"
})();