Bark-Sender CF Worker

同步来源:树洞剪藏 源站剪藏 ID:80 原文地址:https://netcut.cn/p/2bc8406b30d79337
只读剪贴板
网络剪贴板
11 月 15 日 10:58:45 星期五
网络剪贴板详情 网络剪贴板(netcut.cn)是一款极简的提供跨平台的文本复制粘贴和全格式文件传送的在线工具,操作简单,让数据传送更简单。 网络剪贴板可以用于数据临时存储,文本分享,文件分享,不同设备文件和文本传送,网络便签,文本去格式化编辑工具等用途。
剪贴板文本 文件 ( 1 个 )
addEventListener('fetch', event => { event.respondWith(processRequest(event.request)); });
async function processRequest(request) { const requestUrl = new URL(request.url);
if (request.method === 'GET' && requestUrl.pathname === '/') { return new Response(generateHTMLForm(), { headers: { 'Content-Type': 'text/html;charset=UTF-8', ...securityHeaders, }, }); }
if (request.method === 'POST' && requestUrl.pathname === '/send') { try { const formData = await request.formData();
// 验证并清理服务器 URL
let apiServerUrl;
try {
apiServerUrl = sanitizeApiServerUrl(formData.get('server') || 'https://api.day.app');
} catch (error) {
return new Response(
<div class="notification error">无效的服务器 URL,请输入正确的 HTTPS 地址。</div><a href="/">返回</a>,
{
headers: {
'Content-Type': 'text/html;charset=UTF-8',
...securityHeaders,
},
}
);
}
const apiKey = formData.get('key'); const notificationTitle = formData.get('title') || ''; const notificationBody = formData.get('body') || '';
let apiPath = /${encodeURIComponent(apiKey)};
if (notificationTitle) {
apiPath += /${encodeURIComponent(notificationTitle)};
}
apiPath += /${encodeURIComponent(notificationBody)};
const queryParams = new URLSearchParams(); const shouldArchive = formData.get('isArchive') === '1';
['level', 'sound', 'icon', 'group', 'badge', 'url', 'copy', 'autocopy'].forEach(param => { const value = formData.get(param); if (value) queryParams.append(param, value); });
const completeApiUrl = ${apiServerUrl}${apiPath}?${queryParams.toString()};
let apiResponse; const requestMethod = (formData.get('method') || 'GET').toUpperCase();
// 验证请求方法 if (requestMethod !== 'GET' && requestMethod !== 'POST') { return new Response('无效的请求方法', { status: 400 }); }
if (requestMethod === 'POST') { const postData = { title: notificationTitle, body: notificationBody, }; if (shouldArchive) { postData.isArchive = '1'; } else { postData.isArchive = '2'; } ['level', 'sound', 'icon', 'group', 'badge', 'url', 'copy', 'autocopy'].forEach(param => { const value = formData.get(param); if (value) postData[param] = value; });
apiResponse = await fetch(${apiServerUrl}/${encodeURIComponent(apiKey)}, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(postData),
});
} else {
if (shouldArchive) { queryParams.append('isArchive', '1'); } else { queryParams.append('isArchive', '2'); }
apiResponse = await fetch(completeApiUrl, { method: 'GET' }); }
if (apiResponse.ok) {
return new Response(generateSuccessHTML(), {
headers: {
'Content-Type': 'text/html;charset=UTF-8',
...securityHeaders,
},
});
} else {
// 避免将详细错误信息暴露给用户
return new Response(
<div class="notification error">推送失败,请稍后重试。</div><a href="/">返回</a>,
{
headers: {
'Content-Type': 'text/html;charset=UTF-8',
...securityHeaders,
},
}
);
}
} catch (error) {
// 可在此记录错误日志,例如 console.error(error);
return new Response(
<div class="notification error">发生未知错误,请稍后重试。</div><a href="/">返回</a>,
{
headers: {
'Content-Type': 'text/html;charset=UTF-8',
...securityHeaders,
},
}
);
}
}
return new Response('Not Found', { status: 404 }); }
function sanitizeApiServerUrl(url) { try { const parsedUrl = new URL(url); if (parsedUrl.protocol !== 'https:') { throw new Error('只允许使用 HTTPS 协议的服务器地址'); } return parsedUrl.origin; } catch (error) { throw new Error('无效的服务器 URL'); } }
// 安全头信息 const securityHeaders = { 'Content-Security-Policy': "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'; font-src https://fonts.googleapis.com https://fonts.gstatic.com;", 'X-Content-Type-Options': 'nosniff', 'X-Frame-Options': 'DENY', 'Referrer-Policy': 'no-referrer', 'Strict-Transport-Security': 'max-age=63072000; includeSubDomains; preload', };
function generateHTMLForm() { return `
:root { --primary-color: #7C3AED; --primary-hover-color: #6D28D9; --background-color: #F3F4F6; --card-background-color: #FFFFFF; --text-color: #1F2937; --border-color: #E5E7EB; --success-color: #10B981; --error-color: #EF4444; }
body { font-family: 'Inter', sans-serif; background-color: var(--background-color); color: var(--text-color); line-height: 1.5; margin: 0; padding: 0; }
.container { max-width: 600px; margin: 2rem auto; padding: 2rem; background-color: var(--card-background-color); border-radius: 0.5rem; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); }
h1 { font-size: 2.3rem; font-weight: 600; text-align: center; margin-bottom: 1.5rem; color: var(--primary-color); }
form { display: grid; grid-template-columns: 1fr; gap: 1rem; }
label { font-weight: 500; display: block; margin-bottom: 0.5rem; }
input[type="text"], input[type="url"], input[type="number"], select, textarea { width: 100%; padding: 0.5rem; border: 1px solid var(--border-color); border-radius: 0.25rem; font-size: 1rem; transition: border-color 0.3s ease; }
input[type="text"]:focus, input[type="url"]:focus, input[type="number"]:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1); }
.checkbox-group { display: flex; align-items: center; gap: 0.5rem; width: 100%; }
.checkbox-group input[type="checkbox"] { width: auto; }
button { background-color: var(--primary-color); color: white; border: none; padding: 0.75rem 1rem; font-size: 1rem; font-weight: 500; border-radius: 0.25rem; cursor: pointer; transition: background-color 0.3s ease; }
button:hover { background-color: var(--primary-hover-color); }
.tooltip { position: relative; display: inline-block; margin-left: 0.5rem; cursor: help; }
.tooltip .tooltiptext { visibility: hidden; width: 200px; background-color: #333; color: #fff; text-align: center; border-radius: 6px; padding: 5px; position: absolute; z-index: 1; bottom: 125%; left: 50%; transform: translateX(-50%); opacity: 0; transition: opacity 0.3s; }
.tooltip:hover .tooltiptext { visibility: visible; opacity: 1; }
.notification { padding: 1rem; border-radius: 0.25rem; margin-bottom: 1rem; text-align: center; }
.notification.success { background-color: var(--success-color); color: white; }
.notification.error { background-color: var(--error-color); color: white; }
@media (max-width: 640px) { .container { margin: 1rem; padding: 1rem; } }
确认发送
if (!/^https?:\/\/.+/.test(serverUrl)) { event.preventDefault(); alert('请输入有效的服务器地址,以 http:// 或 https:// 开头'); serverInput.focus(); } });
function generateSuccessHTML() { return `
body { font-family: 'Inter', sans-serif; background-color: var(--background-color); color: var(--text-color); line-height: 1.5; margin: 0; padding: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.container { position: relative; z-index: 140; width: 100%; max-width: 440px; margin: auto; background-color: white; border-radius: 8px; padding: 24px 20px; text-align: center; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); }
.success-icon-container { width: 100%; height: 80px; background-color: var(--success-green); border-radius: 4px; display: flex; align-items: center; justify-content: center; margin-bottom: 20px; }
.success-icon { width: 48px; height: 48px; }
.message { margin-bottom: 8px; font-size: 20px; font-weight: 500; }
.description { margin-bottom: 12px; }
async function processRequest(request) { const requestUrl = new URL(request.url);
if (request.method === 'GET' && requestUrl.pathname === '/') { return new Response(generateHTMLForm(), { headers: { 'Content-Type': 'text/html;charset=UTF-8', ...securityHeaders, }, }); }
if (request.method === 'POST' && requestUrl.pathname === '/send') { try { const formData = await request.formData();
// 验证并清理服务器 URL
let apiServerUrl;
try {
apiServerUrl = sanitizeApiServerUrl(formData.get('server') || 'https://api.day.app');
} catch (error) {
return new Response(
<div class="notification error">无效的服务器 URL,请输入正确的 HTTPS 地址。</div><a href="/">返回</a>,
{
headers: {
'Content-Type': 'text/html;charset=UTF-8',
...securityHeaders,
},
}
);
}
const apiKey = formData.get('key'); const notificationTitle = formData.get('title') || ''; const notificationBody = formData.get('body') || '';
let apiPath = /${encodeURIComponent(apiKey)};
if (notificationTitle) {
apiPath += /${encodeURIComponent(notificationTitle)};
}
apiPath += /${encodeURIComponent(notificationBody)};
const queryParams = new URLSearchParams(); const shouldArchive = formData.get('isArchive') === '1';
['level', 'sound', 'icon', 'group', 'badge', 'url', 'copy', 'autocopy'].forEach(param => { const value = formData.get(param); if (value) queryParams.append(param, value); });
const completeApiUrl = ${apiServerUrl}${apiPath}?${queryParams.toString()};
let apiResponse; const requestMethod = (formData.get('method') || 'GET').toUpperCase();
// 验证请求方法 if (requestMethod !== 'GET' && requestMethod !== 'POST') { return new Response('无效的请求方法', { status: 400 }); }
if (requestMethod === 'POST') { const postData = { title: notificationTitle, body: notificationBody, }; if (shouldArchive) { postData.isArchive = '1'; } else { postData.isArchive = '2'; } ['level', 'sound', 'icon', 'group', 'badge', 'url', 'copy', 'autocopy'].forEach(param => { const value = formData.get(param); if (value) postData[param] = value; });
apiResponse = await fetch(${apiServerUrl}/${encodeURIComponent(apiKey)}, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(postData),
});
} else {
if (shouldArchive) { queryParams.append('isArchive', '1'); } else { queryParams.append('isArchive', '2'); }
apiResponse = await fetch(completeApiUrl, { method: 'GET' }); }
if (apiResponse.ok) {
return new Response(generateSuccessHTML(), {
headers: {
'Content-Type': 'text/html;charset=UTF-8',
...securityHeaders,
},
});
} else {
// 避免将详细错误信息暴露给用户
return new Response(
<div class="notification error">推送失败,请稍后重试。</div><a href="/">返回</a>,
{
headers: {
'Content-Type': 'text/html;charset=UTF-8',
...securityHeaders,
},
}
);
}
} catch (error) {
// 可在此记录错误日志,例如 console.error(error);
return new Response(
<div class="notification error">发生未知错误,请稍后重试。</div><a href="/">返回</a>,
{
headers: {
'Content-Type': 'text/html;charset=UTF-8',
...securityHeaders,
},
}
);
}
}
return new Response('Not Found', { status: 404 }); }
function sanitizeApiServerUrl(url) { try { const parsedUrl = new URL(url); if (parsedUrl.protocol !== 'https:') { throw new Error('只允许使用 HTTPS 协议的服务器地址'); } return parsedUrl.origin; } catch (error) { throw new Error('无效的服务器 URL'); } }
// 安全头信息 const securityHeaders = { 'Content-Security-Policy': "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'; font-src https://fonts.googleapis.com https://fonts.gstatic.com;", 'X-Content-Type-Options': 'nosniff', 'X-Frame-Options': 'DENY', 'Referrer-Policy': 'no-referrer', 'Strict-Transport-Security': 'max-age=63072000; includeSubDomains; preload', };
function generateHTMLForm() { return `
:root { --primary-color: #7C3AED; --primary-hover-color: #6D28D9; --background-color: #F3F4F6; --card-background-color: #FFFFFF; --text-color: #1F2937; --border-color: #E5E7EB; --success-color: #10B981; --error-color: #EF4444; }
body { font-family: 'Inter', sans-serif; background-color: var(--background-color); color: var(--text-color); line-height: 1.5; margin: 0; padding: 0; }
.container { max-width: 600px; margin: 2rem auto; padding: 2rem; background-color: var(--card-background-color); border-radius: 0.5rem; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); }
h1 { font-size: 2.3rem; font-weight: 600; text-align: center; margin-bottom: 1.5rem; color: var(--primary-color); }
form { display: grid; grid-template-columns: 1fr; gap: 1rem; }
label { font-weight: 500; display: block; margin-bottom: 0.5rem; }
input[type="text"], input[type="url"], input[type="number"], select, textarea { width: 100%; padding: 0.5rem; border: 1px solid var(--border-color); border-radius: 0.25rem; font-size: 1rem; transition: border-color 0.3s ease; }
input[type="text"]:focus, input[type="url"]:focus, input[type="number"]:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1); }
.checkbox-group { display: flex; align-items: center; gap: 0.5rem; width: 100%; }
.checkbox-group input[type="checkbox"] { width: auto; }
button { background-color: var(--primary-color); color: white; border: none; padding: 0.75rem 1rem; font-size: 1rem; font-weight: 500; border-radius: 0.25rem; cursor: pointer; transition: background-color 0.3s ease; }
button:hover { background-color: var(--primary-hover-color); }
.tooltip { position: relative; display: inline-block; margin-left: 0.5rem; cursor: help; }
.tooltip .tooltiptext { visibility: hidden; width: 200px; background-color: #333; color: #fff; text-align: center; border-radius: 6px; padding: 5px; position: absolute; z-index: 1; bottom: 125%; left: 50%; transform: translateX(-50%); opacity: 0; transition: opacity 0.3s; }
.tooltip:hover .tooltiptext { visibility: visible; opacity: 1; }
.notification { padding: 1rem; border-radius: 0.25rem; margin-bottom: 1rem; text-align: center; }
.notification.success { background-color: var(--success-color); color: white; }
.notification.error { background-color: var(--error-color); color: white; }
@media (max-width: 640px) { .container { margin: 1rem; padding: 1rem; } }
确认发送
if (!/^https?:\/\/.+/.test(serverUrl)) { event.preventDefault(); alert('请输入有效的服务器地址,以 http:// 或 https:// 开头'); serverInput.focus(); } });
function generateSuccessHTML() { return `
body { font-family: 'Inter', sans-serif; background-color: var(--background-color); color: var(--text-color); line-height: 1.5; margin: 0; padding: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.container { position: relative; z-index: 140; width: 100%; max-width: 440px; margin: auto; background-color: white; border-radius: 8px; padding: 24px 20px; text-align: center; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); }
.success-icon-container { width: 100%; height: 80px; background-color: var(--success-green); border-radius: 4px; display: flex; align-items: center; justify-content: center; margin-bottom: 20px; }
.success-icon { width: 48px; height: 48px; }
.message { margin-bottom: 8px; font-size: 20px; font-weight: 500; }
.description { margin-bottom: 12px; }
复制文本 下载保存
创建时间: 2024-11-12 06:56:36 更新时间: 2024-11-13 00:30:37 过期删除时间: (两年后)
点击复制只读链接
非法内容举报
确认修改
以下访问记录仅供参考,建议设置密码确保剪贴板不被非法查看。 ID 设备 访问时间 设备IP IP归属地
暂无访问记录
网络剪贴板 - 让数据暂存和传送更简单! 文本编码工具 常见问答 API调用 关于剪贴板 服务条款 反馈建议 友情链接: UU在线工具 文本派