patch shit properly

This commit is contained in:
Soph :3 2024-11-25 17:25:15 +02:00
parent 5c0c24a170
commit 09436dfdb7
Signed by: sophie
GPG key ID: EDA5D222A0C270F2
8 changed files with 190 additions and 24 deletions

View file

@ -0,0 +1,25 @@
def downloadScript [] {
rm -f bundle.js
print $"(ansi yellow)Downloading the script.."
wget -q https://pianoverse.net/bundle.js
}
def applyPatches [] {
print $"(ansi yellow)Applying patches!.."
let patches = (ls build | find .patch | each { |i| $i.name })
$patches
| each {|i|
let splitted = open $i | split row -r '\n';
let needle = $splitted | get 0;
let haystack = $splitted | skip 1 | str join "";
open bundle.js | str replace $needle $haystack| save -f bundle.js
print $"(ansi green)Applied patch ($i)!"
}
}
downloadScript
applyPatches
print $"(ansi green)Happy hacking!"

16
build/downloadSounds.nu Normal file
View file

@ -0,0 +1,16 @@
mkdir sounds
cd sounds
mkdir grand
mkdir salamander
mkdir soft
mkdir electric
cd salamander
for $x in 21..108 {wget $"https://pianoverse.net/sounds/salamander/($x).mp3"}
cd grand
for $x in 21..108 {wget $"https://pianoverse.net/sounds/grand/($x).mp3"}
cd soft
for $x in 21..108 {wget $"https://pianoverse.net/sounds/soft/($x).mp3"}
cd electric
for $x in 21..108 {wget $"https://pianoverse.net/sounds/electric/($x).mp3"}

7
build/internal.patch Normal file

File diff suppressed because one or more lines are too long

10
build/ws.patch Normal file
View file

@ -0,0 +1,10 @@
this._ws=new WebSocket("wss://pianoverse.net","pianoverse")
let wsurl="";
if(!localStorage.host) {
wsurl = "wss://api.pianoverse.me";
} else if(localStorage.host=="mainline") {
wsurl = "wss://pianoverse.net"
} else if(localStorage.host == "dev") {
wsurl = "ws://127.0.0.1:8081"
};
this._ws = new WebSocket(wsurl,"pianoverse")

File diff suppressed because one or more lines are too long

112
extra.js Normal file
View file

@ -0,0 +1,112 @@
// iife is only so "pv" doesn't go into globals
(() => {
const pv = window.PvInternals;
if(pv.services_client) {
console.log("pv.me has loaded correctly")
}
//#region custom modal
class PvmeRulesModal extends pv.components_pv_popup_pv_popup {
constructor() {
super();
this.message = "yo"
this.innerHTML = `
<dialog class="popup" modal blocking>
<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>
<li>Don't be racist</li>
<li>Do not argue punishments</li>
</ul>
That's it! :)
</div>
</div>
</dialog>`;
}
}
customElements.define("pvme-rules-modal", PvmeRulesModal);
pv.Modal.RULES = "pvme-rules-modal";
//#endregion custom modal
//#region break PopupMananger so it takes our new popup into account
pv.PopupManager.open = (e, ...t) => {
let i;
if (i = document.querySelector(e),
i && !i.querySelector("dialog").hasAttribute("closing"))
return i.close(),
i;
switch (e) {
case pv.Modal.BAN:
i = new components_popups_pv_ban_pv_ban;
break;
case pv.Modal.PROFILE:
i = new components_popups_pv_profile_pv_profile;
break;
case pv.Modal.SETTINGS:
i = new components_popups_pv_settings_pv_settings;
break;
case pv.Modal.MESSAGE:
i = new components_popups_pv_message_pv_message;
break;
case pv.Modal.NEW_ROOM:
i = new components_popups_pv_new_room_pv_new_room;
break;
case pv.Modal.NEW_ROOM:
i = new components_popups_pv_new_room_pv_new_room;
break;
case pv.Modal.RULES:
i = new PvmeRulesModal;
break;
case pv.Dialog.ROOMS:
i = new components_popups_pv_rooms_pv_rooms;
break;
case pv.Dialog.ACTIONS:
i = new components_popups_pv_actions_pv_actions;
break;
case pv.Dialog.DEVICES:
i = new components_popups_pv_devices_pv_devices;
break;
case pv.Dialog.SOUNDS:
i = new components_popups_pv_sounds_pv_sounds;
break;
case pv.Dialog.TRANSPOSE:
i = new components_popups_pv_transpose_pv_transpose;
break;
case pv.Dialog.VELOCITY:
i = new components_popups_pv_velocity_pv_velocity;
break;
default:
throw new Error(`Popup ${e} not found`)
}
return i && (document.body.append(i),
i.open(...t)),
i
}
//#endregion
//#region pvme rules
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, "Rules.\nDon't be annoying.\n\nThat's it.");
})
g.appendChild(a);
}
//#endregion pvme rules
})();

