diff options
author | anekos | 2011-07-21 22:14:51 +0900 |
---|---|---|
committer | anekos | 2011-07-21 22:58:22 +0900 |
commit | 4255eb2eb8dbc66c634eff4ac489ab2af76d1920 (patch) | |
tree | fb7889b1c9e98af1e39ca8b168ce1e87de2c83d9 /google-plus-commando.js | |
parent | a82b2036492aa28ef3e2a2f8773b7934004e2aae (diff) | |
download | vimperator-plugins-4255eb2eb8dbc66c634eff4ac489ab2af76d1920.tar.bz2 |
OZ_initData が存在しない場合に対応
Diffstat (limited to 'google-plus-commando.js')
-rw-r--r-- | google-plus-commando.js | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/google-plus-commando.js b/google-plus-commando.js index 06a834e..d0d2426 100644 --- a/google-plus-commando.js +++ b/google-plus-commando.js @@ -779,21 +779,61 @@ let INFO = * @return {Boolean} */ function setupGooglePlus () { - let tab = getGooglePlusTab(); - if (tab) { - let data = tab.linkedBrowser.contentWindow.wrappedJSObject.OZ_initData; - if (data) { + function onSuccess () { + liberator.echomsg('Initialized: googleplus'); + } + + function onFail () { + liberator.echoerr('Faild: initialize googleplus'); + } + + function getFromWindow (win) { + let data = win.OZ_initData; + if (!data) + return false; + // XXX 全てのデータが揃っていないケースがあるようなので、検査する + try { store.set('UID', data[2][0]); store.set('AT', data[1][15]); let circles = data[12][0]; // CIRCLES[]: [[Name, Description, ID], ...] store.set('CIRCLES', circles.slice(0, circles.length / 2).map(function (c) [c[1][0], c[1][2], c[0][0]])); - liberator.echomsg('Initialized: googleplus'); + onSuccess(); return true; + } catch (e) { + liberator.log(e); + return false; } } - liberator.echoerr('Faild: initialize googleplus'); - return false; + + // XXX ブラチラ大作戦 + function getFromMakedBrowser () { + let browser = document.createElementNS(XUL, 'browser'); + browser.setAttribute('type', 'content'); + browser.setAttribute('src', 'https://plus.google.com/'); + document.getElementById('main-window').appendChild(browser); + + browser.addEventListener( + 'DOMContentLoaded', + function (e) { + if (e.target !== browser.contentWindow.document) + return; + browser.removeEventListener('DOMContentLoaded', arguments.callee, false); + getFromWindow(browser.contentWindow.wrappedJSObject); + browser.parentNode.removeChild(browser); + }, + false + ); + } + + let found = false; + + let tab = getGooglePlusTab(); + if (tab) + found = getFromWindow(tab.linkedBrowser.contentWindow.wrappedJSObject); + + if (!found) + getFromMakedBrowser(); } /** |