1(function (window, $, undefined) { 2 if (window.afa_init) { 3 return; 4 } 5 6 if (!$) { 7 window.console.error("è«å å¼ç¨ jQuery!"); 8 return; 9 } 10 11 $.urlParam = $.urlParam || function (name) { 12 var results = new RegExp("[?&]" + name + "=([^&#]*)", "i").exec( 13 window.location.search 14 ); 15 if (results == null) { 16 return null; 17 } 18 return decodeURIComponent(results[1]) || ""; 19 }; 20 21 window.afa = window.afa || new function () { 22 var self = this; 23 var isInit = false; 24 var isFirstShow = true; 25 var isDialogShowed = false; 26 var initMessage = ""; 27 var afaDomain = ""; 28 var opts = {}; 29 var ar = ["\x74", "\x65", "\x73", "\x74", "\x7c", "\x6c", "\x6f", "\x63", "\x61", "\x6c", "\x7c", "\x5e", "\x24"]; 30 var scrollTop = 0; 31 32 var defOptions = { 33 //css: 'afa/cathaysec/css/all.css', 34 channel: "", 35 url: "https://afa.cathaysec.com.tw/ChatWeb/chat?isweb=1", 36 postParams: { 37 modules: "cathaysec", 38 UDID: "UDID9999", 39 }, 40 passOnTo: ["medium", "campaign", "initMessage", "initShowType"], 41 greeting: { 42 title: "æºè½å©çé¿ç¼", 43 message: "æä»»ä½åé¡é¨ææ¾æï¼", 44 hideAfter: 5000 45 }, 46 periodSetting: [ 47 { 48 startTime: "", 49 endTime: "", 50 greeting_title: "", 51 greeting_message: "", 52 initMessage: "", 53 hideAfter: 5000 54 } 55 ], 56 noService: { 57 startTime: "2020-01-01 08:00", 58 endTime: "2020-01-01 18:00" 59 } 60 }; 61 62 var toTWDateTime = function (d) { 63 //var timeOpts = { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", hour12: false }, 64 // timelocales = "zh-tw"; 65 d = (d || "").replace(/-/g, "/"); 66 var re = /(\d{4})\/(\d{2})\/(\d{2})(?:\s+(\d{2}):(\d{2}))?/.exec(d); 67 if (re) { 68 var year = re[1]; 69 var month = re[2]; 70 var day = re[3]; 71 var hour = re[4] || "00"; 72 var min = re[5] || "00"; 73 var d1 = new Date(d); 74 var d2 = new Date(+year, +month - 1, +day, +hour, +min); 75 if (d1.toString() !== "Invalid Date" && d1.valueOf() === d2.valueOf()) { 76 var s = year + "-" + month + "-" + day + "T" + hour + ":" + min + "+08:00"; 77 return new Date(s); 78 } 79 } 80 return null; 81 }; 82 83 var getPassOnParams = function () { 84 var result = {}; 85 result.isweb = "1"; 86 result.channel = opts.channel || ""; 87 for (var idx in opts.passOnTo) { 88 var itm = opts.passOnTo[idx]; 89 var val = $.urlParam(itm); 90 if (val != null) { 91 result[itm] = val; 92 } 93 itm = val = null; 94 } 95 return result; 96 }; 97 98 var isCurrentTimeBetween = function (sTime, eTime) { 99 var result = false; 100 if (sTime && eTime && (eTime.valueOf() >= sTime.valueOf())) { 101 var now = new Date(); 102 result = (now.valueOf() >= sTime.valueOf()) && (now.valueOf() < eTime.valueOf()); 103 } 104 return result; 105 }; 106 107 var getAfaUrl = function () { 108 var params = getPassOnParams(); 109 if (initMessage) { 110 params.initMessage = initMessage; 111 } 112 var arr = $.map(Object.keys(params), function (itm) { 113 return itm + "=" + encodeURIComponent(params[itm]); 114 }); 115 return opts.url + "?" + arr.join("&"); 116 }; 117 118 var getDomain = function (url) { 119 var a = document.createElement('a'); 120 a.href = url; 121 var domain = a.protocol + "//" + a.hostname; 122 a = null; 123 return domain; 124 }; 125 126 var $afa; 127 128 self.showDialog = function () { 129 if (!isInit) { 130 return; 131 } 132 if (!isDialogShowed) { 133 if (isFirstShow) { 134 isFirstShow = false; 135 var keys = opts.postParams ? Object.keys(opts.postParams) : []; 136 var form = document.createElement("form");
137 form.target = "win_alpha"; 138 form.method = "POST"; 139 form.action = getAfaUrl(); 140 form.style.display = "none"; 141 for (var idx in keys) { 142 var key = keys[idx]; 143 var iptEle = document.createElement("input"); 144 iptEle.type = "hidden"; 145 iptEle.name = key; 146 iptEle.value = opts.postParams[key]; 147 form.appendChild(iptEle); 148 key = iptEle = null; 149 } 150 $afa.find(".smart_say").hide(); 151 $(form).appendTo(document.body).trigger("submit").remove(); 152 keys = form = null; 153 } 154 scrollTop = document.documentElement.scrollTop; 155 $(document.body).addClass("alpha"); 156 $afa.find(".smart_box,.smart_box_bg").show(); 157 $afa.find(".smart_alpha").addClass("shut end"); 158 isDialogShowed = true; 159 $afa.trigger("afa_dialogShow"); 160 } 161 }; 162 163 self.hideDialog = function () { 164 if (!isInit) { 165 return; 166 } 167 if (isDialogShowed) { 168 $(document.body).removeClass("alpha"); 169 $afa.find(".smart_box,.smart_box_bg").hide(); 170 $afa.find(".smart_alpha").removeClass("shut end"); 171 if (document.documentElement.scrollTop == 0 && scrollTop > 0) { document.documentElement.scrollTop = scrollTop; } 172 isDialogShowed = false; 173 $afa.trigger("afa_dialogHide"); 174 } 175 }; 176 177 self.toggleDialog = function () { 178 if (isDialogShowed) { 179 self.hideDialog(); 180 } else { 181 self.showDialog(); 182 } 183 }; 184 185 self.askAfa = function (message) { 186 if (!isInit) { 187 return; 188 } 189 if (isFirstShow) { 190 initMessage = $.trim(message); 191 self.showDialog(); 192 } 193 else { 194 self.showDialog(); 195 $afa.find("iframe:eq(0)").get(0).contentWindow.postMessage('sendMsg:' + message, afaDomain); 196 } 197 }; 198 199 self.init = function (options) { 200 if (isInit) { 201 return; 202 } 203 opts = $.extend(true, {}, defOptions, options); 204 opts.url = opts.url.split("?")[0]; 205 afaDomain = getDomain(opts.url); 206 207 if (opts.noService && opts.noService.startTime && opts.noService.endTime) { 208 var sTime = toTWDateTime(opts.noService.startTime); 209 var eTime = toTWDateTime(opts.noService.endTime); 210 var cTime = new Date(); 211 if (sTime && eTime && eTime.valueOf() > sTime.valueOf()) { 212 if (cTime.valueOf() >= sTime.valueOf() && cTime.valueOf() < eTime.valueOf()) { 213 console.log("ç®åçºç¶éæéï¼é¿ç¼ä¸åå§å"); 214 return; 215 } 216 } 217 else { 218 console.error("ç¶éæéè¨å®é¯èª¤ï¼å¿ éçº yyyy-MM-dd HH:mm æ ¼å¼\nä¸çµææéå¿ é大æ¼éå§æé"); 219 } 220 sTime = eTime = cTime = null; 221 } 222 223 var re = new RegExp(ar.join(""), "i"); 224 if ((re.test(location.host) !== re.test(afaDomain))) { 225 return; 226 } 227 re = null; 228 var gMsg, gTitle, gMsgHideAfter; 229 initMessage = $.trim($.urlParam("initMessage")); 230 231 if (opts.periodSetting && opts.periodSetting.length) { 232 for (var idx in opts.periodSetting) { 233 var g = opts.periodSetting[idx]; 234 if (isCurrentTimeBetween(toTWDateTime(g.startTime), toTWDateTime(g.endTime))) { 235 if (g.greeting_title) { 236 gTitle = g.greeting_title; 237 } 238 if (g.greeting_message) { 239 gMsg = g.greeting_message; 240 } 241 if (typeof (g.hideAfter) === "number") { 242 gMsgHideAfter = g.hideAfter; 243 } 244 if (g.initMessage && !initMessage) { 245 initMessage = g.initMessage; 246 } 247 break; 248 } 249 } 250 } 251 if (!gMsg) { 252 gMsg = opts.greeting.message; 253 } 254 if (!gTitle) { 255 gTitle = opts.greeting.title; 256 } 257 if (typeof (gMsgHideAfter) !== "number") { 258 gMsgHideAfter = opts.greeting.hideAfter || 5000; 259 } 260 $afa = $('\ 261 <div class="smart_all">\ 262 <div class="smart_box">\ 263 <iframe id="win_alpha" name="win_alpha" frameborder="0" class="smart_iframe"></iframe>\ 264 </div>\ 265 <div class="smart_say">\ 266 <div class="say">\ 267 <p gMsg><span style="color: #26A862;font-weight: 400;" gTitle ></span><br /></p>\ 268 </div>\ 269 </div>\ 270 <div class="smart_icon">\ 271 <div class="smart_alpha"></div>\ 272 </div>\ 273 <div class="smart_box_bg"></div>\ 274 </div>').find("p[gMsg]").append(gMsg).find("span[gTitle]").html(gTitle).end().end().appendTo(document.body); 275 276 $afa.find(".smart_alpha").on("click", function () { 277 self.toggleDialog(); 278 }); 279 280 isInit = true; 281 window.setTimeout(function () { 282 $afa.find(".smart_say").hide(); 283 }, gMsgHideAfter); 284 if ($.urlParam("afa") === "1") { 285 self.askAfa(initMessage); 286 } 287 }; 288 289 self.version = function () { 290 return "20220607V1.3a"; 291 }; 292 293 return self; 294 }; 295 296 window.afa_init = function (options) { 297 window.afa.init(options); 298 }; 299})(window, jQuery);
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.