Last active
May 11, 2023 07:41
-
-
Save Shayan-To/2790761d28d43ff990198bc27e1c2001 to your computer and use it in GitHub Desktop.
Sanaar download excel injector
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
// sanaar\.ir/supervisor/assignment | |
div = document.createElement('div') | |
div.innerHTML = '<div class="panel-toolbar"><button class="btn btn-outline-info waves-effect waves-themed btn-sm mr-1" type="button" data-download="excel" onclick="downloadExcel22()"><span><i class="fal fa-file-excel mr-1"></i> دانلود اکسل</span></button></div>' | |
document.querySelector('.panel-hdr').append(div.firstChild) | |
async function downloadExcel22() { | |
const pl = document.querySelectorAll('.page-link') | |
const pages = +pl[pl.length - 1].dataset.page | |
const t = await Promise.all(new Array(pages).fill(0).map((_, i) => fetch(`https://sanaar.ir/supervisor/assignment/page/${i + 1}/${location.search}`).then(r => r.text()))) | |
const data = '\ufeff' + t | |
.map(s => new DOMParser().parseFromString(s, "text/html")) | |
.flatMap(doc => { | |
const a = [...doc.querySelectorAll('table tr')] | |
return a.slice(1, a.length - 1).map(i => { | |
const b = [...i.children] | |
return b.slice(1, b.length - 1).map(j => `"${j.textContent}"`).join(',') | |
}) | |
}) | |
.join("\n") | |
const blob = new Blob([data], {type: 'text/csv'}) | |
const elem = document.createElement('a') | |
elem.href = URL.createObjectURL(blob) | |
elem.download = 'پایش.csv' | |
document.body.appendChild(elem) | |
elem.click() | |
document.body.removeChild(elem) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment