Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

fix(gallery): Xiaohongshu's creator logo leads back to the notes

Tw9312440575376a
diff --git a/gallery/apps/xiaohongshu.js b/gallery/apps/xiaohongshu.js
new file mode 100644
index 00000000..95062578
--- /dev/null
+++ b/gallery/apps/xiaohongshu.js
@@ -0,0 +1,62 @@
+// Xiaohongshu's creator platform, creator.xiaohongshu.com, is a separate site
+// the app opens in place of the notes, and nothing on it leads back to them:
+// a user who opened it found no way home. Its Xiaohongshu logo, top left with
+// the platform's name, now goes back to the home page.
+(() => {
+ if (location.hostname !== "creator.xiaohongshu.com") return;
+ const HOME = "https://www.xiaohongshu.com/explore";
+ const MARK = "pakeHome";
+
+ // The logo is the header's first svg; its group is the nearest ancestor that
+ // also holds the platform's name. Class names are generated, so none is used.
+ const findLogo = () => {
+ for (const svg of document.querySelectorAll("svg")) {
+ const box = svg.getBoundingClientRect();
+ if (box.width === 0 || box.top > 80 || box.left > 160) continue;
+ for (
+ let group = svg.parentElement, depth = 0;
+ group && depth < 4;
+ group = group.parentElement, depth++
+ ) {
+ const width = group.getBoundingClientRect().width;
+ if (width > 420) break;
+ if (group.textContent.includes("创作服务平台")) return group;
+ }
+ return svg.parentElement;
+ }
+ return null;
+ };
+
+ let marked = null;
+ const mark = () => {
+ if (marked?.isConnected) return;
+ const logo = findLogo();
+ if (!logo || logo.dataset[MARK]) return;
+ marked = logo;
+ logo.dataset[MARK] = "1";
+ logo.style.cursor = "pointer";
+ logo.addEventListener("click", (event) => {
+ if (
+ event.button !== 0 ||
+ event.metaKey ||
+ event.ctrlKey ||
+ event.shiftKey ||
+ event.altKey
+ )
+ return;
+ event.preventDefault();
+ event.stopPropagation();
+ location.href = HOME;
+ });
+ };
+
+ const start = () => {
+ mark();
+ new MutationObserver(mark).observe(document.body, {
+ childList: true,
+ subtree: true,
+ });
+ };
+ if (document.body) start();
+ else document.addEventListener("DOMContentLoaded", start, { once: true });
+})();
diff --git a/gallery/apps/xiaohongshu.json b/gallery/apps/xiaohongshu.json
index 2c26fbee..1de0aff3 100644
--- a/gallery/apps/xiaohongshu.json
+++ b/gallery/apps/xiaohongshu.json
@@ -1,6 +1,6 @@
{
"id": "xiaohongshu",
- "version": 1,
+ "version": 2,
"name": {
"en": "Xiaohongshu",
"zh-Hans": "小红书"
@@ -11,5 +11,6 @@
"en": "Lifestyle notes and recommendations",
"zh-Hans": "生活方式笔记和分享"
},
+ "inject_js": "xiaohongshu.js",
"icon": "https://picasso-static.xiaohongshu.com/fe-platform/f43dc4a8baf03678996c62d8db6ebc01a82256ff.png"
}