diff --git a/images/platform-icons/bilibili.png b/images/platform-icons/bilibili.png new file mode 100644 index 0000000..3162d26 Binary files /dev/null and b/images/platform-icons/bilibili.png differ diff --git a/manifest.json b/manifest.json index c1d4638..532d4a4 100644 --- a/manifest.json +++ b/manifest.json @@ -38,6 +38,8 @@ "inc/he.js", "js/lib.js", "js/zs-background.js", + "modules/bilibili_pinia_parser.js", + "modules/bilibili.js", "modules/tiktok.js", "modules/tiktok-comments.js", "modules/instagram.js", diff --git a/modules/bilibili.js b/modules/bilibili.js new file mode 100644 index 0000000..e7cec42 --- /dev/null +++ b/modules/bilibili.js @@ -0,0 +1,104 @@ +zeeschuimer.register_module( + 'Bilibili', + 'bilibili.com', + function (response, source_platform_url, source_url) { + // Ensure each item has an "id" field using the bvid + function ensureItemId(item) { + if (item.bvid) { + item.id = item.bvid; + } + return item; + } + + let domain = source_platform_url.split("/")[2].toLowerCase().replace(/^www\./, ''); + if (!["bilibili.com"].includes(domain)) { + return []; + } + + if (!response) { + return []; + } + + let found_items; + let type_of_item; + + // Try to parse as JSON first (API responses) + let data; + try { + data = JSON.parse(response); + } catch (SyntaxError) { + // Not JSON - might be HTML with embedded __pinia data + if (typeof response === 'string' && response.includes('window.__pinia')) { + console.log('Bilibili module: Detected HTML with __pinia, attempting to parse'); + + // Extract the script tag or line containing window.__pinia + // Look for the line - it should be in a