SteamTransactions2DataGrid

by miyaoka
Steamの購入履歴( https://store.steampowered.com/account/ )がそのままだと非常に扱いづらいので、パースしてDataGridで見れるようにします。
合計金額の算出と、タブ区切り形式でのコピーができます。

つかいかた:
1.スチムーのアカウントページを開く
2.ソースを表示
3.ソースを全文選択コピーして右上のボックスに貼り付ける
♥0 | Line 151 | Modified 2010-12-25 15:50:53 | MIT License
play

ActionScript3 source code

/**
 * Copyright miyaoka ( http://wonderfl.net/user/miyaoka )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lSj1
 */

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" paddingTop="4" paddingRight="4" paddingLeft="4" paddingBottom="4">
<mx:ArrayCollection id="items" collectionChange="onCollectionChange(event)"/>
<mx:DateFormatter id="dft" formatString="YYYY/MM/DD"/>
<mx:NumberFormatter id="nft" precision="2"/>
<mx:String id="totalPriceText"/>
<mx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.events.CollectionEvent;
        public static const SEARCH_URL_BASE:String = 'http://store.steampowered.com/search/?term=';
        private static const trHeader:String = 'div class="transactions"';
        private static const trFooter:String = 'id="transaction_footer_self"';
        private static const liHeader:String = 'id="licenses"';
        private static const liFooter:String = 'id="store_transactions"';
        private var htmlTf:TextField = new TextField();
        private function parseSource(text:String):void
        {
            items.source = []
            text = text.replace(/[\n\r\t]/g, "");
            var lines:Array = text            
            .replace(new RegExp(".*" + trHeader + "(.*?)" + trFooter + ".*", "si"), "$1")
            .replace(/<[^<]*?"transactionRow .*?>/gi, "\n")
            .replace(/<[^<]*?"transactionRow.*?>/gi, "\t")
            .replace(/<[^>]*?>|&nbsp;/gi, "")
            .replace(/.*?>/m, "")
            .replace(/<[^<]*/m, "")
            .split("\n");

            var lines2:Array = text
            .replace(new RegExp(".*" + liHeader + "(.*?)" + liFooter + ".*", "si"), "$1")
            .replace(/<[^<]*?"licenseRow .*?>/gi, "\n")
            .replace(/<[^<]*?"licenseRow.*?>/gi, "\t")
            .replace(/<p>/gi, "\t")
            .replace(/<[^>]*?>/gi, "")
            .replace(/.*?>/m, "")
            .replace(/<[^<]*/m, "")            
            .split("\n");

            var line:String;
            var params:Array;
            for each (line in lines)
            {
                htmlTf.htmlText = line;
                params = htmlTf.text.split("\t");
                if(params.length != 6) continue;
                items.source.push({
                    date: new Date(params[1]),
                    price: params[2],
                    event: params[3],
                    items: params[5]
                });
            }
            
            var itemsAryCopy:Array = items.source.concat();
            outerloop: for each (line in lines2)
            {
                params = line.split("\t");
                if(params.length != 3) continue;
                for(var i:int = 0; i < itemsAryCopy.length; i++)
                {
                    if(itemsAryCopy[i].items == params[2])
                    {
                        itemsAryCopy[i].method = params[1];
                        itemsAryCopy.splice(i,1);
                        continue outerloop;
                    }
                }
            }
            items.refresh();
        }
        private function onCollectionChange(e:CollectionEvent):void
        {
            var totalPrices:Object = {};
            var currency:String;
            
            for each (var item:Object in items.source)
            {
                var priceParams:Array = ((item.price as String).match(/(\D)([0-9.]+)/));
                if(!priceParams) continue;
                currency= priceParams[1];
                var price:Number = Number(priceParams[2]);
                if(!totalPrices[currency])
                {
                    totalPrices[currency] = 0;
                }
                totalPrices[currency] += price;
            }
            
            var formatPrices:Array = [];
            for (currency in totalPrices)
            {
                formatPrices.push(currency + nft.format(totalPrices[currency]));
            }
            totalPriceText = formatPrices.join(", ");
        }
        private function dateLabel(item:Object, column:DataGridColumn):String
        {
            return dft.format(item[column.dataField]);
        }
        private function copyToClipBoard():void
        {
            var lines:Array = [];
            lines.push(["items", "date", "price", "method", "event", "link"].join("\t"));
            for(var i:int = 0; i < items.length; i++)
            {
                var item:Object = items.getItemAt(i);
                lines.push(
                [item.items, dft.format(item.date), item.price, item.method, item.event,
                '=HYPERLINK("' + "http://store.steampowered.com/search/?term=" + escape(item.items) + '","[LINK]")'
                ].join("\t"));
            }
            lines.push("\nTotalPrice\t\t" + totalPriceText);
            
            System.setClipboard(lines.join("\n"));
            Alert.show("クリップボードにコピーしました", "", Alert.OK);            
        }
    ]]>
</mx:Script>
    <mx:HBox width="100%">
        <mx:Text>
            <mx:htmlText>
                <![CDATA[Input your source text from
( <a href="https://store.steampowered.com/account/">https://store.steampowered.com/account/</a> )
into right area.]]>
            </mx:htmlText>
        </mx:Text>
        <mx:TextArea id="inputSource" change="parseSource(inputSource.text)" width="100%"/>
    </mx:HBox>
    <mx:DataGrid dataProvider="{items}" width="100%" height="100%">
        <mx:columns>
            <mx:DataGridColumn headerText="items" dataField="items"/>
            <mx:DataGridColumn headerText="date" dataField="date" labelFunction="{dateLabel}"/>
            <mx:DataGridColumn headerText="price" dataField="price"/>
            <mx:DataGridColumn headerText="event" dataField="event" visible="false"/>
            <mx:DataGridColumn headerText="method" dataField="method"/>
            <mx:DataGridColumn headerText="link" dataField="items" width="50">
                <mx:itemRenderer>
                    <mx:Component>
                        <mx:Button label="■" fontSize="8" click='
                            navigateToURL(
                                new URLRequest(
                                    "http://store.steampowered.com/search/?term=" + escape(data.items)
                                )
                            );                        
                        '/>
                    </mx:Component>
                </mx:itemRenderer>
                
            </mx:DataGridColumn>
        </mx:columns>
    </mx:DataGrid>
    <mx:HBox width="100%">
        <mx:Label text="TotalPrice"/>
        <mx:TextInput width="100%" text="{totalPriceText}"/>
    </mx:HBox>
    <mx:Button click="copyToClipBoard()" label="copy to ClipBoard" />
    
</mx:Application>