pre.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. !(function (window) {
  2. var env = {};
  3. window.env = env;
  4. checkPlatform(env);
  5. var isCN = checkIsChinese();
  6. initTitle(isCN);
  7. initSplash(isCN);
  8. function hideLoading() {
  9. var url = window.location.href;
  10. if (url.indexOf("?") > -1) {
  11. console.log('hide splash');
  12. var splash = document.getElementsByClassName("splash")[0];
  13. setTimeout(function () {
  14. document.body.style.backgroundColor = "white";
  15. splash.style.display = "none";
  16. splash.style.zIndex = 0;
  17. });
  18. console.log('no hideLoading');
  19. var loading = document.getElementsByClassName("full-screen-center")[0];
  20. setTimeout(function () {
  21. loading.style.zIndex = 1003;
  22. });
  23. return;
  24. }
  25. console.log('hideLoading');
  26. var loading = document.getElementsByClassName("full-screen-center")[0];
  27. setTimeout(function () {
  28. loading.style.zIndex = 0;
  29. });
  30. }
  31. hideLoading();
  32. function initTitle(isCN) {
  33. document.title = isCN ? "杏聆荟" : "Flyinsono";
  34. }
  35. function initSplash(isCN) {
  36. var splash = document.getElementsByClassName('splash')[0];
  37. if (!splash) return;
  38. splash.classList.add(isCN ? 'splash_cn' : 'splash_en');
  39. }
  40. function checkPlatform(target) {
  41. // injectWinTest();
  42. var shell = window["FisShellApi"];
  43. if (shell) {
  44. target.platform = 'shell';
  45. shell.getPlatformName().then(function (res) {
  46. target.platform = res;
  47. });
  48. } else {
  49. target.platform = 'Web';
  50. }
  51. }
  52. /// inject `FisShellApi` for debug
  53. function injectWinTest() {
  54. window["FisShellApi"] = {
  55. writeLog: async (text) => {
  56. console.log(text);
  57. },
  58. getPlatformName: async () => "Win",
  59. setTitle: async (title) => {
  60. console.log(`Set title - ${title}`);
  61. },
  62. };
  63. }
  64. function checkIsChinese() {
  65. var lang = navigator.language.split('-')[0].toLocaleLowerCase();
  66. // var storeLocale = localStorage['flutter.store_app_locale'];
  67. // if (storeLocale != null && storeLocale.length) {
  68. // try {
  69. // var arr = JSON.parse(storeLocale);
  70. // if (arr && arr.length === 2) {
  71. // lang = arr[0].toLocaleLowerCase();
  72. // }
  73. // } catch (error) { }
  74. // }
  75. return lang === 'zh';
  76. }
  77. })(window);