Copy instead of prompting data link for Chromium based browsers

This commit is contained in:
Glitchii 2022-04-09 20:08:19 +01:00
parent 43c63db954
commit 806cc35d17
3 changed files with 25 additions and 23 deletions

View file

@ -2366,25 +2366,9 @@ body.toHook .done .channels .selectOptions .hook {
/* Send button and components **/ /* Send button and components **/
.invisible {
display: none!important;
}
::-webkit-scrollbar { ::-webkit-scrollbar {
width: 7px; width: 7px;

View file

@ -64,7 +64,6 @@ var params = currentURL().searchParams,
if (autoParams) isReversed ? urlOptions({ set: ['reverse', ''] }) : urlOptions({ remove: 'reverse' }); if (autoParams) isReversed ? urlOptions({ set: ['reverse', ''] }) : urlOptions({ remove: 'reverse' });
}, },
urlOptions = ({ remove, set }) => { urlOptions = ({ remove, set }) => {
console.log(remove, set);
const url = currentURL(); const url = currentURL();
if (remove) url.searchParams.delete(remove); if (remove) url.searchParams.delete(remove);
if (set) url.searchParams.set(set[0], set[1]); if (set) url.searchParams.set(set[0], set[1]);
@ -970,8 +969,26 @@ addEventListener('DOMContentLoaded', () => {
}) })
document.querySelector('.top-btn.menu')?.addEventListener('click', e => { document.querySelector('.top-btn.menu')?.addEventListener('click', e => {
if (e.target.closest('.item.dataLink')) if (e.target.closest('.item.dataLink')) {
return prompt('Here\'s the current URL with base64 embed data:', jsonToBase64(json, true)); const data = jsonToBase64(json, true);
// With long text inside a 'prompt' on Chromium based browsers, some text will but cut and replaced with '...'.
// So, for the Chromium users, we copy to clipboard instead of showing a prompt.
if (!window.chrome)
return prompt('Here\'s the current URL with base64 embed data:', data);
if (location.protocol === 'http:')
// Clipboard API only works on HTTPS protocol.
navigator.clipboard.writeText(data);
else {
const input = document.createElement('input');
input.value = data;
document.body.appendChild(input);
input.select();
document.execCommand('copy');
document.body.removeChild(input);
}
alert('Copied to clipboard.');
}
const input = e.target.closest('.item')?.querySelector('input'); const input = e.target.closest('.item')?.querySelector('input');
if (input) input.checked = !input.checked; if (input) input.checked = !input.checked;

View file

@ -119,7 +119,7 @@
</g> </g>
</svg> </svg>
</div> </div>
<div>Get data link</div> <div>Get URL with data link</div>
</div> </div>
<div class="item normal auto no-frame"> <div class="item normal auto no-frame">
<!-- <input type="checkbox" id="auto" name="auto" autocomplete="off" class="hidden"> --> <!-- <input type="checkbox" id="auto" name="auto" autocomplete="off" class="hidden"> -->
@ -334,5 +334,6 @@
</div> </div>
</section> </section>
</div> </div>
<input type="hidden" value>
</body> </body>
</html> </html>