feat: add copy link button for IFreeTime with event handling

This commit is contained in:
王锦强
2025-04-02 23:16:03 +08:00
parent 2ac0f2dd8f
commit dd5a83100a
2 changed files with 39 additions and 2 deletions

View File

@@ -166,6 +166,7 @@ document.addEventListener('DOMContentLoaded', function () {
const downloadButton = document.getElementById('download');
const copyLinkButton = document.getElementById('copyLink');
const copyHttpTtsLinkButton = document.getElementById('copyHttpTtsLink');
const copyIfreetimeLinkButton = document.getElementById('copyIfreetimeLink'); // 新增元素引用
const audioPlayer = document.getElementById('audioPlayer');
const resultSection = document.getElementById('resultSection');
const charCount = document.getElementById('charCount');
@@ -384,6 +385,32 @@ document.addEventListener('DOMContentLoaded', function () {
window.open(httpTtsLink, '_blank')
});
// 复制爱阅记链接按钮点击事件
copyIfreetimeLinkButton.addEventListener('click', function () {
const text = "{{java.encodeURI(speakText)}}";
const voice = voiceSelect.value;
const displayName = voiceSelect.options[voiceSelect.selectedIndex].text;
const style = styleSelect.value;
const rate = "{{speakSpeed*4}}"
const pitch = pitchInput.value;
const apiKey = apiKeyInput.value.trim();
// 构建爱阅记链接
let ifreetimeLink = `${window.location.origin}${config.basePath}/ifreetime.json?&v=${voice}&r=${rate}&p=${pitch}&n=${displayName}`;
// 只有当style不为空时才添加
if (style) {
ifreetimeLink += `&s=${style}`;
}
// 添加API Key参数如果有
if (apiKey) {
ifreetimeLink += `&api_key=${apiKey}`;
}
window.open(ifreetimeLink, '_blank')
});
// 显示/隐藏API Key区域的按钮事件
if (toggleApiKeyButton) {
toggleApiKeyButton.addEventListener('click', function () {
@@ -681,10 +708,10 @@ function showCustomAlert(message, type = 'info', title = '', duration = 3000) {
iconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm-1-7v2h2v-2h-2zm0-8v6h2V7h-2z"/></svg>';
break;
case 'warning':
iconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm-1-7v2h2v-2h-2zm0-8v6h2V7h-2z"/></svg>';
iconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10-10-4.477 10-10 10zm-1-7v2h2v-2h-2zm0-8v6h2V7h-2z"/></svg>';
break;
default: // info
iconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm-1-11v6h2v-6h-2zm0-4v2h2V7h-2z"/></svg>';
iconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10-10-4.477 10-10 10zm-1-11v6h2v-6h-2zm0-4v2h2V7h-2z"/></svg>';
}
// 构建通知内容

View File

@@ -1154,6 +1154,16 @@
</svg>
导入阅读
</button>
<button id="copyIfreetimeLink"
class="btn-neo btn-neo-secondary btn-neo-icon inline-flex items-center gap-1.5 bg-slate-100 hover:bg-slate-200 text-slate-700 px-4 py-2 rounded-md transition hover:-translate-y-0.5 active:translate-y-0 shadow border border-slate-200">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
stroke="currentColor" stroke-width="2" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round"
d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"/>
</svg>
导入爱阅记
</button>
</div>
</div>
</section>