PageSourceSearch

https://www.fly168.com.tw/Scripts/member/marketing-page.js?t=639263853567452944

js fly168.com.tw collected 2026-10-05 22:26:18 UTC 4,520 bytes, 114 lines download raw bytes

1document.addEventListener("DOMContentLoaded", function () {
2    //解析JSON
3    function parseJSONSafely(jsonString) {
4        let parsedObject = null;
5        try {
6            parsedObject = JSON.parse(jsonString);
7        } catch (e) { }
8        return parsedObject;
9    }
10
11    //設定對話視窗
12    function setMarketingModel() {
13        // 防止 script 被多次載入導致出現重複視窗
14        if (document.querySelector('[data-rel="member-marketing-check"]')) {
15            return;
16        }
17        // 加入css
18        const css = `
19            .modal-overlay{
20                position:fixed;
21                inset:0;
22                background:rgba(0,0,0,0.5);
23                display:flex;
24                align-items:center;
25                justify-content:center;
26                z-index:99999;
27            }
28        `;
29        const style = document.createElement('style');
30        style.textContent = css;
31        document.head.appendChild(style);
32
33        // 建立modal結構
34        const overlay = document.createElement('div');
35        overlay.className = 'modal-overlay';
36        overlay.innerHTML = `
37        <div class="container">
38            <div class="row justify-content-center">
39                <div class="col-md-7 col-12">
40                    <div class="card shadow" data-rel="member-marketing-check">
41                        <div class="card-body">
42                            <h5 class="card-title text-center mb-4">個資保護法政策</h5>
43                            <p class="card-text text-center">
44                                配合個資保護法政策,請您選擇是否訂閱最新資訊,以掌握優惠、活動與重要公告。<br>
45                                您也可以隨時登入會員資料編輯頁面,更新個人資料或調整此訂閱選項。
46                            </p>
47                            <div class="text-center">
48                                <button id="btnMarketingNo" type="button" data-type="false" class="btn btn-danger">
49                                    <i class="fa fa-times">&nbsp;</i>暫不需要
50                                </button>
51                                <button id="btnMarketingYes" type="button" data-type="true" class="btn btn-success">
52                                    <i class="fa fa-check">&nbsp;</i>同意接收
53                                </button>
54                            </div>
55                        </div>
56                    </div>
57                </div>
58            </div>
59        </div>
60        `;
61
62        // 加入到body
63        document.body.appendChild(overlay);
64
65        // 按鈕事件
66        overlay.addEventListener('click', e => {
67            if (!e.target.closest('[data-rel="member-marketing-check"]')) {
68                overlay.remove();
69            }
70        });
71
72        $("#btnMarketingNo, #btnMarketingYes").on('click', function (e) {
73            const type = $(this).data('type');
74            $.ajax({
75                url: '/api/member/setmembermarketing',
76                type: 'POST',
77                data: { marketing: type }
78            }).always(() => {
79                sessionStorage.setItem("marketingInfo", JSON.stringify({ userid: aesUserId, check: false }));
80            });
81            overlay.remove();
82        });
83    }
84
85
86    const aesUserId = sessionStorage.getItem("aesUserId");
87    let mInfo = parseJSONSafely(sessionStorage.getItem("marketingInfo"));
88    //抓取sessionStorage防止大量讀取
89    if (mInfo != null && mInfo.userid === aesUserId) {
90        if (mInfo.check === true) {
91            setMarketingModel();
92        }
93    } else {
94        $.ajax({
95            url: '/api/member/getmarketinginfo',
96            type: 'GET',
97            success: function (result) {
98                mInfo = parseJSONSafely(result);
99                if (mInfo != null) {
100                    if (mInfo.check === true) {
101                        setMarketingModel();
102                    }
103                    sessionStorage.setItem("marketingInfo", result);
104                    sessionStorage.setItem("aesUserId", mInfo.userid);
105                }
106            }
107        }).always(() => {
108            //未登入處理
109            if (sessionStorage.getItem("aesUserId") === null) {
110                sessionStorage.setItem("marketingInfo", JSON.stringify({ userid: null, check: false }));
111            }
112        });
113    }
114});

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.