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

feat: update creator page price tag dom #142

Merged
merged 1 commit into from
May 14, 2024
Merged
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
10 changes: 3 additions & 7 deletions src/content/addToTwitterHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,7 @@ export const addTwitterComponent = () => {

export const addUserPagePriceComponent = () => {
const addByXPath = (xpath: string) => {
const specificElement = document.evaluate(
xpath,
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue as Element;
const specificElement = document.querySelectorAll('[data-testid="UserName"]')[0];

if (specificElement) {
const priceContainer = document.createElement('span');
Expand All @@ -128,6 +122,7 @@ export const addUserPagePriceComponent = () => {
const elementId = `xfans-userPagePrice-${username}`;
const existingElement = document.getElementById(elementId);

console.log(username);
// 由于个人中心页面有复用,因此在插入之前要删除掉其他price tag
const elements = document.querySelectorAll('[id^="xfans-userPagePrice-"]');
elements.forEach((x) => {
Expand All @@ -144,5 +139,6 @@ export const addUserPagePriceComponent = () => {
// 当用户个人主页有背景图或者没有背景图的时候,xpath不一致。
const xpath = `/html/body/div[1]/div/div/div[2]/main/div/div/div/div[1]/div/div[3]/div/div/div/div[1]/div[2]/div[1]/div/div[1]/div/div/span/span[2]`;
const xpath2 = `/html/body/div[1]/div/div/div[2]/main/div/div/div/div[1]/div/div[3]/div/div/div/div[2]/div[2]/div[1]/div/div[1]/div/div/span/span[2]`;
console.log(!addByXPath(xpath));
if (!addByXPath(xpath)) addByXPath(xpath2);
};
Loading