Skip to content

Commit

Permalink
fix: reddit battery
Browse files Browse the repository at this point in the history
  • Loading branch information
pavanjoshi914 authored and im-adithya committed Dec 11, 2024
1 parent 6f0936d commit a75430c
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/extension/content-script/batteries/Reddit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@ import { findLightningAddressInText, setLightningData } from "./helpers";
const urlMatcher = /^https:\/\/www.reddit\.com\/user\/(\w+).*/;

function battery(): void {
const descriptionElement = document.querySelector<HTMLMetaElement>(
'head > meta[name="description"]'
const descriptionElement = document.querySelector<HTMLElement>(
'p[data-testid="profile-description"]'
);
const imageUrl = document.querySelector<HTMLMetaElement>(
'head > meta[property="og:image"]'
)?.content;

const imageUrl = document.querySelector<HTMLImageElement>(
'img[data-testid="profile-icon"]'
)?.src;

if (!descriptionElement || !imageUrl) {
return;
}

const content = descriptionElement.content.split(/:(.*)/s);
const userName = content[0];
const description =
document.querySelector<HTMLMetaElement>(
`h4 + a[href*='user/${userName.split("/")[1]}'] + div`
)?.textContent ?? content[1].slice(1);
const content = descriptionElement.textContent || "";
const userName =
document.querySelector("aside div h2")?.textContent?.trim() || "";

let match;
let recipient;
// attempt to extract lnurlp: from the description text
if ((match = (description || "").match(/lnurlp:(\S+)/i))) {
if ((match = (content || "").match(/lnurlp:(\S+)/i))) {
recipient = match[1];
} else if ((match = findLightningAddressInText(description))) {
} else if ((match = findLightningAddressInText(content || ""))) {
recipient = match;
}
// if we still did not find anything ignore it.
Expand All @@ -40,7 +38,7 @@ function battery(): void {
method: "lnurl",
address: recipient,
...getOriginData(),
description,
description: content,
icon: imageUrl,
name: userName,
},
Expand Down

0 comments on commit a75430c

Please sign in to comment.