Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reddit +medium battery #3284

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/extension/content-script/batteries/Medium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ const urlMatcher = /^https:\/\/(.+\.)?medium.com\/(\S+)?/;
const battery = (): void => {
const name =
document.querySelector<HTMLHeadingElement>(".pw-author-name")?.innerText;
const description = document.querySelector<HTMLParagraphElement>(
".pw-follower-count ~ p"
)?.textContent;

const description = document
.querySelector(".pw-author-name")
?.parentElement?.parentElement?.querySelector("p")
?.querySelector("span")?.textContent;

if (!name || !description) return;

const match = findLightningAddressInText(description);
Expand Down
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
Loading