Last active
August 29, 2015 14:15
-
-
Save ShingoFukuyama/a8d8aa95a24ae2db7c94 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
(function(){ | |
var domain = location.host; // ドメイン | |
var url = location.href; // URL全体 | |
var extension = location.pathname.split('.').pop(); // 拡張子 | |
// よく切り替える機能はスイッチ用の変数があると、機能のON/OFFしやすい | |
var youtubeSwitch = 1; // 例: 1が有効、0が無効 | |
// ドメインが完全一致 | |
if (domain == 'm.youtube.com') { | |
alert('ドメインが完全一致'); | |
if (youtubeSwitch) { | |
// よく切り替える機能など | |
} | |
return; | |
} | |
// ドメインの一致が部分 | |
if (domain.match('google')) { | |
alert('部分一致'); | |
return; | |
} | |
// URL全体の一致が部分 | |
if (url.match('/search?=')) { | |
alert('部分一致'); | |
return; | |
} | |
// 拡張子がZIP (大文字もしくは小文字) | |
if (extension == 'zip' || extension == 'ZIP') { | |
alert('拡張子がPDF'); | |
return; | |
} | |
// 拡張子がPDF (正規表現 大文字小文字区別なし) | |
if (/^pdf$/i.test(extension)) { | |
alert('拡張子がPDF'); | |
return; | |
} | |
// 正規表現の使用 (高度) | |
if (/\.yahoo\..+search/.test(url)) { | |
alert('正規表現の使用 (高度)'); | |
return; | |
} | |
// その他例 | |
if (domain.match('yoursite.jp')) { | |
// URLのエンコード | |
var encoded = encodeURIComponent(url); | |
// http部分の置換 | |
var replaced = url.replace('http', 'googlechrome'); | |
// URLの移動、外部アプリのURLスキームも可能 | |
location.href = replaced; // URLスキームを入れ替えてChromeで開く | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment