import KataUrl from './kata-url.js'

export default class StartUp {
  constructor(xhrGet, xhrGetDefaultKata) {
    this.xhrGet = xhrGet;
    this.xhrGetDefaultKata = xhrGetDefaultKata;
  }

  loadSourceCode(withSourceCode) {

    const getSourceCode = () => {
      const queryString = window.location.hash.replace(/^#\?/, '');
      var kataUrl = KataUrl.fromQueryString(queryString);
      var sourceCode = localStorage.getItem('code');
      if (kataUrl) {
        this.loadKataFromUrl(kataUrl, withSourceCode);
      } else if (sourceCode) {
        withSourceCode(sourceCode);
      } else {
        this.loadDefaultKata(withSourceCode);
      }
      window.location.hash = window.location.hash.replace(/kata=([^&]+)/, '');
    };

    getSourceCode();
  }

  loadDefaultKata(onLoaded) {
    this.xhrGetDefaultKata(
      (_, {status}) => onLoaded(`// Default kata not found (status ${status})\n// Maybe try a different kata (see URL).`),
      data => {onLoaded(data)}
    );
  }

  loadKataFromUrl(kataUrl, onLoaded) {
    this.xhrGet(
      kataUrl,
      (_, {status}) => onLoaded(`// Kata at "${kataUrl}" not found (status ${status})\n// Maybe try a different kata (see URL).`),
      data => {onLoaded(data)}
    );
  }

}

@@ -222,45 +222,8 @@
 ) %7B%0A
-%0A    const getSourceCode = () =%3E %7B%0A  
     
@@ -284,26 +284,24 @@
 /, '');%0A    
- 
- 
 var kataUrl 
@@ -344,18 +344,16 @@
 g);%0A    
-  
 var sour
@@ -391,18 +391,16 @@
 code');%0A
-  
     if (
@@ -408,34 +408,32 @@
 ataUrl) %7B%0A      
-  
 this.loadKataFro
@@ -463,26 +463,24 @@
 eCode);%0A    
-  
 %7D else if (s
@@ -488,26 +488,24 @@
 urceCode) %7B%0A
-  
       withSo
@@ -530,18 +530,16 @@
 e);%0A    
-  
 %7D else %7B
@@ -539,18 +539,16 @@
  else %7B%0A
-  
       th
@@ -591,14 +591,10 @@
     
- 
- 
 %7D%0A
-  
     
@@ -670,37 +670,8 @@
 ');%0A
-    %7D;%0A%0A    getSourceCode();%0A
   %7D%0A

Remove useless function around it.