head.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. function getUrlParameter(sParam) {
  2. var sPageURL = decodeURIComponent(window.location.search.substring(1)),
  3. sURLVariables = sPageURL.split('&'),
  4. sParameterName, i;
  5. for (i = 0; i < sURLVariables.length; i++) {
  6. sParameterName = sURLVariables[i].split('=');
  7. if (sParameterName[0] === sParam) {
  8. return sParameterName[1] === undefined ? null : sParameterName[1];
  9. }
  10. }
  11. return null;
  12. }
  13. var LANGUAGE = getUrlParameter("lang");
  14. if (LANGUAGE == null) {
  15. LANGUAGE = localStorage.handPyLanguage ? localStorage.handPyLanguage : "zh-CN";
  16. }
  17. function showfile(b) {
  18. if (b) {
  19. document.getElementById("restore-file-upload").style.visibility = "visible";
  20. $("#restore-file-upload").val("");
  21. $("#restore-file-upload").trigger("click");
  22. } else {
  23. document.getElementById("restore-file-upload").style.visibility = "hidden";
  24. }
  25. }
  26. function setDevice(device) {
  27. function getLang() {
  28. if (localStorage.handPyLanguage) {
  29. return localStorage.handPyLanguage;
  30. } else {
  31. return "zh-CN";
  32. }
  33. }
  34. disconnectCom();
  35. localStorage.handPyDevice = device;
  36. var lang = getLang();
  37. switch (device) {
  38. case "CocoRobobox":
  39. location.replace('editor_box.html?lang=' + lang);
  40. break;
  41. case "microbit":
  42. location.replace('editor_microbit.html?lang=' + lang);
  43. break;
  44. default:
  45. location.replace('editor.html?lang=' + lang);
  46. break;
  47. }
  48. }
  49. function doRouter(lang) {
  50. function getDevice() {
  51. if (localStorage.handPyDevice) {
  52. return localStorage.handPyDevice;
  53. } else {
  54. return "CocoRobo";
  55. }
  56. }
  57. function routerTo(_device, _lang) {
  58. if ('zh-TW' == _lang) _lang = 'zh-HK';
  59. switch(_device) {
  60. case 'CocoRobobox':
  61. location.replace('editor_box.html?lang=' + _lang);
  62. break;
  63. case 'microbit':
  64. location.replace('editor_microbit.html?lang=' + _lang);
  65. break;
  66. default:
  67. location.replace('editor.html?lang=' + _lang);
  68. break;
  69. }
  70. }
  71. disconnectCom();
  72. localStorage.handPyLanguage = lang;
  73. routerTo(getDevice(), lang);
  74. }
  75. VERSION = " X 0.5.0";
  76. var VERSION_NO = "0.5.0";
  77. var hasInternet = false;
  78. var newVersion = VERSION_NO;
  79. var newDescription = "";
  80. var newLink = "";
  81. var OFFICE_HARDWARD_DATE = "2019-11-25";
  82. var OFFICE_HARDWARD_VERSION = "v1.5.1-16";
  83. var CocoRoboBOX_HARDWARD_DATE = "2019-10-16";
  84. var CocoRoboBOX_HARDWARD_VERSION = "v1.0.0-20";
  85. function doNothing(){
  86. window.event.returnValue = false;
  87. return false;
  88. }