GeSHi Source Viewer: loader.jsView Raw


  1. /*! 
  2.  * @file Planeptune Loop Player Core Loader
  3.  * @version 1.3
  4.  * @author zefie <zefie@zefie.net>
  5.  * @copyright 2017-2021 Zefie Networks
  6.  * @license CC-BY-SA-4.0
  7.  *
  8.  * Minified using uglify-js v3.x
  9.  * For human readable version of the loader, see https://loops.planeptune.org/geshi/source/js/loader.js
  10.  * For human readable version of the loop player core, see https://loops.planeptune.org/geshi/source/js/loopplayer.html5.core.js
  11.  */
  12.  
  13. var z_urlp;
  14. var dm;
  15. var offline = false;
  16.  
  17. (function () {
  18.   "use strict";
  19.   z_urlp = function (sParam) {
  20.     var sPageURL = decodeURIComponent(window.location.search.substring(1)).replace(/\+/g,' '),
  21.     sURLVariables = sPageURL.split("&"),
  22.     sParameterName;
  23.     for (var i = 0; i < sURLVariables.length; i++) {
  24.       sParameterName = sURLVariables[i].split("=");
  25.       if (sParameterName[0] === sParam) {
  26.         return sParameterName[1] === undefined ? true : sParameterName[1];
  27.       }
  28.     }
  29.   };
  30.  
  31.   function is_nwjs(){
  32.     try{
  33.         return (typeof require('nw.gui') !== "undefined");
  34.     } catch (e){
  35.         return false;
  36.     }
  37.   }
  38.  
  39.   function loadScriptWithIntegrity(url, integrity, successCallback, errorCallback) {
  40. 	  const script = document.createElement('script');
  41. 	  script.src = url;
  42. 	  script.integrity = integrity;
  43. 	  script.crossOrigin = 'anonymous'; // Required for SRI to work
  44.  
  45. 	  script.onload = successCallback;
  46.  
  47. 	  script.onerror = errorCallback;
  48.  
  49. 	  document.head.appendChild(script);
  50.   }
  51.  
  52.   $(document).ready(function () {
  53. 	console.log("loopplayer loader v1.3 initializing");
  54.     dm = z_urlp("debug") || null;    
  55.     offline = is_nwjs();
  56. 	var offlinescript = "/source/js/offline.js";
  57. 	var offlinehash = "~OFFLINEHASH~"
  58. 	var corescript = "/core/js/loopplayer.html5.core.min.js";
  59. 	var corehash = "~COREHASH~"
  60. 	var howlscript = "/core/js/howler.min.js";
  61. 	var howlhash = "~HOWLHASH~"
  62.     var caching = true;
  63.     var cachingAfter = true;
  64.     if (dm) {
  65.       switch (dm) {
  66.       case "core":
  67.         corescript = "/source/js/loopplayer.html5.core.js";
  68.         corehash = "~CORESRCHASH~"
  69.         break;
  70.       case "howler":
  71.         corescript = "/source/js/loopplayer.html5.core.js";
  72.         corehash = "~CORESRCHASH~"
  73.         howlscript = "/source/js/howler.js";
  74.         howlhash = "~HOWLSRCHASH~"
  75.         break;
  76.       }
  77.       caching = false;
  78.     }
  79.     $.ajaxSetup({
  80.       cache: caching
  81.     });
  82.     if (offline) {
  83.       loadScriptWithIntegrity(offlinescript, offlinehash, function () {
  84.         loadScriptWithIntegrity(howlscript, howlhash, function (s) {
  85.           if (s) {
  86.             loadScriptWithIntegrity(corescript, corehash, function () {          
  87.               $.ajaxSetup({
  88.                 cache: cachingAfter
  89.               });
  90.             });
  91.           }
  92.         });
  93.       });
  94.     } else {
  95.       loadScriptWithIntegrity(howlscript, howlhash, function (s) {
  96.         if (s) {
  97.           loadScriptWithIntegrity(corescript, corehash, function () {          
  98.             $.ajaxSetup({
  99.               cache: cachingAfter
  100.             });
  101.           });
  102.         }
  103.       });
  104.     };
  105.   });
  106.  
  107. /*
  108.     if (offline) {
  109.       loadScript(offlinescript, function () {
  110.         loadScript(howlscript, function (s) {
  111.           if (s) {
  112.             loadScript(corescript, function () {          
  113.               $.ajaxSetup({
  114.                 cache: cachingAfter
  115.               });
  116.             });
  117.           }
  118.         });
  119.       });
  120.     } else {
  121.       loadScript(howlscript, function (s) {
  122.         if (s) {
  123.           loadScript(corescript, function () {          
  124.             $.ajaxSetup({
  125.               cache: cachingAfter
  126.             });
  127.           });
  128.         }
  129.       });
  130.     };
  131.   });
  132. */
  133. })();
  134.