|
1 | 1 | // ==UserScript== |
2 | 2 | // @name Gyazo Gif and Video Direct Link Button |
3 | 3 | // @namespace typpi.online |
4 | | -// @version 3.2 |
| 4 | +// @version 3.3 |
5 | 5 | // @description Adds a link button to redirect to the direct video or gif link on Gyazo |
6 | 6 | // @author Nick2bad4u |
7 | 7 | // @license UnLicense |
|
43 | 43 |
|
44 | 44 | function createTooltipElement() { |
45 | 45 | 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 | + } |
46 | 51 | const tooltip = document.createElement('div'); |
47 | 52 | tooltip.id = 'tooltip-direct-video-link-button'; |
48 | 53 | tooltip.setAttribute('role', 'tooltip'); |
|
64 | 69 | tooltip.innerHTML = |
65 | 70 | 'Direct Link<div class="react-tooltip-arrow core-styles-module_arrow__cvMwQ styles-module_arrow__K0L3T" style="left: 38px; top: -4px;"></div>'; |
66 | 71 |
|
67 | | - if (!document.getElementById('tooltip-direct-video-link-button')) { |
68 | | - document.body.appendChild(tooltip); |
69 | | - } |
| 72 | + document.body.appendChild(tooltip); |
70 | 73 |
|
71 | 74 | console.log('Tooltip element created', tooltip); |
72 | 75 | return tooltip; |
|
106 | 109 | return directLink; |
107 | 110 | } |
108 | 111 |
|
| 112 | + let isButtonAdded = false; // Global flag to track button addition |
| 113 | + |
109 | 114 | 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; |
116 | 119 | } |
117 | 120 |
|
| 121 | + console.log('Adding redirect button'); |
| 122 | + isButtonAdded = true; // Set the flag to true to prevent duplicate calls |
| 123 | + |
118 | 124 | let targetElement = null; |
119 | 125 | let attempts = 0; |
120 | 126 | const maxAttempts = 10; |
|
153 | 159 | } |
154 | 160 |
|
155 | 161 | function removeRedirectButton() { |
| 162 | + // Reset the global flag when removing the button |
| 163 | + isButtonAdded = false; |
| 164 | + |
156 | 165 | if (!location.href.includes('https://gyazo.com/captures')) { |
157 | 166 | console.log('Not removing redirect button since not on captures page'); |
158 | 167 | return; |
|
0 commit comments