1import { detect } from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm' 2/** 3 * @class Version 4 * @description ããã¤ã¹æ å ±ãå¤å®ããå¦ç (Detect device and browser information) 5 * 6 * @example 7 * import { Version } from 'path/to/components/Version'; 8 * const version = new Version(); 9 * console.log(version.isSP); // true if smartphone 10 */ 11 export class Version { 12 constructor() { 13 const browserInfo = detect(); 14 // User-Agent ãåå¾ 15 this.ua = window.navigator.userAgent; 16 // ãã©ã¦ã¶åãåå¾ ('chrome', 'firefox', 'safari', 'edge', 'ie', 'ios', ...) 17 this.browserName = browserInfo.name; 18 // OS åãåå¾ ('Windows 10', 'Android OS', 'iOS', ...) 19 this.detectOS = browserInfo.os; 20 // body è¦ç´ ã¸ã®åç § 21 this.bodyElm = document.querySelector('body'); 22 // SPï¼ã¹ããï¼ å¤å®ãã©ã° 23 this.isSP = false; 24 25 // åæå¦ç 26 this.eventHandler(); 27 } 28 29 /** 30 * åæå¦ç: SP å¤å®ã¨ã¯ã©ã¹ä»ä¸ 31 */ 32 eventHandler() { 33 this.onJudgeSP(); 34 this.handleAddClass(); 35 } 36 37 /** 38 * ã¹ãã¼ããã©ã³ãã©ããå¤å¥ã㦠isSP ã«ã»ãã 39 */ 40 onJudgeSP() { 41 switch (this.detectOS) { 42 case 'Android OS': 43 case 'iOS': 44 case 'Windows Mobile': 45 case 'BlackBerry OS': 46 this.isSP = true; 47 break; 48 default: 49 this.isSP = false; 50 } 51 } 52 53 /** 54 * body è¦ç´ ã«ãã©ã¦ã¶åã isSP ã¯ã©ã¹ãä»ä¸ 55 */ 56 handleAddClass() { 57 if (!this.bodyElm) return; 58 59 // ã¢ãã³ãã©ã¦ã¶åºæã®ã¯ã©ã¹ä»ä¸ 60 switch (this.browserName) { 61 case 'ie': 62 case 'edge': 63 case 'firefox': 64 this.bodyElm.classList.add(this.browserName); 65 break; 66 case 'safari': 67 case 'ios': 68 this.bodyElm.classList.add('safari'); 69 break; 70 default: 71 // ãã®ä»ã®ãã©ã¦ã¶ã¯ä½ãããªã 72 break; 73 } 74 75 // SP å¤å®ã¯ã©ã¹ 76 if (this.isSP) { 77 this.bodyElm.classList.add('isSP'); 78 } 79 } 80}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.