User Details on Hover

Show user details on hover

< 脚本 User Details on Hover 的反馈

提问 / 留言

§
发布于:2023-11-13

Hello! I am a developer for an open-source project called ListenBrainz (https://github.com/metabrainz/listenbrainz-server). We have recently seen some strange errors accumulating in our error reporting software, with "/userscript.html?name=User-Details-on-Hover.user.js" showing as the source.

After some searching I found this userscript to be the source of the error. If I understand correctly this userscript is meant to be used in conjunction with Lemmy, and the first thing the script does is check whether it should apply to the current page. However, the check in question throws an error which is then reported by our reporting software.

Running the unmodified const isLemmy = document.head.querySelector("[name~=Description][content]").content === "Lemmy"; on a random page causes Uncaught TypeError: Cannot read properties of null (reading 'content').

However, using the optional chaining ?. before trying to access .content ensures the code doesn't throw an error:

const isLemmy = document.head.querySelector("[name~=Description][content]")?.content === "Lemmy";

Alternatively, if the optional chaining operator is too recent a feature, the boolean can be broken down like so:

const targetElement = document.head.querySelector("[name~=Description][content]");
const isLemmy = targetElement && targetElement.content === "Lemmy";

发布留言

登录以发布留言。