1"use strict"; 2 3/** 4 * ã¯ããã¼ãè¨å®ãã颿° 5 * @param {string} name - ã¯ããã¼å 6 * @param {string} value - ã¯ããã¼ã«ä¿åããæååï¼UTF-8æ³å®ï¼ 7 * @param {number} [days] - æå¹æé(æ¥æ°) 8 * @param {string} [path="/"] - ã¯ããã¼ã®ãã¹ 9 * @param {string} [domain=""] - ã¯ããã¼ã®ãã¡ã¤ã³ 10 */ 11function setCookie(name, value, days = 7, path = "/", domain = "") { 12 // å¤ã null ã¾ã㯠undefined ã®å ´åã¯ã¹ããã 13 if (value === null || value === undefined) return; 14 15 // æå¹æéè¨å® 16 let expires; 17 const date = new Date(); 18 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 19 expires = `; expires=${date.toUTCString()}`; 20 21 // UTF-8æåå â Base64 ã«å¤æ 22 const encodedValue = utf8ToBase64(String(value)); // value ãæååã«å¤æ 23 24 // ã¯ããã¼æååã®çµã¿ç«ã¦ 25 let cookieString = `${name}=${encodedValue}${expires}; path=${path}`; 26 if (domain) { 27 cookieString += `; domain=${domain}`; 28 } 29 30 // ã¯ããã¼è¨å® 31 document.cookie = cookieString; 32} 33 34/** 35 * ã¯ããã¼ãåå¾ãã颿° 36 * @param {string} name - åå¾ãããã¯ããã¼å 37 * @returns {string|null} - ã¯ããã¼ã®å¤ï¼UTF-8ãã³ã¼ãå¾ï¼ãè¦ã¤ãããªãå ´åã¯null 38 */ 39function getCookie(name) { 40 // æ£è¦è¡¨ç¾ãç¨ãã¦ã¯ããã¼æååãã該å½é¨åãæ½åº 41 const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`)); 42 if (match) { 43 // Base64 â UTF-8æååã«ãã³ã¼ã 44 return base64ToUtf8(match[1]); 45 } 46 return null; 47} 48 49// noinspection JSUnusedGlobalSymbols 50/** 51 * ã¯ããã¼ãåé¤ãã颿° 52 * @param {string} name - åé¤ããã¯ããã¼å 53 * @param {string} [path="/"] - ã¯ããã¼ã®ãã¹ 54 * @param {string} [domain=""] - ã¯ããã¼ã®ãã¡ã¤ã³ 55 */ 56function deleteCookie(name, path = "/", domain = "") { 57 // æå¹æéãé廿¥ã«è¨å®ããã°ã¯ããã¼ãåé¤ããã 58 let cookieString = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=${path}`; 59 if (domain) { 60 cookieString += `; domain=${domain}`; 61 } 62 document.cookie = cookieString; 63} 64 65/** 66 * UTF-8æååãBase64æååã«ã¨ã³ã³ã¼ããã颿° 67 * @param {string} str - UTF-8æåå 68 * @returns {string} - Base64ã¨ã³ã³ã¼ãå¾ã®æåå 69 */ 70function utf8ToBase64(str) { 71 const utf8Bytes = new TextEncoder().encode(str); 72 let binary = ""; 73 for (let i = 0; i < utf8Bytes.length; i++) { 74 binary += String.fromCharCode(utf8Bytes[i]); 75 } 76 return btoa(binary); 77} 78 79/** 80 * Base64æååãUTF-8æååã«ãã³ã¼ããã颿° 81 * @param {string} base64 - Base64æåå 82 * @returns {string} - UTF-8æåå 83 */ 84function base64ToUtf8(base64) { 85 try { 86 const binary = atob(decodeURIComponent(base64)); 87 const bytes = new Uint8Array(binary.length); 88 for (let i = 0; i < binary.length; i++) { 89 bytes[i] = binary.charCodeAt(i); 90 } 91 return new TextDecoder().decode(bytes); 92 } catch (e) { 93 console.error('Base64 decode failed:', base64, e); 94 return ''; 95 } 96} 97 98/** 99 * ãã©ã¤ãèå¥ãã¼ãçæããï¼ä¹ãç¶ã便ã¯å ¨åºéã® bincd ã ':' ã§çµåï¼ 100 * PHPå´ã® TourUtil::getFlightKey() ã¨åä¸ãã¸ãã¯ã 101 * 102 * ç´è¡ä¾¿: "ANA1767" 103 * 1ä¹ãç¶ã: "ANA761:ANA2443" 104 * 2ä¹ãç¶ã: "ANA761:ANA2443:ANA1234" 105 * 106 * @param {Object} flight - ãã©ã¤ããã¼ã¿ãªãã¸ã§ã¯ã 107 * @returns {string} 108 */ 109function getFlightKey(flight) { 110 let key = flight.bincd || ''; 111 const via1 = flight.air_via1 && flight.air_via1[0]; 112 if (via1 && via1.bincd) { 113 key += ':' + via1.bincd; 114 const via2 = via1.air_via2 && via1.air_via2[0]; 115 if (via2 && via2.bincd) { 116 key += ':' + via2.bincd; 117 } 118 } 119 return key; 120} 121 122/** 123 * ã¯ããã¼ã®å¤ããã¨ã«ç¾å¨ã®URLã«ã¯ã¨ãªãã©ã¡ã¼ã¿ã追å ããURLãè¿ã 124 * @param {Array<[string, string]>} cookieKeys - [ [cookieå, ã¯ã¨ãªå], ... ] 125 * @returns {string} 126 */ 127function getUpdatedUrlWithCookies(cookieKeys) { 128 const params = new URLSearchParams(window.location.search); 129 cookieKeys.forEach(([cookieKey, paramKey]) => { 130 const value = getCookie(cookieKey); 131 if (value) { 132 params.set(paramKey, value); 133 } 134 }); 135 const newUrl = window.location.pathname + '?' + params.toString(); 136 history.pushState(null, '', newUrl);//ãã©ã¦ã¶ã®URLæ´æ° 137 return newUrl; 138}
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.