Files
FixIt/assets/js/pages/link.js
T
Cell dd6d320654 refactor!: build with Dart Sass and update Vercel deployment scripts (#746)
* 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
2026-05-10 23:02:54 +08:00

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);
}