PageSourceSearch

https://www.e-myholiday.com/js/st5/cookies.js?1778223572

js e-myholiday.com collected 2026-10-02 05:54:33 UTC 4,403 bytes, 138 lines download raw bytes

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.