// 按F12
// 先拷貝下面這段到 console 運行, 注入 jquery 功能
var body = document.getElementsByTagName('body')[0];
var s = document.createElement('script');
s.setAttribute('type', 'text/javascript');
s.setAttribute('src', 'https://code.jquery.com/jquery-3.2.1.min.js');
body.appendChild(s);
//上面執行成功再拷貝執行下面的:
var sectionCount = 100; // 每次從豆瓣拉取幾條歌曲詳情
var outputCount = 150; // 每個區塊輸出幾首歌曲, 超過150條QQ音樂無法識別
var limit = 0; // 只獲取前 limit 首歌曲
var songIds = [];
var songSection = [];
var songInfos = []
start();
function start() {
$.get("https://douban.fm/j/v2/redheart/basic", function (data) {
for (var i in data.songs) {
songIds.push(data.songs[i].sid);
}
if (limit > 0) {
songIds = songIds.slice(0, limit);
}
console.log("獲取到歌曲id " + songIds.length + "條");
loadSection();
});
}
function loadSection() {
songSection = [];
var count = (songIds.length < sectionCount) ? songIds.length : sectionCount;
songSection = songIds.slice(0, count);
songIds.splice(0, count);
var sectionIds = songSection.join("|");
console.log("開始抓取歌曲 " + songSection.length + "條");
console.log("剩余歌曲 " + songIds.length + "條");
$.post("https://douban.fm/j/v2/redheart/songs", {
sids: sectionIds,
kbps: 192,
ck: "lM1o"
}, function (data) {
// console.log(data);
for (var i in data) {
var songInfo = {};
songInfo.title = data[i].title;
songInfo.artist = data[i].artist;
songInfo.album = data[i].albumtitle;
songInfos.push(songInfo);
}
//console.log(songInfos);
if (songSection.length < sectionCount) {
processInfos();
} else {
setTimeout(loadSection, 3 * 1000);
}
});
}
function processInfos() {
$("body").html("");
console.log("準備展示數據: " + songInfos.length + "條");
while (songInfos.length > 0) {
outputSection = [];
var count = (songInfos.length < outputCount) ? songInfos.length : outputCount;
outputSection = songInfos.slice(0, count);
songInfos.splice(0, count);
var content = [];
content.push("歌曲標題<br>時長<br>歌手<br>專輯<br><br>");
for (var i = 0; i < outputSection.length; i++) {
content.push(outputSection[i].title);
content.push("<br><br>");
content.push(outputSection[i].artist);
content.push("<br>");
content.push(outputSection[i].album);
content.push("<br><br>");
}
$("body").append("<div contenteditable=\"true\" style=\"border: 1px solid black;" +
"padding: 1rem;margin: 1rem;max-height: 150px;overflow-y: scroll;\"><div>");
$("body > div:last").html(content.join(""));
}
console.log("數據展示完成");
alert("完成, 請剪切區塊內容到導入頁面");
}
// 最后, 將頁面中出現的每個區塊內容分別剪切到QQ音樂的網易云導入頁面:
// PS. 記得登錄.
posted on 2017-08-11 16:13
ApolloDeng 閱讀(1480)
評論(0) 編輯 收藏 所屬分類:
Js/JQuery/Ajax