From d764299ad6c50731affd8f67cf54fe864fef48f1 Mon Sep 17 00:00:00 2001 From: anekos Date: Thu, 16 Aug 2012 20:46:38 +0900 Subject: Follow yahoo changes. --- umihara.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'umihara.js') diff --git a/umihara.js b/umihara.js index fe61b9f..677e8fe 100644 --- a/umihara.js +++ b/umihara.js @@ -39,7 +39,7 @@ let PLUGIN_INFO = 外国為替換算 for exchangeconvertion 為替換算をします - 1.1.1 + 1.1.2 anekos new BSD License (Please read the source code comments of this plugin) 修正BSDライセンス (ソースコードのコメントを参照してください) @@ -61,6 +61,8 @@ let PLUGIN_INFO = let g:umihara_default_source="USD" let g:umihara_default_target="JPY" ||< + == Require == + _libly.js ]]> ; // }}} @@ -90,8 +94,6 @@ let PLUGIN_INFO = const defaultSource = liberator.globalVariables.umihara_default_source || 'USD'; const defaultTarget = liberator.globalVariables.umihara_default_target || 'JPY'; - const re = /(\d+:\d+)<\/td>([\d,]+\.[\d,]+)<\/td>([\d,]+\.[\d,]+)<\/b><\/td><\/tr><\/table><\/div>/; - const ContryCodes = [ ['USD', '\u30a2\u30e1\u30ea\u30ab\u30c9\u30eb'], ['GBP', '\u30a4\u30ae\u30ea\u30b9 \u30dd\u30f3\u30c9'], @@ -146,18 +148,28 @@ let PLUGIN_INFO = from = defaultSource; if (to == '-') to = defaultTarget; - let url = 'http://quote.yahoo.co.jp/m5?a=' + value + '&s=' + from + '&t=' + to; + //let url = 'http://quote.yahoo.co.jp/m5?a=' + value + '&s=' + from + '&t=' + to; + let url = 'http://info.finance.yahoo.co.jp/exchange/convert/?a=' + value + '&s=' + from + '&t=' + to; var req = new XMLHttpRequest(); req.open('GET', url); req.onreadystatechange = function (aEvt) { if (req.readyState == 4 && req.status == 200) { - let m = req.responseText.match(re); - if (m) { + let html = req.responseText; + let doc = plugins.libly.$U.createHTMLDocument(html); + liberator.log(doc); + let a = doc.querySelector('tbody.yjM > tr > td > a[href^="http://stocks"]'); + if (a) { + let tr = a.parentNode.parentNode; + liberator.__tr = tr; + let toValue = tr.querySelectorAll('td')[3].textContent; + let rateTime = tr.querySelectorAll('td')[2].textContent.match(/([\d,]+\.[\d,]+).*(\d+:\d+)/); + let rate = rateTime[1]; + let time = rateTime[2]; let text = from + ' -> ' + to + '\n ' + from + ': ' + value + - '\n ' + to + ': ' + m[3] + - '\n rate: ' + m[2] + - '\n time: ' + m[1]; + '\n ' + to + ': ' + toValue + + '\n rate: ' + rate + + '\n time: ' + time; echo(text); if (clipboard) { resultBuffer += text + '\n'; -- cgit v1.2.3