1const langList = [ 2 // "CN", 3 "EN", 4 "DE", 5 "ES", 6 "FR", 7 "ID", 8 "IT", 9 "JP", 10 "KO", 11 "PT", 12 "CH", // ç¹ä½ï¼å¯¹åºpc 13 "RU", 14]; 15const NOTICE_URL_ONLINE = { 16 edraw_config: "https://www.edraw.ai/notify/config.json", 17 edraw_dialog: "https://www.edraw.ai/notify/dialog.html", 18 edraw_notice: "https://www.edraw.ai/notify/notice.html", 19 edraw_home: "https://www.edraw.ai/app/aipower", 20 mind_config: "https://www.edrawmind.com/notify/config.json", 21 mind_dialog: "https://www.edrawmind.com/notify/dialog.html", 22 mind_notice: "https://www.edrawmind.com/notify/notice.html", 23 mind_home: "https://www.edrawmind.com/app/create", 24}; 25 26const NOTICE_URL_DEV = { 27 edraw_config: "https://dev-en.edraw.ai/app/js/config.json", 28 edraw_config_js: "https://www.edraw.ai/notify/test/config-test.js", 29 edraw_dialog: "https://www.edraw.ai/notify/test/dialog.html", 30 edraw_notice: "https://www.edraw.ai/notify/test/notice.html", 31 edraw_home: "http://dev-en.edraw.ai/app", 32 mind_config: "http://dev.master.com/app/assets/js/config.json", 33 mind_config_js: "https://www.edrawmind.com/notify/test/config-test.js", 34 mind_dialog: "https://www.edrawmind.com/notify/test/dialog.html", 35 mind_notice: "https://www.edrawmind.com/notify/test/notice.html", 36 mind_home: "http://dev.master.com/app/create/", 37}; 38 39 40let _OPEN = true; // 线ä¸ç¯å¢ å ¨å±å¼å ³ 41let _OPEN_DEV = true; // devç¯å¢ å ¨å±å¼å ³ 42let _IS_FIRST_SHOW = false; // 馿¬¡å±ç¤ºè®°å½æ è¯ 43// DEV 44let DEV_LOCAL; 45let NOTICE_URL; 46let _TIMER = { 47 _NOTICE: null, 48 _GLOBALAPI: null, 49 _FORCEOFF: null, 50 _REDIRECT: null 51}; 52let _CURRENT_DATA = null; 53let _KEY = ""; 54let _NOTICE_CACHE = []; 55let _NOTICE_TOAST = null; 56let lang; 57// ç¡®å®å¼ç¨ç¯å¢ 58let isEdrawAI; 59let isMind; 60// ç¡®å®æ¯é¦é¡µè¿æ¯ç¼è¾é¡µ 61let isEdrawEditor; 62let isMindEditor; 63let isEditor; 64 65function useNotice() { 66 // 夿OPEN 67 setEnv() 68 const open = DEV_LOCAL ? _OPEN_DEV : _OPEN; 69 70 const nowEditor = isEdrawAI ? location.href.includes("/master/") || location.href.includes("/max/") : location.href.includes("/editor/") 71 // ä»é¦é¡µè·³å°ç¼è¾é¡µ 72 const homeToEditor = !isEditor && nowEditor 73 // ä»ç¼è¾é¡µè·³å°é¦é¡µ 74 const editorTohome = isEditor && !nowEditor 75 const canStart = _IS_FIRST_SHOW ? homeToEditor : true 76 77 if (open && (homeToEditor || editorTohome)) { 78 clearTimer(); 79 setHomeEditor() 80 } 81 if (open && canStart) { 82 const iframeMask = document.getElementById("notice-iframe-mask"); 83 if (iframeMask) { 84 iframeMask.parentNode.removeChild(iframeMask); 85 } 86 87 setData(); 88 getJsonData(); 89 window.addEventListener("message", receiveMessage, false); 90 window.addEventListener("beforeunload", beforeUnload); 91 } else { 92 window.removeEventListener("message", receiveMessage, false); 93 window.removeEventListener("beforeunload", beforeUnload); 94 } 95 96 function receiveMessage(event) { 97 const receiveData = event.data; 98 const type = receiveData.type; 99 if (type === "close") { 100 removeIframe(receiveData.data); 101 if (isEditor) { 102 location.href = isEdrawAI ? 103 NOTICE_URL.edraw_home : 104 NOTICE_URL.mind_home; 105 } 106 } 107 }; 108 109 // ç¡®å®æ¶é´ 110 function getJsonData() { 111 if (DEV_LOCAL) { 112 const script = document.createElement("script"); 113 script.src = isEdrawAI ? NOTICE_URL.edraw_config_js : NOTICE_URL.mind_config_js 114 document.body.appendChild(script); 115 script.onload = () => { 116 success(window._NOTICE_CONFIG) 117 } 118 return 119 } 120 121 fetch(isEdrawAI ? NOTICE_URL.edraw_config : NOTICE_URL.mind_config) 122 .then((response) => response.json()) 123 .then((data) => { 124 success(data) 125 }) 126 .catch((err) => { 127 console.error(err); 128 }) 129 .finally(() => { 130 // const interval = (150 + Math.floor(60 * Math.random())) * 1000; 131 // setTimeout(getJsonData, interval); 132 }); 133 134 135 function success(data) { 136 let list = data || []; 137 138 if (isEdrawAI && isEdrawEditor) { 139 // EdrawAIç¼è¾é¡µ 140 setCurrentData(list); 141 } else if (isEdrawAI && !isEdrawEditor) { 142 // EdrawAIé¦é¡µ isEdrawAI && !isEdrawEditor 143 if (canShowAtHome(list)) insertIframe(); 144 } else if (isMind && isMindEditor) { 145 // Mindç¼è¾é¡µ 146 setCurrentData(list); 147 } else if (isMind && !isMindEditor) { 148 // Mindé¦é¡µ 149 if (canShowAtHome(list)) { 150 insertIframe(); 151 } 152 } 153 } 154 } 155 156 function setCurrentData(arr) { 157 // 便¬¡ä»æé«ä¼å 级å¼å§å¤æ 158 const isRedirectInTime = getDataByType(arr, "redirect") 159 if (isRedirectInTime) { 160 _CURRENT_DATA = isRedirectInTime 161 _NOTICE_CACHE.push(redirectPage); 162 } else if (!isEditor) { 163 _CURRENT_DATA = getDataByType(arr, "popover") 164 timeToRedirect() 165 } else { 166 const isOffInTime = getDataByType(arr, "forceOff") 167 const isToastInTime = getDataByType(arr, "notify") 168 169 if (isOffInTime) { 170 _CURRENT_DATA = isOffInTime; 171 _NOTICE_CACHE.push(forceOffPage); 172 timeToRedirect() 173 } else if (isToastInTime) { 174 _CURRENT_DATA = isToastInTime; 175 _NOTICE_CACHE.push(showToast); 176 // 强å¶ä¸çº¿å¼å§æ¶é´ - å½åæ¶é´ = å¼¹åºå¼ºå¶ä¸çº¿å¼¹çªé´é 177 const OffData = arr.filter((item) => item.type === "forceOff"); 178 const nowTime = new Date().getTime(); 179 const timeToOff = OffData.length ? 180 OffData[0].start_time * 1000 - nowTime : 181 0; 182 if (timeToOff > 0) { 183 _TIMER._FORCEOFF = setTimeout(() => { 184 _CURRENT_DATA = OffData[0]; 185 forceOffPage() 186 }, timeToOff); 187 } 188 } 189 } 190 watchGlobalApi(); 191 192 function timeToRedirect() { 193 // éå®åå¼å§æ¶é´ - å½åæ¶é´ = éå®å页é¢é´é 194 const RedirectData = arr.filter((item) => item.type === "redirect"); 195 const nowTime = new Date().getTime(); 196 const timeToOff = RedirectData.length ? 197 RedirectData[0].start_time * 1000 - nowTime : 198 0; 199 if (timeToOff > 0) { 200 _TIMER._REDIRECT = setTimeout(() => { 201 _CURRENT_DATA = RedirectData[0]; 202 redirectPage() 203 }, timeToOff); 204 } 205 } 206 } 207 208 function canShowAtHome(arr) { 209 setCurrentData(arr); 210 if (!_CURRENT_DATA) return false; 211 212 _KEY = `notice-${_CURRENT_DATA.interval}-${_CURRENT_DATA.start_time}`; 213 const value = localStorage.getItem(_KEY); 214 // ä» å±ç¤ºä¸æ¬¡ 215 if (!_CURRENT_DATA.interval) { 216 return value ? false : true; 217 } else { 218 const nowTime = new Date().getTime(); 219 // æå¼ && å½åæ¶é´å°äºè¿ææ¶é´ = ä¸å±ç¤º 220 if (value && nowTime < value) return false; 221 } 222 223 return true; 224 } 225 226 function getTodayEndTimes() { 227 // è·åä»å¤©çæ¥æ 228 const today = new Date(); 229 // 设置æ¶é´ä¸º23:59:59 230 today.setHours(23, 59, 59, 999); 231 const timestamp = Math.floor(today.getTime()); 232 return timestamp; 233 } 234 235 function insertIframe() { 236 const oldiframe = document.getElementById("notice-iframe"); 237 if (oldiframe) return; 238 239 // å建ä¸ä¸ª iframe å ç´ 240 const iframe = document.createElement("iframe"); 241 242 // 设置 iframe ç屿§ 243 iframe.src = isEdrawAI ? 244 NOTICE_URL.edraw_dialog : 245 NOTICE_URL.mind_dialog; 246 iframe.id = "notice-iframe"; // å¨æè®¾ç½® id 屿§ 247 iframe.style.position = "absolute"; 248 iframe.style.top = "50%"; 249 iframe.style.left = "50%"; 250 iframe.style.transform = "translate(-50%, -50%)"; 251 iframe.style.width = isEdrawAI ? "400px" : "432px"; 252 iframe.style.height = isEdrawAI ? "364px" : "350px"; 253 iframe.style.borderRadius = "8px"; 254 iframe.style.border = "none"; 255 256 const mask = document.createElement("div"); 257 mask.id = "notice-iframe-mask"; 258 mask.classList.add("ed-mask"); 259 mask.style.zIndex = "9999"; 260 mask.style.display = "none"; 261 iframe.style.boxShadow = "0px 15px 30px 0px rgba(0, 0, 0, 0.15)"; 262 263 // å° iframe æå ¥å° body ä¸ 264 mask.appendChild(iframe); 265 document.body.appendChild(mask); 266 267 iframe.addEventListener("load", function () { 268 mask.style.display = "block"; 269 // update lang 270 if (isMind) { 271 let l = 'en' 272 if (window.store) l = window.store.getters.currentLang 273 if (langList.includes(l.toUpperCase())) { 274 lang = l.toLowerCase() 275 } 276 } 277 iframe.contentWindow.postMessage({ 278 type: "content", 279 data: { 280 ..._CURRENT_DATA.message[lang], 281 icon_url: _CURRENT_DATA.icon_url, 282 editor: isEditor, 283 from: isEdrawAI ? "edrawai" : "mind", 284 showToday: !isEditor && _CURRENT_DATA.interval 285 }, 286 }, 287 "*" 288 ); 289 _TIMER._NOTICE && clearInterval(_TIMER._NOTICE); 290 if (!_IS_FIRST_SHOW && !isEditor) _IS_FIRST_SHOW = true 291 }); 292 } 293 294 function removeIframe(data) { 295 const { 296 today 297 } = data; 298 if (!isEditor) { 299 _TIMER._NOTICE && clearInterval(_TIMER._NOTICE); 300 // å¾é仿¥ä¸åæç¤º 301 if (today) { 302 const todayEnd = getTodayEndTimes(); 303 _KEY && localStorage.setItem(_KEY, todayEnd); 304 } else if (!_CURRENT_DATA.interval) { 305 // åªå±ç¤ºä¸æ¬¡ 306 _KEY && localStorage.setItem(_KEY, _CURRENT_DATA.end_time * 1000); 307 } else { 308 // éç½®å®æ¶å¨ 309 _TIMER._NOTICE = setInterval(() => { 310 insertIframe(); 311 }, _CURRENT_DATA.interval * 1000); 312 } 313 } 314 315 const iframeMask = document.getElementById("notice-iframe-mask"); 316 if (iframeMask) { 317 iframeMask.parentNode.removeChild(iframeMask); 318 } 319 } 320 321 function redirectPage() { 322 const url = isEdrawAI ? 323 NOTICE_URL.edraw_notice : 324 NOTICE_URL.mind_notice; 325 location.href = `${url}?lang=${lang}` 326 } 327 328 function forceOffPage() { 329 // å¼¹åºæ¶ä¿åæä»¶(max)ï¼ç¹å»ç¡®å®æ¶è¿åé¦é¡µ 330 const isMaxEditor = location.href.includes("/max/"); 331 if (isMaxEditor) { 332 window.globalApi.$bus.emit("savefile"); 333 } 334 insertIframe(); 335 } 336 337 function showToast() {
338 if (_NOTICE_TOAST) return 339 _NOTICE_TOAST = window.globalApi.$message({ 340 type: "warning", 341 showClose: true, 342 duration: 0, 343 message: _CURRENT_DATA.message[lang].body, 344 customClass: "ed_notice_toast" 345 }); 346 const mesDom = document.querySelectorAll(".ed_notice_toast") 347 if (mesDom && mesDom[0].style.display === "none") { 348 mesDom[0].style.display = "flex" 349 } 350 } 351 352 function watchGlobalApi() { 353 _TIMER._GLOBALAPI = setInterval(() => { 354 if (window.globalApi) { 355 _NOTICE_CACHE.forEach((fun) => fun()); 356 clearInterval(_TIMER._GLOBALAPI); 357 _TIMER._GLOBALAPI = null 358 _NOTICE_CACHE = []; 359 } 360 }, 1000); 361 } 362 363 function setData() { 364 setHomeEditor() 365 // DEV 366 NOTICE_URL = DEV_LOCAL ? NOTICE_URL_DEV : NOTICE_URL_ONLINE; 367 368 _TIMER = { 369 _NOTICE: null, 370 _GLOBALAPI: null, 371 _FORCEOFF: null, 372 _REDIRECT: null, 373 }; 374 _CURRENT_DATA = null; 375 _KEY = ""; 376 _NOTICE_CACHE = []; 377 378 // ç¡®å®è¯è¨ç¯å¢ 379 const params = new URL(document.location).searchParams; 380 const s_lang = params.get('lang') 381 lang = s_lang && langList.includes(s_lang.toUpperCase()) ? s_lang.toLowerCase() : 'en' 382 383 if (isMind) { 384 // mindè·åå¤è¯è¨ 385 _NOTICE_CACHE.push(setLangByStore) 386 } 387 } 388 389 function setLangByStore() { 390 // éè¦è°æ¥å£profileè·åï¼ç1s 391 setTimeout(() => { 392 let l = 'en' 393 if (window.store) l = window.store.getters.currentLang 394 if (langList.includes(l.toUpperCase())) { 395 lang = l.toLowerCase() 396 } 397 }, 1000) 398 } 399 400 function clearTimer() { 401 // æ¸ é¤å®æ¶å¨ 402 if (_TIMER._NOTICE) { 403 clearInterval(_TIMER._NOTICE); 404 _TIMER._NOTICE = null 405 } 406 if (_TIMER._GLOBALAPI) { 407 clearInterval(_TIMER._GLOBALAPI); 408 _TIMER._GLOBALAPI = null 409 } 410 if (_TIMER._FORCEOFF) { 411 clearInterval(_TIMER._FORCEOFF); 412 _TIMER._FORCEOFF = null 413 } 414 if (_TIMER._REDIRECT) { 415 clearInterval(_TIMER._REDIRECT); 416 _TIMER._REDIRECT = null 417 } 418 if (_NOTICE_TOAST) { 419 _NOTICE_TOAST.close() 420 _NOTICE_TOAST = null 421 } 422 423 // å¦ææ²¡æcloseæ¹æ³ï¼æ¾å°domå ç´ ç§»é¤ 424 const mesDom = document.querySelectorAll(".ed_notice_toast") 425 if (mesDom && mesDom[0]) { 426 mesDom[0].style.display = "none" 427 } 428 } 429 430 // 页é¢éæ¯ 431 function beforeUnload() { 432 clearTimer(); 433 } 434 435 function getDataByType(arr, type) { 436 const nowTime = new Date().getTime(); 437 const res = arr.filter((item) => { 438 return ( 439 item.type === type && 440 item.start_time * 1000 < nowTime && 441 item.end_time * 1000 > nowTime 442 ); 443 }); 444 return res && res.length ? res[0] : null 445 } 446 447 function setEnv() { 448 DEV_LOCAL = 449 location.host.includes("127.0.0.1") || 450 location.host.includes("10.90") || 451 location.host.includes("dev-en") || location.host.includes("dev"); 452 453 // ç¡®å®å¼ç¨ç¯å¢ 454 isEdrawAI = 455 location.host.includes("edraw.ai") || 456 location.host.includes(":5001"); 457 isMind = location.host.includes("edrawmind.com") || location.host.includes("dev.master.com") || location.host.includes(":3000"); 458 } 459 460 function setHomeEditor() { 461 // ç¡®å®æ¯é¦é¡µè¿æ¯ç¼è¾é¡µ 462 isEdrawEditor = location.href.includes("/master/") || location.href.includes("/max/"); 463 isMindEditor = location.href.includes("/editor/"); 464 isEditor = isMind ? isMindEditor : isEdrawAI ? isEdrawEditor : false; 465 } 466}
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.