index.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="apple-mobile-web-app-capable" content="yes" />
  6. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  7. <meta name="theme-color" content="#4b75ff">
  8. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  9. <script src="../script/jquery.min.js"></script>
  10. <script src="../script/semantic/semantic.min.js"></script>
  11. <script src="../script/ao_module.js"></script>
  12. <title>Browser</title>
  13. <style>
  14. </style>
  15. </head>
  16. <body>
  17. <div id="renderer">
  18. </div>
  19. <script>
  20. let renderingURL = "http://124.244.86.40:8080";
  21. //Get window hash
  22. let targetFrameingURL = "";
  23. if (window.location.hash.length > 0){
  24. targetFrameingURL = window.location.hash.substr(1);
  25. targetFrameingURL = JSON.parse(decodeURIComponent(targetFrameingURL));
  26. console.log(targetFrameingURL);
  27. }
  28. ao_module_agirun("Browser/backend/downpage.js", {
  29. url: renderingURL
  30. }, function(data){
  31. var postScripts = manualScriptLoading(renderingURL, data, true);
  32. //console.log(data);
  33. var titleFilter = JSON.parse(JSON.stringify(data));
  34. var pageTitle = $(titleFilter).filter('title').text();
  35. var renderEle = $(JSON.parse(JSON.stringify(data)));
  36. console.log(renderEle);
  37. $(renderEle).each(function(){
  38. if (!$(this).is("script")){
  39. $("#renderer").append($(this));
  40. if ($(this).attr("src") !== undefined){
  41. fixRelativePath(renderingURL, $(this).attr("src"), $(this));
  42. }
  43. }
  44. });
  45. ao_module_setWindowTitle(pageTitle);
  46. //Get the script parts and execute it
  47. setTimeout(function(){
  48. postScripts.forEach(function(script){
  49. $("#renderer").append($(script));
  50. });
  51. }, 300);
  52. //Replace all images
  53. $("img").each(function(){
  54. bufferImageLoad(renderingURL, $(this).attr("src"), $(this));
  55. });
  56. });
  57. function manualScriptLoading(url, contentBody, srcOnly = true){
  58. var scripts = $(contentBody).filter("script");
  59. console.log(scripts);
  60. var postScripts = [];
  61. scripts.each(function(){
  62. if (srcOnly){
  63. if ($(this).attr("src") == undefined){
  64. let internalScriptEle = $(this);
  65. postScripts.push(internalScriptEle);
  66. }else{
  67. //Check for relative or absolute
  68. if ($(this).attr("src").includes("//") == false){
  69. let seperator = "/";
  70. if ($(this).attr("src").substr(0, 1) == "/"){
  71. seperator = "";
  72. }
  73. $(this).attr("src", url+seperator + $(this).attr("src"));
  74. console.log("Fixing relative import with absolute: ", $(this).attr("src"));
  75. }
  76. $("head").append($(this));
  77. }
  78. }else{
  79. //Check for relative or absolute
  80. if ($(this).attr("src").includes("//") == false){
  81. let seperator = "/";
  82. if ($(this).attr("src").substr(0, 1) == "/"){
  83. seperator = "";
  84. }
  85. $(this).attr("src", url+seperator + $(this).attr("src"));
  86. console.log("Fixing relative import with absolute: ", $(this).attr("src"));
  87. }
  88. $("head").append($(this));
  89. }
  90. console.log($(this).attr("src"));
  91. });
  92. return postScripts;
  93. }
  94. function fixRelativePath(baseURL, relpath, element){
  95. let fullURL = relpath;
  96. if (!relpath.includes("//")){
  97. let seperator = "/";
  98. if (relpath.substr(0, 1) == "/"){
  99. seperator = "";
  100. }
  101. fullURL = baseURL + seperator + relpath;
  102. }
  103. $(element).attr('src',fullURL);
  104. }
  105. function bufferImageLoad(baseURL, imageURL, object){
  106. //Parse the relative URL
  107. let fullURL = imageURL;
  108. let ext = imageURL.split(".").pop();
  109. if (!imageURL.includes("//")){
  110. let seperator = "/";
  111. if (imageURL.substr(0, 1) == "/"){
  112. seperator = "";
  113. }
  114. fullURL = baseURL + seperator + imageURL;
  115. }
  116. console.log(fullURL);
  117. if (ext == "svg"){
  118. $(object).attr("src", fullURL);
  119. }else{
  120. ao_module_agirun("Browser/backend/downimg.js", {
  121. url: fullURL
  122. }, function(base64){
  123. $(object).attr("src", "data:image/" + ext + ";base64," + base64);
  124. });
  125. }
  126. }
  127. function stringToBytes (str) {
  128. var ch, st, re = [];
  129. for (var i = 0; i < str.length; i++ ) {
  130. ch = str.charCodeAt(i);
  131. st = [];
  132. do {
  133. st.push( ch & 0xFF );
  134. ch = ch >> 8;
  135. } while ( ch );
  136. re = re.concat( st.reverse() );
  137. } // return an array of bytes
  138. return re;
  139. }
  140. </script>
  141. </body>
  142. </html>