Skip to content

Commit

Permalink
fixed missing download buttons on post pages
Browse files Browse the repository at this point in the history
  • Loading branch information
flurrux committed Aug 20, 2024
1 parent fd61aa1 commit 6ebea43
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 63 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ so before you use this extension, you have to be willing to wait for a fix when

## latest update

February 23rd 2024
August 20th 2024

this release should fix missing download buttons in stories other than the main feed.
fixed missing download buttons on post pages.



Expand Down
31 changes: 13 additions & 18 deletions app/src/download-button-injection/post-button-injection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,34 +204,29 @@ async function findSinglePagePostInjectionPoint(postElement: HTMLElement): Promi
// there are two elements of tag 'polygon' on the page: the share and save buttons.
// we'll wait for any of such elements to show up:

const polygonElement = await waitForElementExistence(200, 10, postElement, "polygon");
if (!polygonElement) {
return left([
`trying to inject download buttons into post, but cannot find any child with tag 'polygon' that was expected to be in the following element: `,
postElement
])
}
const shareButtonPolygon = await waitForElementExistence(
500, 10,
postElement,
'[aria-label="Share"]'
);

const polygonElements = Array.from(postElement.querySelectorAll("polygon"));
if (polygonElements.length !== 2){
console.warn(`expected to find exactly two svg-polygon elements on this page, but got a different number, namely ${polygonElements.length}`);
if (!shareButtonPolygon){
return left(["did not find aria-label=\"Share\" are 10 attempts."]);
}

if (polygonElements.length < 1){
return left("expected to find atleast one svg-polygon on this page that belonged to the share-button, but did not find any.");
if (!shareButtonPolygon){
return left(["couldn't find an element with the aria-label=\"Share\""]);
}

// we'll assume that the first polygon element is a descendant of the share button

const firstPolygon = polygonElements[0];
const shareButtonOpt = findInAncestors(
(el) => el.matches("button"), firstPolygon
(el) => el.matches('[role="button"]'),
shareButtonPolygon as HTMLElement
);

if (isNone(shareButtonOpt)){
return left([
`found an svg-polygon element that was assumed to belong to the share-button. then we tried to find the share-button itself, but got no matches. here is the polygon element:`,
firstPolygon
`didn't find any parent with a role of button. here's the starting point:`,
shareButtonPolygon
])
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(async () => {
await import(
/* @vite-ignore */
chrome.runtime.getURL("assets/index.ts.f965b02c.js")
chrome.runtime.getURL("assets/index.ts.8d5ddaa6.js")
);
})().catch(console.error);

Expand Down
Loading

0 comments on commit 6ebea43

Please sign in to comment.