-
-
Save tekei/249c294e2f94423d3e4521bf729ae485 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
| (function(){ | |
| var total = 0; | |
| var year = '2024'; | |
| function init(num) { | |
| num = (typeof num !== 'number' ? 0 : num); | |
| if(num === 0) { | |
| $('<div/>').css({ | |
| position: 'fixed', | |
| left: 0, | |
| top: 0, | |
| width: '100%', | |
| height: '100%', | |
| zIndex: 1000, | |
| backgroundColor: 'rgba(0,0,0,.7)', | |
| color: '#fff', | |
| fontSize: 30, | |
| textAlign: 'center', | |
| paddingTop: '15em' | |
| }).attr('id', '___overlay').text('楽天市場いくら使った?').appendTo('body'); | |
| year = window.prompt('何年分の注文を集計しますか?\n半角数字4桁で入力してください', '2024'); | |
| if(!/^[0-9]+$/.test(year)) { | |
| alert('正しい数値を入力してください'); | |
| $('#___overlay').remove(); | |
| return false; | |
| } | |
| } | |
| var progress = load(num+1); | |
| $('#___overlay').text('集計中… / '+(num+1)+'ページ目'); | |
| progress.done(function(price){ | |
| total += price; | |
| init(num+1); | |
| }).fail(function(e){ | |
| alert('あなたは'+year+'年、合計'+ addFigure(total) + '円分の買い物を楽天市場でしました!'); | |
| $('#___overlay').remove(); | |
| }); | |
| } | |
| function load(num) { | |
| var df = $.Deferred(); | |
| var page = get(num); | |
| page.done(function(data) { | |
| var dom = $.parseHTML(data, true); | |
| var _total = 0; | |
| $(dom).each(function(idx, s) { | |
| if(s.nodeName == 'SCRIPT' && s.innerText.startsWith('window.__INITIAL_STATE__ = ')) { | |
| j = s.innerText.slice(27); | |
| state = JSON.parse( j.substring(0, j.indexOf(";\nwindow.__REWIRED_SCHEMAS__"))); | |
| state.orderListData.orderList.forEach((o) => { o.items.forEach((i) => { _total += (i.itemPrice * i.itemUnits); })}); | |
| } | |
| }); | |
| if(_total === 0) df.reject(); | |
| else df.resolve(_total); | |
| }); | |
| return df.promise(); | |
| } | |
| function get(num) { | |
| var df = $.Deferred(); | |
| $.ajax({ | |
| url: 'https://order.my.rakuten.co.jp/purchase-history/order-list/?l-id=pc_header_func_ph&order_year=' + year + '&page=' + num, | |
| success: function(data){ | |
| df.resolve(data); | |
| } | |
| }); | |
| return df.promise(); | |
| } | |
| function addFigure(str) { | |
| var num = new String(str).replace(/,/g, ""); | |
| while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2"))); | |
| return num; | |
| } | |
| if(typeof $ !== 'function') { | |
| var d=document; | |
| var s=d.createElement('script'); | |
| s.src='//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'; | |
| s.onload=init; | |
| d.body.appendChild(s); | |
| } else { | |
| init(); | |
| } | |
| })(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
コンソールに標準出力出すときは、window._console.enableConsole()