qrac / ie-buster Goto Github PK
View Code? Open in Web Editor NEWSave web creators with Chrome link popup for IE.
Home Page: https://ie-buster.qranoko.jp
License: MIT License
Save web creators with Chrome link popup for IE.
Home Page: https://ie-buster.qranoko.jp
License: MIT License
nuxt.config.js
module.exports = {
head: {
script: [
{ src: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/ie-buster.min.js' }
]
}
}
とりあえず、これでいける?
npm installとかではなくて?
専用のライブラリ化・プラグイン化とか必要?
妻からの提案。まだ、プラグインの作り方も公式リポジトリへの上げ方も知らず。
UAは偽装も可能らしく、ブラウザの機能で判定可能とのご意見をいただいたので検証する。コードも短くできそう。
Autoprefixerの設定がIE11になっていたからか、IE9以下で動作していない。なんとかする?
以下、動作非検証ですが、classで書いてbabelで変換みたいな感じです。IE8でも頑張れば行けるようですが、そこまで頑張るかは要判断ですねw
https://qiita.com/k_ui/items/bd728f059f868b8ee528
一応以下コード置いときます。確認して適当にcloseお願いします。
class ieBuster {
constructor(message) {
this.message = message
this.ieBusterTarget = document.getElementsByTagName('body')[0]
this.ieBusterApp = document.createElement('div')
}
ieBusterUserAgentCheck() {
const ieBusterUserAgent = window.navigator.userAgent.toLowerCase()
if (
~ieBusterUserAgent.indexOf('msie') ||
~ieBusterUserAgent.indexOf('trident')
)
return true
}
main() {
if (this.ieBusterUserAgentCheck()) {
this.ieBusterApp.innerHTML =
'<div style="position: fixed; top: 0px; left: 0; width: 100%; padding: 16px; box-sizing: border-box; z-index: 999999;">' +
'<div style="width: 100%; max-width:866px; margin: 0 auto; padding: 16px 20px; background-color: #fff; box-shadow: rgba(0, 0, 0, 0.4) 0px 0px 5px 0px; box-sizing: border-box; font-family: SegoeUI, Meiryo, sans-serif;">' +
'<p style="display: block; float: left; width: 100%; max-width: 664px; margin: 0; color: #000; font-size: 14px; font-weight: 400; line-height: 1.5;">' +
this.message +
'</p>' +
'<a style="display: block; float: right; height: 36px; width: 154px; padding: 0 16px; background-color: rgb(0, 120, 212); box-sizing: border-box; color: #fff; font-size: 12px; font-weight: 400; line-height: 36px; text-align: center; text-decoration: none; white-space: nowrap;" href="https://www.google.com/chrome/" target="_blank" rel="noopener noreferrer">ダウンロードページへ</a>' +
'<div style="clear: both;"></div>' +
'</div>' +
'</div>'
this.ieBusterTarget.appendChild(this.ieBusterApp)
}
}
}
window.onload = () => {
const ieBuster = new ieBuster(
'ご利用のインターネットブラウザは推奨環境ではありません。セキュリティリスクが高い状態ですので、最新の Google Chrome をご利用ください。'
)
ieBuster.main()
}
最初の div
にスタイルを当てれば1つ省略できる。また、利用者のカスタマイズ性を上げるためにIDを付与する。IE8で動くか要確認。
ieBusterApp.id = 'ie-buster-app'
ieBusterApp.setAttribute(
'style',
'position: fixed; top: 0px; left: 0; width: 100%; padding: 16px; box-sizing: border-box; z-index: 999999;'
)
制作のしやすさからWebpack+SCSSで作っているものの、AutoprefixerやBabelが気を使ってくれてビルド時に旧ブラウザ用のコードを吐いていることだろうと思う。
現状は10.1 KBだけど、そもそも旧式の書き方をすればもっと削れるのではないだろうか。極限まで容量を削って気軽に導入できるようにする。Webpackなどのコードを変換するツールはすべて省く。
妻に依頼中。8月はどちらも忙しいので9月にでも。
CodePen以外のデモを作成。
ブラウザの種類を認知されていない層にはセキュリティリスクの訴求が刺さりやすいものの、サポートが続いているバージョンのIEに関してはセキュリティアップデートが行われているため、文言が必ずしも的確でない状態になっている。
逆に「JavaScriptが動かない・CSSが適応されない」という事実は今後もアップデートされることはなく、Microsoftも動作保証の観点から別のブラウザへの乗り換えを推奨している。
そこで、IE Busterで表示されるデフォルトテキストもセキュリティリスクの訴求から動作保証に関する文言に修正する。
package.json
の exports
定義を使うと他のファイルにアクセスできなくなるようで、ドキュメントサイトへのバージョン表記などに支障が出たため、一旦削除。
"exports" を定義することで、パッケージのサブパスはすべて隠蔽されます。"exports" に記載のないパスを指定して import しようとすると、ERR_PACKAGE_PATH_NOT_EXPORTED エラーが発生するようになります。これはユーザーに本来使われることを意図していないファイルを隠蔽するのに役立ちます。
使いこなせばwebpackの動作に貢献できそうだった。main
と module
書いてるし、無くしても大丈夫かなと。
exports
がnpmの内部モジュールを参照できないようになったという話も見かけたが、この件とは関係ない?そもそも、npmのドキュメントに exports
の項目が無くよくわからない。
v2を開発中とのことで、表題の件をご提案いたします。
<script nomodule>
を利用した場合、モダンブラウザではそのスクリプトを読み込みません。これを利用して、IEを含むレガシーなブラウザでのみ IE Buster を読み込ませることで、実質的に軽量化となります。
https://developer.mozilla.org/ja/docs/Web/HTML/Element/script#attr-nomodule
https://caniuse.com/mdn-html_elements_script_nomodule
下記の通り懸念点もありますが、ご検討いただけますでしょうか。
<script nomodule src="ie-buster.js"></script>
import
などで組み込むと効果がないので、CDNを利用するのがベストだと思います。
モダンブラウザの場合、スクリプトが読み込まれず ieBuster
関数は存在しません。なので、Option設定時の方法を変更する必要があります。
<!-- 案1: 存在チェック -->
<script nomodule src="ie-buster.js"></script>
<script>
typeof ieBuster === 'function' && ieBuster({
mainText: "...",
linkText: "...",
linkUrl: "..."
})
</script>
<!-- 案2: html内で記述するよう変更する -->
<script
nomodule
src="ie-buster.js"
id="ie-buster-script"
data-main-text="..."
data-link-text="..."
data-link-url="..."
></script>
案2の方は、下記に仮実装がありますので、ご参考になれば幸いです。
https://github.com/iMasanari/ie-buster/blob/use-nomodule/src/app/ie-buster.js
とかが気になったので、もしよろしければ動的に文言が書き換えられるようになったらいいなと思ってます。
開発機運の高まりを感じ、2年半振りにIE Busterを書き直してみることに。
MicrosoftはIE非推奨を打ち出し、Edgeへの転送を開始。この情勢の変化もあってか、仕事でIE対応することはほぼなくなったので、IE Busterのv2アップデートを最後のIE対応にしたいところ。
フロントエンド開発向けに設計を一新💥
2018.01-02 (v1リリース当時) | 2021.01-02 (v2リリース予定) |
---|---|
![]() |
![]() |
日本のブラウザシェアでも直近でIE8〜10が使われている様子はないので、対象ブラウザをIE11に限定した書き方に変更(そもそもIE8〜10で検証する環境自体用意できない...)。動作環境をIE11に限定することで、見送ってしまった書き方が可能に。
Floatと差し替え。
ユーザーオプションとのマージを効率化。
JavaScriptを読み込んだ時点で window.onload
実行していたが、カスタマイズや実行タイミングの調整などを考え設計を変更。任意のタイミングで初期化して呼び出せるようにした。
ieBuster.init()
// 通常の実行:IE検出をしてポップアップ表示
ieBuster.init()
// IE検出のみ:付随する処理を同時に行う場合に使う
ieBuster.check()
// ポップアップ表示のみ:IE検出を含まない
ieBuster.create()
// ポップアップの削除
ieBuster.clear()
付与するID、挿入先のセレクター、別タブで開くかどうか、付与するCSSの設定をオプションに渡して反映させられるよう強化。CSSはオブジェクトで必要な変更点を指定することでデフォルトスタイルとマージして表示可能。
ieBuster.init({
appId: "your-custom-id",
mainText: "ご利用の Internet Explorer は推奨環境ではありません。最新の Firefox を推奨します。",
linkText: "Download",
linkUrl: "https://www.mozilla.org/ja/firefox/new/",
linkNewTab: false,
appStyles: { top: "auto", bottom: "0" },
cardStyles: { maxWidth: "540px", borderRadius: "8px" },
textStyles: { fontWeight: "700" },
linkStyles: { background: "purple", borderRadius: "4px" },
})
// ※別タブで開く設定は強制的にオフとなる
ieBuster.init(
{
linkUrl: "microsoft-edge:https://example.com"
}
)
IE BusterのWordPressプラグイン版で「インストール済みのEdgeで開かせたい」という要望があり対応。その際、target="_blank"
では空白タブが生まれて良くない状態だったため、URLのプロトコルをチェックして target="_self"
に切り替わるようにした。JS版にも同様の機能を付与。
dist/ie-buster.js
)dist/ie-buster.min.js
)dist/ie-buster.common.js
)dist/ie-buster.es.js
)TypeScriptプロジェクトで npm install
した場合に型定義を提供。
innerHTML
ではなく innerText
で挿入するよう変更innerHTML
ではなく encodeURI
で挿入するよう変更<head>
<script src="ie-buster.min.js"></script>
<script>
window.onload = function () {
ieBuster.init()
}
</script>
</head>
dev-v2 にて開発。 master にマージ。
容量がバージョンを重ねるごとに1〜2KBで上下している。v1.1.0では1.7KBになりそうだが、書き方によっては軽くなるだろう。
どちらにせよ軽量なことには変わりなく、新機能・改善・見通しの良いコードの採用を容量基準で判断したくはない(5KBを超えるようであれば太り過ぎだと思うけど...)。
数字を提示することは軽量さを伝える上で有効ではあるものの、アップデートの多い現段階では単純に「軽量」としておきたい。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.