Last active
January 22, 2018 11:06
-
-
Save GitHub30/f6cf5bc33e975c346c6880764c4a2044 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<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