Skip to content

Instantly share code, notes, and snippets.

@GitHub30
Last active January 22, 2018 11:06
Show Gist options
  • Save GitHub30/f6cf5bc33e975c346c6880764c4a2044 to your computer and use it in GitHub Desktop.
Save GitHub30/f6cf5bc33e975c346c6880764c4a2044 to your computer and use it in GitHub Desktop.
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
axios.defaults.headers['x-requested-with'] = 'XMLHttpRequest';
function getURLFromHTML(html){
return new DOMParser().parseFromString(html, "text/html").querySelector('a').href;
}
function getURLById(param, type){
return new Promise((resolve, reject) => {
axios.get('/dp/api/v2/function', {params: {url: 'download', param, isLogin: true}});
var intervalID = setInterval(async () => {
var response = await axios.get('/dp/api/v2/function', {params: {url: 'dlmakecheck', param, isLogin: true, acTime: new Date().getTime()}});
if(response.data.finish){
clearInterval(intervalID);
var url = null;
response.data.item.forEach(item => {
if(item.clsname.startsWith(type))
url = getURLFromHTML(item.html);
});
resolve(url);
}
}, 1000);
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment