Skip to content

Commit 1120daf

Browse files
committed
feat(GyazoDirectLink): bump version to 3.4 and enhance button creation logic to prevent duplicates
1 parent 872a842 commit 1120daf

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

GyazoDirectLink.user.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name Gyazo Gif and Video Direct Link Button
33
// @namespace typpi.online
4-
// @version 3.3
4+
// @version 3.4
55
// @description Adds a link button to redirect to the direct video or gif link on Gyazo
66
// @author Nick2bad4u
77
// @license UnLicense
@@ -109,24 +109,27 @@
109109
return directLink;
110110
}
111111

112-
let isButtonAdded = false; // Global flag to track button addition
113-
114112
function addRedirectButton() {
115-
// Check if the button already exists or has been added
116-
if (isButtonAdded || document.getElementById('direct-video-link-button')) {
117-
console.log('Redirect button already exists or has been added, skipping creation');
113+
// Check if the button already exists
114+
if (document.getElementById('direct-video-link-button')) {
115+
console.log('Redirect button already exists, skipping creation');
118116
return;
119117
}
120118

121119
console.log('Adding redirect button');
122-
isButtonAdded = true; // Set the flag to true to prevent duplicate calls
123120

124121
let targetElement = null;
125122
let attempts = 0;
126123
const maxAttempts = 10;
127124
const interval = 500;
128125

129126
const findTargetElement = () => {
127+
// Check again for existing button before retrying
128+
if (document.getElementById('direct-video-link-button')) {
129+
console.log('Redirect button already exists during retry, skipping creation');
130+
return;
131+
}
132+
130133
targetElement = document.querySelector(
131134
'#react-root > div.header-block.explorer-header-block > div.explorer-action-btn-toolbar > div.explorer-action-btn-group',
132135
);
@@ -159,9 +162,6 @@
159162
}
160163

161164
function removeRedirectButton() {
162-
// Reset the global flag when removing the button
163-
isButtonAdded = false;
164-
165165
if (!location.href.includes('https://gyazo.com/captures')) {
166166
console.log('Not removing redirect button since not on captures page');
167167
return;
@@ -189,6 +189,10 @@
189189

190190
function initialize() {
191191
console.log('Initializing script');
192+
193+
// Remove any existing button to prevent duplicates
194+
removeRedirectButton();
195+
192196
handlePageChange();
193197

194198
// Store the observer globally for cleanup
@@ -197,6 +201,9 @@
197201
if (currentUrl !== window.scriptObserver.lastUrl) {
198202
console.log('URL changed from', window.scriptObserver.lastUrl, 'to', currentUrl);
199203
window.scriptObserver.lastUrl = currentUrl;
204+
205+
// Remove any existing button before handling the page change
206+
removeRedirectButton();
200207
handlePageChange();
201208
}
202209
});

Profile.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
# See https://ch0.co/tab-completion for details.
66
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
77
if (Test-Path($ChocolateyProfile)) {
8-
Import-Module "$ChocolateyProfile"
8+
Import-Module "$ChocolateyProfile"
99
}

0 commit comments

Comments
 (0)