Last active
July 14, 2019 07:52
-
-
Save mmmcorpsvit/704cd95ce0aad3fbef97ab19f9c8fd9c to your computer and use it in GitHub Desktop.
Function for get status active downloads (dont forget open chrome://downloads/)
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
// Tested on Chrome 75 | |
function donwloads_status() { | |
let tag = document.querySelector('downloads-manager').shadowRoot; | |
let item_tags = tag.querySelectorAll('downloads-item'); | |
let items_count = item_tags.length; | |
let progress_lst = []; | |
for (let i = 0; i < items_count; i++) { | |
let intag = item_tags[i].shadowRoot; | |
let _filename = intag.getElementById('name').innerText; | |
let _url = intag.getElementById('url').innerText; | |
let _description = intag.getElementById('description').innerText; | |
let _progress = -1; | |
let _status = -1; | |
try { | |
_progress = intag.getElementById('progress').value; | |
} catch (e) { | |
// console.log('get progress error: ', e.text); | |
} | |
// finished, all ok, 0 | |
let _status0 = false; | |
try { | |
_status0 = !intag.getElementById('show').hidden; | |
} catch (e) { | |
} | |
// paused, 1 | |
let _status1 = false; | |
try { | |
_status1 = intag.querySelector('paper-button').tabIndex === 0; | |
} catch (e) { | |
} | |
// fail, 2 | |
let _status2 = false; | |
try { | |
_status2 = intag.querySelector('paper-button').tabIndex === -1; | |
} catch (e) { | |
} | |
if (_status0 === true) { | |
_status = 0; | |
} | |
if (_status2 === true) { | |
_status = 2; | |
} | |
if (_status1 === true) { | |
_status = 1; | |
} | |
let items_status = { | |
'url': _url, | |
'filename': _filename, | |
'status': _status, | |
'status_text': _description, | |
'progress': _progress, | |
}; | |
// let progress = progress_tag.innerText; | |
progress_lst.push(items_status); | |
} | |
return progress_lst; | |
} | |
console.log(donwloads_status()); |
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
// Tested on Chrome 75 | |
function downloads_status() { | |
// let tag = document.querySelector('downloads-manager').shadowRoot; | |
let item_tags = document.querySelector('downloads-manager').shadowRoot.querySelectorAll('downloads-item'); | |
let items_count = item_tags.length; | |
let progress_lst = []; | |
for (let i = 0; i < items_count; i++) { | |
if (item_tags[i].hidden){ | |
continue; | |
} | |
let intag = item_tags[i].shadowRoot; | |
let _filename = intag.getElementById('name').innerText; | |
let _url = intag.getElementById('url').innerText; | |
let _description = intag.getElementById('description').innerText; | |
let _progress = -1; | |
let _status = -1; | |
try { | |
_progress = intag.getElementById('progress').value; | |
} catch (e) { | |
// console.log('get progress error: ', e.text); | |
} | |
// finished, all ok, 0 | |
let _status0 = false; | |
try { | |
_status0 = !intag.getElementById('show').hidden; | |
} catch (e) { | |
} | |
// paused, 1 | |
let _status1 = false; | |
try { | |
_status1 = intag.querySelector('paper-button').tabIndex === 0; | |
} catch (e) { | |
} | |
// fail, 2 | |
let _status2 = false; | |
try { | |
_status2 = intag.querySelector('paper-button').tabIndex === -1; | |
} catch (e) { | |
} | |
if (_status0 === true) { | |
_status = 0; | |
} | |
if (_status2 === true) { | |
_status = 2; | |
} | |
if (_status1 === true) { | |
_status = 1; | |
} | |
let items_status = { | |
'url': _url, | |
'filename': _filename, | |
'status': _status, | |
'status_text': _description, | |
'progress': _progress, | |
}; | |
// let progress = progress_tag.innerText; | |
progress_lst.push(items_status); | |
} | |
return progress_lst; | |
} | |
downloads_status(); | |
// return true; | |
// console.log(downloads_status()); | |
// return downloads_status(); | |
// remove first file from history | |
// document.querySelector('downloads-manager').shadowRoot.querySelectorAll('downloads-item')[0].shadowRoot.getElementById('remove').click() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// Tested on Chrome 75
function downloads_status() {
// let tag = document.querySelector('downloads-manager').shadowRoot;
let item_tags = document.querySelector('downloads-manager').shadowRoot.querySelectorAll('downloads-item');
}
downloads_status();
// return true;
// console.log(downloads_status());
// return downloads_status();
// remove first file from history
// document.querySelector('downloads-manager').shadowRoot.querySelectorAll('downloads-item')[0].shadowRoot.getElementById('remove').click()