Skip to content

Commit

Permalink
show share buttons on media page if visiting after any other page
Browse files Browse the repository at this point in the history
  • Loading branch information
usyless committed Sep 10, 2024
1 parent f5f79d2 commit 3878dd6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion manifest_chrome.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Twitter Improvements",
"version": "1.0.5.5",
"version": "1.0.5.6",

"description": "Various helpful twitter improvements",

Expand Down
2 changes: 1 addition & 1 deletion manifest_firefox.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Twitter Improvements",
"version": "1.0.5.5",
"version": "1.0.5.6",

"description": "Various helpful twitter improvements",

Expand Down
1 change: 1 addition & 0 deletions popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="popup.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="popup.js"></script>
</head>

Expand Down
13 changes: 11 additions & 2 deletions twitter_improvements.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
download_button_path = "M 12 17.41 l -5.7 -5.7 l 1.41 -1.42 L 11 13.59 V 4 h 2 V 13.59 l 3.3 -3.3 l 1.41 1.42 L 12 17.41 zM21 15l-.02 3.51c0 1.38-1.12 2.49-2.5 2.49H5.5C4.11 21 3 19.88 3 18.5V15h2v3.5c0 .28.22.5.5.5h12.98c.28 0 .5-.22.5-.5L19 15h2z",
Settings = await getSettings();

// Fallbacks for when button cannot be found
let fallbackButton;

class Tweet { // Tweet functions
static addVXButton(article) {
try {
Expand All @@ -23,7 +26,13 @@
}

static anchor(article) {
return article.querySelector('button[aria-label="Share post"]').parentElement.parentElement;
const anchor = article.querySelector('button[aria-label="Share post"]').parentElement.parentElement;
if (!fallbackButton) fallbackButton = anchor;
return anchor;
}

static anchorWithFallback(article) {
try {return Tweet.anchor(article);} catch {return fallbackButton;}
}

static url(article) {
Expand All @@ -44,7 +53,7 @@
static addImageButton(image) {
try {
image.setAttribute('usy', '');
image.after(Button.newButton(Tweet.anchor(Tweet.nearestTweet(image)), download_button_path, (e) => {
image.after(Button.newButton(Tweet.anchorWithFallback(Tweet.nearestTweet(image)), download_button_path, (e) => {
e.preventDefault();
chrome.runtime.sendMessage({type: 'image', url: Image.respectiveURL(image), sourceURL: image.src});
}));
Expand Down

0 comments on commit 3878dd6

Please sign in to comment.