Last active
December 3, 2018 08:57
-
-
Save gotraveltoworld/892420806fd6f40530fa930dccb5bc91 to your computer and use it in GitHub Desktop.
Use a simple JS function to get some notes of the Voicetube's pronunciation challenge service.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @Description: Use JS to get notes from future in console(brwoser). | |
* @Date: 2018-10-18 02:28 | |
* @Author: undefined | |
*/ | |
/*中文說明 | |
此程式必須要在voicetube的口說挑戰網頁並且已經是登入狀態才能運作,記得根據實際需求改寫開始和結束日期 | |
* startDate = '2018-10-19'; | |
* endDate = '2018-10-20'; | |
兩日期間至少要1天以上,不能小於1天。 | |
運行方式:如果是用google chrome,就是開啟開發者模式,然後貼入下方的方法"getAllNotes('2018-10-19', '2018-10-20')"。貼完之後執行即可。 | |
執行方式:在console模式下,輸入"getAllNotes('2018-10-19', '2018-10-20')"就可以執行並且顯示資料了。 | |
PS: 開發者模式開啟方式:http://mark528.pixnet.net/blog/post/33445174-%E5%A5%BD%E7%94%A8%E7%9A%84-chrome-%E5%85%A7%E5%BB%BA%E9%96%8B%E7%99%BC%E4%BA%BA%E5%93%A1%E5%B7%A5%E5%85%B7 | |
(或是 Win10 環境下按下快捷鍵:F12;MAC OS 環境下按下:Cmd + Opt + I),參考:https://developers.google.com/web/tools/chrome-devtools/shortcuts?hl=zh-tw | |
選用'console'頁面,就可以執行以下程式碼。 | |
步驟說明: | |
1. 複製function getAllNotes(startDate = '2018-10-19', endDate = '2018-10-20';) {...} <= 貼到console裡面,並且按下enter | |
2. 複製getAllNotes('2018-10-19', '2018-10-20'),執行程式,記得要跟自身的需求修改開始和結束日期。 | |
*/ | |
function getAllNotes(startDate = '2018-10-19', endDate = '2018-10-20') { | |
let html = document.body.innerHTML; | |
let regexUserId = /userId\:\s*\'([0-9]*)\'/; | |
if (html.match(regexUserId) === null) { | |
console.log('Empty user id'); | |
} else { | |
console.log('OK'); | |
let api = 'https://vtapi.voicetube.com/v2.1.1/zhTW/pronunciationChallenges'; | |
let userId = html.match(regexUserId)[1]; | |
let date = { | |
'startAt': startDate, | |
'endAt': endDate | |
}; | |
let statusApi = | |
`${api}/status?platform=Web&userId=${userId}&startAt=${date.startAt}&endAt=${date.endAt}`; | |
fetch(statusApi) | |
.then(response => response.json()) | |
.then(response => { | |
if (response.hasOwnProperty('data')) { | |
return Promise.all(response.data.map(e => { | |
return fetch( | |
`${api}/${e.id}?platform=Web&&userId=${userId}` | |
).then(response => response.json() | |
).then(response => { | |
response['data']['date'] = e.date; | |
return response; | |
}); | |
})); | |
} | |
}).then(response => { | |
if (Array.isArray(response)) { | |
return response.map(e => { | |
if (e.hasOwnProperty('data')) { | |
return e.data; | |
} else { | |
return undefined; | |
} | |
}); | |
} else { | |
console.log('Not array.'); | |
} | |
}).then(response => { | |
console.log(response); | |
if (Array.isArray(response)) { | |
response.forEach((e, k) => { | |
console.log('---開始線---'); | |
console.log('---日期---', e.date); | |
console.log('主持人錄音:', e.audioUrl); | |
console.log('主持人:', e.host.displayName); | |
console.log('標題:', e.title); | |
console.log('內文:', e.content); | |
let start = e.startAt; | |
let end = e.startAt + e.duration; | |
console.log('Youtube 影片連結:', | |
`https://www.youtube.com/embed/${e.youtubeId}?rel=0&showinfo=0&cc_load_policy=0&controls=1&autoplay=1&iv_load_policy=3&playsinline=1&wmode=transparent&start=${start}&end${end}=&enablejsapi=1&origin=https://tw.voicetube.com&widgetid=1` | |
); | |
console.log('單字:', e.vocabularies); | |
console.log('---終止線---'); | |
}); | |
} | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkExistence(days = 10) { | |
let end = new Date(); | |
end.setDate(end.getDate() + parseInt(days)); | |
let startDate = (new Date()).toISOString().slice(0,10); | |
let endDate = end.toISOString().slice(0,10); | |
let html = document.body.innerHTML; | |
let regexUserId = /userId\:\s*\'([0-9]*)\'/; | |
if (html.match(regexUserId) === null) { | |
console.log('Empty user id'); | |
} else { | |
console.log('OK'); | |
let api = 'https://vtapi.voicetube.com/v2.1.1/zhTW/pronunciationChallenges'; | |
let userId = html.match(regexUserId)[1]; | |
let date = { | |
'startAt': startDate, | |
'endAt': endDate | |
}; | |
let statusApi = | |
`${api}/status?platform=Web&userId=${userId}&startAt=${date.startAt}&endAt=${date.endAt}`; | |
fetch(statusApi) | |
.then(response => response.json()) | |
.then(response => { | |
if (response.hasOwnProperty('data')) { | |
return Promise.all(response.data.map(e => { | |
return fetch( | |
`${api}/${e.id}?platform=Web&&userId=${userId}` | |
).then(response => response.json() | |
).then(response => { | |
response['data']['date'] = e.date; | |
return response; | |
}); | |
})); | |
} | |
}).then(response => { | |
if (Array.isArray(response)) { | |
return response.map(e => { | |
if (e.hasOwnProperty('data')) { | |
return e.data; | |
} else { | |
return undefined; | |
} | |
}); | |
} else { | |
console.log('Not array.'); | |
} | |
}).then(response => { | |
console.log(response); | |
if (Array.isArray(response)) { | |
response.forEach((e, k) => { | |
console.log('---開始線---'); | |
console.log('日期, 主持人錄音:', e.date, e.audioUrl); | |
console.log('主持人:', e.host.displayName); | |
console.log('標題:', e.title); | |
console.log('內文:', e.content); | |
let start = e.startAt; | |
let end = e.startAt + e.duration; | |
console.log('Youtube 影片連結:', | |
`https://www.youtube.com/embed/${e.youtubeId}?rel=0&showinfo=0&cc_load_policy=0&controls=1&autoplay=1&iv_load_policy=3&playsinline=1&wmode=transparent&start=${start}&end${end}=&enablejsapi=1&origin=https://tw.voicetube.com&widgetid=1` | |
); | |
console.log('---終止線---'); | |
}); | |
} | |
}); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment