Skip to content

Commit 872a842

Browse files
committed
feat(GyazoDirectLink): bump version to 3.3 and enhance tooltip management to prevent duplicates
1 parent 776f5c2 commit 872a842

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

GyazoDirectLink.user.js

Lines changed: 19 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.2
4+
// @version 3.3
55
// @description Adds a link button to redirect to the direct video or gif link on Gyazo
66
// @author Nick2bad4u
77
// @license UnLicense
@@ -43,6 +43,11 @@
4343

4444
function createTooltipElement() {
4545
console.log('Creating tooltip element');
46+
const existingTooltip = document.getElementById('tooltip-direct-video-link-button');
47+
if (existingTooltip) {
48+
console.log('Existing tooltip found, removing it');
49+
existingTooltip.remove();
50+
}
4651
const tooltip = document.createElement('div');
4752
tooltip.id = 'tooltip-direct-video-link-button';
4853
tooltip.setAttribute('role', 'tooltip');
@@ -64,9 +69,7 @@
6469
tooltip.innerHTML =
6570
'Direct Link<div class="react-tooltip-arrow core-styles-module_arrow__cvMwQ styles-module_arrow__K0L3T" style="left: 38px; top: -4px;"></div>';
6671

67-
if (!document.getElementById('tooltip-direct-video-link-button')) {
68-
document.body.appendChild(tooltip);
69-
}
72+
document.body.appendChild(tooltip);
7073

7174
console.log('Tooltip element created', tooltip);
7275
return tooltip;
@@ -106,15 +109,18 @@
106109
return directLink;
107110
}
108111

112+
let isButtonAdded = false; // Global flag to track button addition
113+
109114
function addRedirectButton() {
110-
removeRedirectButton();
111-
console.log('Adding redirect button');
112-
const existingButton = document.getElementById('direct-video-link-button');
113-
if (existingButton) {
114-
console.log('Existing button found, removing it');
115-
existingButton.remove();
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');
118+
return;
116119
}
117120

121+
console.log('Adding redirect button');
122+
isButtonAdded = true; // Set the flag to true to prevent duplicate calls
123+
118124
let targetElement = null;
119125
let attempts = 0;
120126
const maxAttempts = 10;
@@ -153,6 +159,9 @@
153159
}
154160

155161
function removeRedirectButton() {
162+
// Reset the global flag when removing the button
163+
isButtonAdded = false;
164+
156165
if (!location.href.includes('https://gyazo.com/captures')) {
157166
console.log('Not removing redirect button since not on captures page');
158167
return;

0 commit comments

Comments
 (0)