Last active
December 24, 2017 23:13
-
-
Save felinebabies/f87518a30b30757aaf682250bad142e9 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <base target="_top"> | |
| </head> | |
| <body> | |
| <h1>聖晶石カウンタ</h1> | |
| <p> | |
| あなたが今まで石に費やした金額は、<?= fgoStonePriceCounter(); ?>円です。 | |
| </p> | |
| </body> | |
| </html> | |
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 fgoStonePriceCounter() { | |
| var myThreads = GmailApp.search("subject:Google Play のご注文明細 聖晶石"); | |
| var myMsgs = GmailApp.getMessagesForThreads(myThreads); | |
| // 正規表現による金額のマッチング | |
| var myRegexp = /^合計: ¥(.+?)((.*込み))*$/m; | |
| // 合計金額 | |
| var totalPrice = 0; | |
| var valMsgs = []; | |
| for(var i = 0 ; i < myMsgs.length ; i++){ | |
| valMsgs[i] = []; | |
| valMsgs[i][0] = myMsgs[i][0].getSubject(); | |
| valMsgs[i][1] = myMsgs[i][0].getPlainBody(); | |
| var match = myRegexp.exec(valMsgs[i][1]); | |
| if(match != null){ | |
| valMsgs[i][2] = match[1].replace(",", ""); | |
| totalPrice += parseInt(valMsgs[i][2]); | |
| } | |
| } | |
| Logger.log("合計金額:" + totalPrice + "円"); | |
| return(totalPrice); | |
| } | |
| function doGet() { | |
| return HtmlService.createTemplateFromFile("counter").evaluate(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment