|
|
这个网站好像做了反爬的设置。
打开多了或者访问频繁了会失败。
一个一个点,说实话有点麻烦,凑合用吧。
www.ting13.cc
[code]// ==UserScript==
// @name 13听书网 · 精准下载(自动命名·进度显示)
// @namespace https://www.ting13.cc/
// @version 5.0
// @description 点击下载,通过流方式获取音频,自动命名,显示下载进度,无干扰。
// @author You
// @match https://www.ting13.cc/play/*
// @grant GM_setClipboard
// @grant GM_xmlhttpRequest
// @connect mp3nn.ysxs.top
// @license MIT
// ==/UserScript==
(function() {
'use strict';
function getChapterInfo() {
const h1 = document.querySelector('h1');
if (!h1) return null;
const raw = h1.textContent.trim();
const match = raw.match(/正在播放[::]\s*(.+?)\.mp3$/);
if (!match) return null;
return {
full: match[1],
filename: match[1] + '.mp3'
};
}
function getAudioUrl() {
const audio = document.querySelector('audio');
if (audio && audio.src) return audio.src;
const jplayer = document.getElementById('jquery_jplayer_1');
if (jplayer) {
const audioEl = jplayer.querySelector('audio');
if (audioEl && audioEl.src) return audioEl.src;
}
return null;
}
function downloadWithProgress(url, filename) {
const btn = document.getElementById('ting13-download-btn');
if (!btn) return;
btn.disabled = true;
btn.textContent = '⏳ 0%';
GM_xmlhttpRequest({
method: 'GET',
url: url,
responseType: 'blob',
onprogress: function(ev) {
if (ev.lengthComputable) {
const percent = Math.round((ev.loaded / ev.total) * 100);
btn.textContent = `⏳ ${percent}%`;
} else {
btn.textContent = '⏳ 下载中...';
}
},
onload: function(response) {
const blob = new Blob([response.response], { type: 'audio/mpeg' });
const blobUrl = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = blobUrl;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
setTimeout(() => URL.revokeObjectURL(blobUrl), 5000);
btn.textContent = '✅ 完成';
setTimeout(() => {
btn.textContent = '⬇ 下载';
btn.disabled = false;
}, 2000);
},
onerror: function() {
alert('下载失败,请检查网络或重试。');
btn.textContent = '⬇ 下载';
btn.disabled = false;
}
});
}
function createWidget(info, audioUrl) {
const old = document.getElementById('ting13-download-widget');
if (old) old.remove();
if (!audioUrl) return;
const widget = document.createElement('div');
widget.id = 'ting13-download-widget';
widget.style.cssText = `
position: fixed;
bottom: 20px;
right: 20px;
z-index: 9999;
background: rgba(20,20,20,0.85);
backdrop-filter: blur(4px);
color: #eee;
padding: 8px 14px;
border-radius: 8px;
border: 1px solid #444;
font-size: 13px;
font-family: sans-serif;
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
opacity: 0.8;
transition: opacity 0.3s;
box-shadow: 0 2px 10px rgba(0,0,0,0.4);
`;
widget.innerHTML = `
<span style="color:#aaa;font-size:12px;max-width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="${info.full}">${info.full}</span>
<button id="ting13-download-btn" style="background:#00d4aa;border:none;color:#000;padding:4px 14px;border-radius:4px;font-weight:bold;cursor:pointer;font-size:12px;">
⬇ 下载
</button>
<span id="close-widget" style="color:#666;cursor:pointer;font-size:16px;line-height:1;">✕</span>
`;
document.body.appendChild(widget);
document.getElementById('ting13-download-btn').addEventListener('click', (e) => {
e.stopPropagation();
downloadWithProgress(audioUrl, info.filename);
});
document.getElementById('close-widget').addEventListener('click', () => {
widget.style.opacity = '0';
setTimeout(() => widget.remove(), 300);
});
widget.addEventListener('mouseenter', () => widget.style.opacity = '1');
widget.addEventListener('mouseleave', () => widget.style.opacity = '0.8');
}
function main() {
const info = getChapterInfo();
if (!info) return;
const audioUrl = getAudioUrl();
if (!audioUrl) return;
try {
GM_setClipboard(info.full);
} catch (e) {}
createWidget(info, audioUrl);
console.log(` |
上一篇:澎湃工具箱
|