mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
dd6d320654
* BREAKING CHANGE: refactor with Dart Sass (supplement to #741) * chore: update .gitignore to include .vercel and .env*.local * CI: add build script for Hugo site deployment on Vercel * CI: update build script for Hugo site deployment on Vercel * refactor: update SCSS layout styles and introduce page-style mixin * refactor: reorganize SCSS files and improve layout structure * refactor: rename copy button classes and update related styles
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
/**
|
|
* for link redirection page
|
|
*/
|
|
|
|
import { createCopyText } from '../utils/common';
|
|
|
|
const copyText = createCopyText();
|
|
|
|
function initLinkGuard() {
|
|
const params = new URLSearchParams(window.location.search);
|
|
const target = params.get('target');
|
|
const targetElement = document.querySelector('.target');
|
|
const copyBtn = document.querySelector('.copy-icon-btn');
|
|
const confirmBtn = document.querySelector('.confirm-btn');
|
|
|
|
if (target) {
|
|
targetElement.textContent = target;
|
|
copyBtn.disabled = false;
|
|
confirmBtn.disabled = false;
|
|
|
|
copyBtn.addEventListener('click', () =>{
|
|
copyText(target).then(() => {
|
|
copyBtn.toggleAttribute('data-copied', true);
|
|
setTimeout(() => {
|
|
copyBtn.toggleAttribute('data-copied', false);
|
|
}, 2000);
|
|
}, () => {
|
|
console.error('Clipboard write failed!', 'Your browser does not support clipboard API!');
|
|
});
|
|
});
|
|
|
|
confirmBtn.addEventListener('click', () => {
|
|
window.location.href = target;
|
|
});
|
|
} else {
|
|
targetElement.textContent = 'Invalid target URL';
|
|
}
|
|
}
|
|
|
|
if (document.readyState !== 'loading') {
|
|
initLinkGuard();
|
|
} else {
|
|
document.addEventListener('DOMContentLoaded', initLinkGuard, false);
|
|
}
|