View file

@ -1,7 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<!-- Mirrored from pianoverse.net/ by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 25 Nov 2024 08:27:12 GMT -->
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="author" content="https://github.com/charleprr" /> <meta name="author" content="https://github.com/charleprr" />
@ -34,6 +32,7 @@
<link rel="canonical" href="index.html" /> <link rel="canonical" href="index.html" />
<title>Pianoverse - Play piano with your friends!</title> <title>Pianoverse - Play piano with your friends!</title>
<script src="bundle.js" defer></script> <script src="bundle.js" defer></script>
<script src="extra.js" defer></script>
<script src="https://kit.fontawesome.com/4044784fdc.js" crossorigin="anonymous"></script> <script src="https://kit.fontawesome.com/4044784fdc.js" crossorigin="anonymous"></script>
</head> </head>
<body> <body>
@ -50,6 +49,4 @@
</div> </div>
</div> </div>
</body> </body>
<!-- Mirrored from pianoverse.net/ by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 25 Nov 2024 08:27:19 GMT -->
</html> </html>

View file

@ -1,28 +1,27 @@
# [Pianoverse Client for pianoverse.me](https://pianoverse.me/) # [Pianoverse Client for pianoverse.me](https://pianoverse.me/)
Extracted from the https://pianoverse.net site at 10:33, November 25. Extracted from the https://pianoverse.net site at 10:33, November 25.
Bundle.js has modifications to point towards "api.pianoverse.me"
Commit ID: 6202927ae53e43bafd8b8fd3be1ffcaaa45426a3 Commit ID: 6202927ae53e43bafd8b8fd3be1ffcaaa45426a3
``` ## Patches
let wsurl = ""; This client contains two patches, internal.patch, and ws.patch.
if(!localStorage.host){
wsurl = "wss://api.pianoverse.me";
} else if(localStorage.host == "mainline") {
wsurl = "wss://pianoverse.net"
} else if(localStorage.host == "dev") {
wsurl = "ws://127.0.0.1:8081"
};
this._ws=new WebSocket(wsurl,"pianoverse") 1. ws.patch
```
s/`,services_client=client;`/`,services_client=client;window.client=client;` | localStorage.host value | connnects to |
s/`this._ws=new WebSocket("wss://pianoverse.net","pianoverse")`/`let wsurl="";if(!localStorage.host){wsurl = "wss://api.pianoverse.me";}else if(localStorage.host=="mainline"){wsurl="wss://pianoverse.net"}else if(localStorage.host == "dev"){wsurl="ws://127.0.0.1:8081"};this._ws=new WebSocket(wsurl,"pianoverse")` |:-----------------------:|:-----------------:|
| | api.pianoverse.me |
| mainline | pianoverse.net |
| dev | 127.0.0.1:8081 |
To reverse these modifications, run `localStorage.host = "mainline"`. You can also make it point towards 127.0.0.1:8081 with `localStorage.host = "dev"` 2. internal.patch
Exposes all internal pianoverse APIs on window.PvInternals.
Nushell script for downloading all sounds:
```nu Use nushell and `build/createPatchedBundle.nu` in the root to create a bundle.js.
for $x in 21..108 {wget $"https://pianoverse.net/sounds/salamander/($x).mp3"}
``` ## extra.js
extra.js is a quick attempt to implement a new feature for Pianoverse with the internal APIs, which is possible, however hard. It adds a simple button for rules and a new modal. It **requires the internal patch** and for it to be added in index.html.
## Sounds
Use the `build/downloadSounds.nu` nushell script to download all sounds.