Skip to content

Instantly share code, notes, and snippets.

@Meigyoku-Thmn
Last active December 2, 2022 06:46
Show Gist options
  • Save Meigyoku-Thmn/b9c59d2271a3b55280fc2f5590b12e04 to your computer and use it in GitHub Desktop.
Save Meigyoku-Thmn/b9c59d2271a3b55280fc2f5590b12e04 to your computer and use it in GitHub Desktop.
Script để lấy danh sách gọi vốn trên Comicola
(() => {
function resolveDate(str) {
const match = /(.+?) (\d{2}), (\d{4})/.exec(str);
const months = {
'Tháng Một': 1,
'Tháng Hai': 2,
'Tháng Ba': 3,
'Tháng Tư': 4,
'Tháng Năm': 5,
'Tháng Sáu': 6,
'Tháng Bảy': 7,
'Tháng Tám': 8,
'Tháng Chín': 9,
'Tháng Mười': 10,
'Tháng Mười Một': 11,
'Tháng Mười Hai': 12,
};
const month = months[match[1]];
if (month == null)
throw Error('Invalid month: ' + match[1]);
return `${match[2]}/${month}/${match[3]}`;
}
const table = Array.from(document.querySelectorAll(".table > tbody > tr"))
.slice(1)
.map(elem => Array.from(elem.querySelectorAll("td")))
.map(row => row.map(elem => elem.innerText))
.map(row => [row[0], row[1], resolveDate(row[2])])
.map(row => row.map(cell => cell.replaceAll(',', '').replaceAll('₫', '').trim()).map(cell => `"${cell}"`).join());
table.splice(0, 0, ['Tên,Quyên góp,Date']);
const a = document.createElement('a');
a.download = "input.csv";
a.href = URL.createObjectURL(new Blob([table.join('\n')], {type: 'text/csv'}));
a.click();
a.remove();
})();
@Meigyoku-Thmn
Copy link
Author

Vào trang gọi vốn nào đó trên Comicola, bật danh sách người quyên góp lên rồi bỏ cái này vào Console, chạy và sẽ có file csv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment