Created
February 18, 2022 16:50
-
-
Save ajaxsys/4a006718b16e35eb2ba4a976928c8dcc to your computer and use it in GitHub Desktop.
Web21デビュー版のCSVダウンロードのbookmarklet (consoleで貼り付けて実行可)
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
| (function() { | |
| function formatYYYYMM(dt) { | |
| var y = dt.getFullYear(); | |
| var m = ('00' + (dt.getMonth()+1)).slice(-2); | |
| var d = ('00' + dt.getDate()).slice(-2); | |
| return (y + m); | |
| } | |
| function getUpperLinePrice(txt) { | |
| return txt | |
| .replaceAll(',', '') | |
| .replaceAll(' ', '') | |
| .replaceAll('\n', ' ') | |
| .trim() | |
| .split(' ')[0]; | |
| } | |
| var d = [] | |
| var c = [] | |
| $('.tbl_style tr').each(function(i, e) { | |
| var dd = [] | |
| var cc = [] | |
| if(i === 0) { | |
| $(this).find('th').each(function(j, el) { | |
| cc.push(getUpperLinePrice($(this).text())) | |
| }) | |
| c.push(cc) | |
| } else { | |
| $(this).find('td').each(function(j, el) { | |
| dd.push(getUpperLinePrice($(this).text())) | |
| }) | |
| d.push(dd) | |
| } | |
| }) | |
| var m = $.merge(c, d) | |
| //csv出力処理記述 | |
| // BOM の用意(文字化け対策) | |
| var bom = new Uint8Array([0xEF, 0xBB, 0xBF]) | |
| // CSV データの用意 | |
| var csv_data = m.map(function(l){return l.join(',')}).join('\n') | |
| var blob = new Blob([bom, csv_data], { type: 'text/csv' }) | |
| var url = (window.URL || window.webkitURL).createObjectURL(blob) | |
| var a = document.createElement("a"); | |
| a.download = 'ts_' + formatYYYYMM(new Date()) + '.csv' | |
| a.href = url | |
| document.body.appendChild(a); | |
| // ダウンロードリンクをクリックする | |
| a.click() | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment