PageSourceSearch

https://e123.hk/modules/custom/olink_auth_login/assets/global/js/olink_auth_login.js?v=3&v=1

js e123.hk collected 2026-10-01 12:23:34 UTC 7,954 bytes, 191 lines download raw bytes

1jQuery(function ($) {
2    var olink_domain = $.trim($("body").attr("olink-base-url"));
3    var olink_domain_display_only = $.trim($("body").attr("olink-base-url-display-only"));
4
5    $(document).ready(function () {
6        // Header
7        if ($(".olink-visit-text").length > 0) {
8            if (olink_domain_display_only !== "") {
9                $(".olink-visit-text").find("a").attr("href", olink_domain_display_only);
10            } else {
11                $(".olink-visit-text").closest(".olink-visit-wrapper").addClass("d-none");
12            }
13        }
14        // Register Page
15        if ($("#user-register-form").length > 0) {
16            if ((olink_auth_login_getUrlParameter('s_source') !== undefined)) {
17                let _s_source = olink_auth_login_getUrlParameter('s_source');
18                if (_s_source == "olink") {
19                    if (sessionStorage.getItem("s_source") === null) {
20                        sessionStorage.setItem("s_source", _s_source);
21
22                        // Other params
23                        // ?apply_olink_caregiver=1  (from olink)
24                        let _apply_olink_caregiver = olink_auth_login_getUrlParameter('apply_olink_caregiver');
25                        if (_apply_olink_caregiver !== undefined) {
26                            // delay 1 second
27                            setTimeout(() => {
28                            // Set checkbox #edit-field-is-olink-caregiver-value
29                            $("#edit-field-is-olink-caregiver-value").prop("checked", true);
30                                // Show the text after the .js-form-item-field-is-olink-caregiver-value
31                                let msg = "申請成功後,同時成為「傲齡匯 照顧者」。";
32                                $(".js-form-item-field-is-olink-caregiver-value").after("<div class='form-item olink-caregiver-text'>" + msg + "</div>");
33                            }, 2000)
34                        }
35                    } else {
36                        sessionStorage.removeItem("s_source");
37                    }
38                }
39            }
40        }
41
42        // Home Page
43        if (drupalSettings.path.currentPath == "node/1") {
44            if (drupalSettings.user.uid > 0) {
45                if (sessionStorage.getItem("s_source") !== null) {
46                    sessionStorage.removeItem("s_source");
47
48                    setTimeout(() => {
49                        window.location.href = olink_domain;
50                    }, 200)
51                }
52            }
53        }
54
55
56        if (olink_domain != "") {
57            // Save the olink_token_key to sessionStorage if ?olink_login_token is existing
58            if (olink_auth_login_getUrlParameter('olink_login_token') !== undefined) {
59                let _token = olink_auth_login_getUrlParameter('olink_login_token');
60                sessionStorage.setItem("olink_login_token", _token);
61
62                let _olink_dest = olink_auth_login_getUrlParameter('dest');
63
64                sessionStorage.setItem("olink_dest", _olink_dest);
65                // sessionStorage.setItem("_debug_url", window.location.pathname + document.location.search);
66
67
68                // Redirect
69                setTimeout(() => {
70                    if (drupalSettings.user.uid == 0) {
71                        // redirect to 
72                        window.location.replace("/user/login");
73                    } else {
74                        window.location.replace("/user");
75                    }
76                }, 200)
77
78                $("body").addClass("for_login_only");
79            } else {
80                $("body").removeClass("for_login_only");
81            }
82        }
83    })
84
85
86    $(document).ready(function () {
87        if (olink_domain != "") {
88            if ((sessionStorage.getItem("olink_login_token") !== null)) {
89                $("body").addClass("for_login_only");
90
91                if (($("#user-login-form #edit-name").length) > 0) {
92                    $("#user-login-form #edit-name").focus();
93                }
94            } else {
95                $("body").removeClass("for_login_only");
96            }
97
98
99            if ($(".olink-login-auth-wrapper").length > 0) {
100                // alert("0101 olink-login-auth-wrapper is existing");
101                // alert("0102 olink_login_token is existing in sessionStorage" + sessionStorage.getItem("olink_login_token"));
102
103                if ((sessionStorage.getItem("olink_login_token") !== null)) {
104                    $(".olink-login-auth-wrapper").html("正在連結到「傲齡匯」...");
105                    $(".olink-login-auth-wrapper").removeClass("d-none");
106
107
108                    let existing_token = sessionStorage.getItem("olink_login_token");
109                    // sessionStorage.removeItem("olink_login_token");
110
111                    let olink_dest = sessionStorage.getItem("olink_dest");
112                    // sessionStorage.removeItem("olink_dest");
113
114
115                    // Redirect to {{ olink_site }}   /e123_auth_succ
116                    // ?uid=xxx&
117                    // &uuid=xxxxxx
118                    // &name=xxxxxxx
119                    // &olink_login_token=xxxxxxxxxxx    (<- from sessionStorage)
120
121                    if ((drupalSettings.user.uid) > 0) {
122                        sessionStorage.removeItem("olink_login_token");
123                        sessionStorage.removeItem("olink_dest");
124
125                        $.ajax({
126                            url: "/current-user-info/?_format=json",
127                            cache: false,
128                            method: "GET",
129                            headers: { "Accept": "application/json", "Content-Type": "application/json" },
130                            beforeSend: function () {
131
132                            },
133                            success: function (data, status, xhr) {
134                                setTimeout(() => {
135                                    var _url = "";
136
137                                    data[0]['olink_token'] = existing_token;
138                                    data[0]['olink_dest'] = olink_dest;
139
140                                    var d = JSON.stringify(data);
141
142                                    // _url += olink_domain + "e123_auth_succ?d=" + btoa(encodeURIComponent(d));
143                                    _url += olink_domain + "e123_auth_succ?d=" + ohexEncode(encodeURIComponent(d));
144                                    // _url += olink_domain + "e123_auth_succ?d=" + (encodeURIComponent(d));
145
146
147                                    // Redirect to Olink
148                                    if (olink_domain != "") {
149                                        window.location.replace(_url);
150                                    }
151                                }, 200)
152                            },
153                            error: function (data) { },
154                        })
155                    }
156                } else {
157                    // $("body").removeClass("for_login_only");
158                }
159            }
160
161
162            if (($(".to-olink-logout-page").length) > 0) {
163                $("body").addClass("for_login_only");
164            }
165        }
166    })
167
168    function ohexEncode(str) {
169        return str.split('').map(char => char.charCodeAt(0).toString(16).padStart(2, '0')).join('');
170    }
171
172    function ohexDecode(hex) {
173        return hex.match(/.{1,2}/g).map(byte => String.fromCharCode(parseInt(byte, 16))).join('');
174    }
175
176
177    function olink_auth_login_getUrlParameter(sParam) {
178        var sPageURL = window.location.search.substring(1),
179            sURLVariables = sPageURL.split('&'),
180            sParameterName,
181            i;
182
183        for (i = 0; i < sURLVariables.length; i++) {
184            sParameterName = sURLVariables[i].split('=');
185
186            if (sParameterName[0] === sParam) {
187                return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
188            }
189        }
190    };
191});

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.