Skip to content

Instantly share code, notes, and snippets.

@jogerj
Last active September 23, 2024 10:24
Show Gist options
  • Save jogerj/985b6d3112f96027eee599f91f87a211 to your computer and use it in GitHub Desktop.
Save jogerj/985b6d3112f96027eee599f91f87a211 to your computer and use it in GitHub Desktop.
Runtime patches for paimon.moe

Fix Paimon.moe

Runtime patches for paimon.moe

Fixes

Remove duplicate/non-existent achievements

Due to regression, currently broken

Related issues/PRs

PRs

Issues

Fixed PWA function

Related issues/PRs

PRs

Issues

Installation

  1. Get tampermonkey extension for your browser https://www.tampermonkey.net/
  2. Click this link or copy content of fix-paimon-moe.user.js below.
  3. When prompted to install by Tampermonkey, install the script. If Tampermonkey doesn't detect the script, add it manually (create new script and copy-paste contents of fix-paimon-moe.user.js.
  4. (Chrome) Go to manage extensions, enable developer mode. Close the browser and reopen to reload.

Disclaimer

  • Make sure you create backups of your data! Open https://paimon.moe/settings and export your data regularly. This goes without saying with or without using this userscript!
  • You are responsible for installing and running the script at your own risk.
  • I am not the developer of paimon.moe. Development of the website is done here. I am not involved in any way with the development of the website.
  • The development of this script has nothing to do with the author of the website (MadeBaruna). Please do not bother him about it.
  • These fixes are band-aids to address the abandoned condition of the website. These may break in the future, in which case please inform me.

Changelog

0.2.1

  • rename log output

0.2.0

  • Patch webmanifest to enable PWA

0.1.0

  • Initial release
  • Fix for invalid achievements

License

MIT

The MIT License (MIT)

Copyright (c) 2024 JogerJ

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// ==UserScript==
// @name fix-paimon-moe
// @namespace https://jogerj.com
// @version 0.2.1
// @description Fixes for paimon.moe!
// @author JogerJ
// @match https://paimon.moe/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=paimon.moe
// @downloadUrl https://gist.github.com/jogerj/985b6d3112f96027eee599f91f87a211/raw/fix-paimon-moe.user.js
// @run-at document-start
// @grant none
// @license MIT
// ==/UserScript==
async function fixBadAchievements() {
try {
const defaultObjectEntries = Object.entries;
function getFilteredAchievements(achievements) {
// Updated for version 5.0
const IGNORED_ACHIEVEMENTS = new Set([
81416, // Measure of Interference - non-existent
81418, // Gentle Descent - non-existent
81426, // Deianeira of Snezhevna - duplicate
81429, // Semnai Sans Shadow - duplicate
81451, // Secret Miracle - non-existent
81453, // Hanging Gardens of Plucked Jade - non-existent
]);
return defaultObjectEntries(achievements).map(([key, value]) => [
key,
{
...value,
achievements: value.achievements.filter(item => !IGNORED_ACHIEVEMENTS.has(item.id))
}
])
}
const hasAchievementDataSignature = (it) => (
typeof it === 'object' &&
typeof it[0] === 'object' &&
typeof it[0].name === 'string' &&
typeof it[0].achievements === 'object' &&
typeof it[0].order === 'number'
);
const modifiedObjectEntries = (obj) => {
if (hasAchievementDataSignature(obj)) {
return getFilteredAchievements(obj);
} else {
return defaultObjectEntries(obj);
}
};
Object.defineProperty(Object, 'entries', {
value: modifiedObjectEntries,
writable: false,
enumerable: false,
configurable: true
});
console.log('[fix-paimon-moe] INFO: Achievements patched.');
} catch (e) {
console.error('[fix-paimon-moe] ERROR: Failed to patch achievements!', e);
}
}
async function fixWebManifest() {
try {
function patchManifest(manifest) {
// remove relative paths
const ROOT_URL = 'https://paimon.moe';
function patchIcons(node) {
return node.icons ?
node.icons.map(it => ({
...it,
src: ROOT_URL + it.src
})) :
[];
}
manifest.start_url = ROOT_URL;
manifest.scope = ROOT_URL;
manifest.icons = patchIcons(manifest);
manifest.shortcuts = manifest.shortcuts.map(shortcut => ({
...shortcut,
url: ROOT_URL + shortcut.url,
icons: patchIcons(shortcut)
}));
return manifest;
}
const manifestLink = document.querySelector('link[rel="manifest"]');
if (manifestLink) {
const manifestResponse = await fetch('https://raw.githubusercontent.com/MadeBaruna/paimon-moe/refs/heads/main/static/manifest.json');
if (!manifestResponse.ok) {
throw new Error('Failed to fetch fixed manifest');
}
const manifestJson = await manifestResponse.json();
const manifestPayload = btoa(JSON.stringify(patchManifest(manifestJson)));
manifestLink.setAttribute('href', 'data:application/manifest+json;base64,' + manifestPayload);
manifestLink.removeAttribute('crossorigin');
console.log('[fix-paimon-moe] INFO: Manifest link patched.');
}} catch(e) {
console.error('[fix-paimon-moe] ERROR: When trying to patch manifest.', e);
}
}
(function() {
'use strict';
console.log('[fix-paimon-moe] INFO: Loading patches...');
fixBadAchievements();
fixWebManifest();
console.log('[fix-paimon-moe] INFO: Patches applied!');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment