Last active
February 7, 2026 14:02
-
-
Save Dobby233Liu/7f19bfd24d141fd5a7b98d0435f307c7 to your computer and use it in GitHub Desktop.
Get hovered liveroom ids: These guys can't use <a> like normal people
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Get hovered liveroom ids | |
| // @namespace io.github.dobby233liu.userscripts.bilibili.livegetroomundercursorurl | |
| // @version 1.1.1 | |
| // @description These guys can't use <a> like normal people | |
| // @author Liu Wenyuan | |
| // @match https://live.bilibili.com/* | |
| // @grant GM_registerMenuCommand | |
| // ==/UserScript== | |
| (function() { | |
| "use strict"; | |
| const tmplGen = ((cb, dataType) => { | |
| async function perform() { | |
| const hoveredElems = Array.from(document.querySelectorAll(":hover")).reverse(); | |
| for (const elem of hoveredElems) { | |
| if (!elem.dataset.report) continue; | |
| let reportData = null; | |
| try { | |
| reportData = JSON.parse(elem.dataset.report); | |
| } catch (err) { | |
| console.warn(err); | |
| continue; | |
| } | |
| const url = cb(reportData); | |
| if (!url) return; | |
| try { await navigator.clipboard.writeText(url); } catch (err) { console.warn(err); } | |
| alert(url); | |
| return true; | |
| } | |
| } | |
| async function performAbsorbErrors() { | |
| try { | |
| return await perform(); | |
| } catch (err) { | |
| console.warn(err); | |
| } | |
| } | |
| function sleep(t) { | |
| return new Promise(function(r, _) { | |
| setTimeout(r, t); | |
| }); | |
| } | |
| return async function() { | |
| if (await performAbsorbErrors()) return; | |
| await sleep(1000); | |
| if (await performAbsorbErrors()) return; | |
| alert(`No ${dataType} found`); | |
| } | |
| }); | |
| GM_registerMenuCommand("Get room url", tmplGen((reportData) => { | |
| if (!reportData.room_id) return; | |
| return `https://live.bilibili.com/${reportData.room_id}`; | |
| }, "room id")); | |
| GM_registerMenuCommand("Get up url", tmplGen((reportData) => { | |
| if (!reportData.up_id) return; | |
| return `https://space.bilibili.com/${reportData.up_id}`; | |
| }, "up id")); | |
| GM_registerMenuCommand("Get area url", tmplGen((reportData) => { | |
| function isAreaIdNull(id) { return !id || id == "0"; } | |
| const urlObj = new URL("https://live.bilibili.com/p/eden/area-tags"); | |
| let useSubareaId = true; | |
| if (!isAreaIdNull(reportData.parent_area_id)) { | |
| useSubareaId = false; | |
| urlObj.searchParams.set("parentAreaId", reportData.parent_area_id); | |
| } else if (!isAreaIdNull(reportData.area_id)) { | |
| urlObj.searchParams.set("parentAreaId", reportData.area_id); | |
| } | |
| if (useSubareaId && !isAreaIdNull(reportData.subarea_id)) { | |
| urlObj.searchParams.set("areaId", reportData.subarea_id); | |
| } else if (!isAreaIdNull(reportData.area_id)) { | |
| urlObj.searchParams.set("areaId", reportData.area_id); | |
| } | |
| if (urlObj.search == "") return; | |
| return urlObj.href; | |
| }, "area id(s)")); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment