Last active
August 29, 2015 14:15
-
-
Save ShingoFukuyama/a9136f101718371f80ed to your computer and use it in GitHub Desktop.
This file contains 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
/* Before load user script for Ohajiki Web Browser | |
* 読み込み前用です。 | |
* FacebookとTwitter関連のページを開くときにそれぞれの公式アプリで開くか確認を取ります。 | |
* 動きますが、まだ他にも調整が必要かもしれません。 | |
*/ | |
(function(){ | |
/* Facebook公式アプリで開く */ | |
var facebook = 1; // 1:有効, 0:無効 | |
var facebookConfirm = 0; // 確認してから移動するか | |
/* Twitter公式アプリで開く */ | |
var twitter = 1; | |
var twitterConfirm = 0; | |
var url = location.href, | |
d = document; | |
var prepareForJump = function(){ | |
location.href = 'about:blank'; | |
}; | |
/* Facebook公式アプリで開く */ | |
if (facebook && /\.facebook\.com/.test(url)) { | |
var openInFacebook = function(id) { | |
var fbURL = 'fb://profile/'+id; | |
if (facebookConfirm) { | |
if (confirm('Facebookアプリで開きますか?')) { | |
prepareForJump(); | |
location.href = fbURL; | |
} | |
} else { | |
prepareForJump(); | |
location.href = fbURL; | |
} | |
}; | |
if (!/id\=/.test(url)) { | |
var splited = url.split('/'); | |
var user = splited[splited.length-1]; | |
user = user.replace(/(.+?)[?#].*/, '$1'); | |
if (!/\S/.test(user)) return; | |
if (/^[0-9]+$/.test(user)) { | |
openInFacebook(user); | |
return; | |
} | |
/* ID 割り出し */ | |
$.ajax({ | |
dataType: 'json', | |
url: 'http://graph.facebook.com/'+user, | |
data: null, | |
success: function(success) { | |
openInFacebook(success.id); | |
} | |
}); | |
} else { | |
var id = url.replace(/.+id\=([0-9]+).*/, '$1'); | |
openInFacebook(id); | |
} | |
} | |
/* Twitter公式アプリで開く */ | |
if (twitter && /\.twitter\.com/.test(url)) { | |
var result; | |
if (/\/status\//.test(url)) { | |
var status = url.replace(/.+\/status\/([0-9]+).*/, '$1'); | |
if (/\S/.test(status)) { | |
result = 'twitter://status?id='+status; | |
} | |
} else { | |
var user = url.split('/')[3]; | |
if (/\S/.test(user)) { | |
result = 'twitter://user?screen_name='+user; | |
} | |
} | |
if (result) { | |
if (twitterConfirm) { | |
if (confirm('Twitterアプリで開きますか?')) { | |
prepareForJump(); | |
location.href = result; | |
} | |
} else { | |
prepareForJump(); | |
location.href = result; | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment