Browse Source

endlerbrecer translator

Kajetan Johannes Hammerle 3 years ago
parent
commit
82348cbbab
5 changed files with 100 additions and 36 deletions
  1. 2 0
      web/css/brainfuck.css
  2. 4 0
      web/css/style.css
  3. 12 0
      web/endlerbrecer.php
  4. 11 36
      web/index.php
  5. 71 0
      web/js/endlerbrecer.js

+ 2 - 0
web/css/brainfuck.css

@@ -42,6 +42,7 @@
 
 #outputcode
 {
+    margin-top: 6px;
     margin-bottom: 6px;
     
     width: 100%;
@@ -60,6 +61,7 @@
 
 #output
 {
+    margin-top: 6px;
     margin-bottom: 6px;
     
     width: 100%;

+ 4 - 0
web/css/style.css

@@ -283,6 +283,10 @@ general stuff
     font-weight: bold;
 }
 
+.full-width {
+    width: 100%;
+}
+
 /* 
 --------------------------------------------------------------------------------
 footer

+ 12 - 0
web/endlerbrecer.php

@@ -0,0 +1,12 @@
+<div class="container">
+    <div class="col-lg">
+        <textarea id="input">Type any German text to translate it.</textarea>
+    </div>
+    <div class="col-lg">
+        <button onClick="translateText()" class="btn full-width">Translate</button>
+    </div>
+    <div class="col-lg">
+        <div id="output"></div>
+    </div>
+    <script src="js/endlerbrecer.js"></script>
+</div>

+ 11 - 36
web/index.php

@@ -1,6 +1,5 @@
 <?php
-    if(session_status() == PHP_SESSION_NONE) 
-    {
+    if(session_status() == PHP_SESSION_NONE) {
         session_start();
     }
 ?>
@@ -39,38 +38,19 @@
                         <div class='dropdown-menu nav_drop' aria-labelledby='snuvi_dropdown'>
                             <a class='dropdown-item nav_drop_item' href='index.php?section=snuvi_core'>Core</a>
                             <a class='dropdown-item nav_drop_item' href='index.php?section=snuvi_supersnuvi'>Super Snuvi</a>
-                            <?php
-                                //if(isset($_SESSION["user"]))
-                                //{
-                                    echo "<a class='dropdown-item nav_drop_item' href='index.php?section=snuvi_minecraft'>Minecraft</a>";
-                                //}
-                            ?>
+                            <a class='dropdown-item nav_drop_item' href='index.php?section=snuvi_minecraft'>Minecraft</a>
                         </div>
                     </li>
-                    <?php
-                        /*if(isset($_SESSION["user"]))
-                        {
-                            echo "<li class='nav-item dropdown'>";
-                            echo "<a class='nav-link dropdown-toggle' href='#' id='coding_dropdown' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>";
-                            echo "Coding";
-                            echo "</a>";
-                            echo "<div class='dropdown-menu nav_drop' aria-labelledby='coding_dropdown'>";
-                            echo "<a class='dropdown-item nav_drop_item' href='index.php?section=snuvi_git'>Snuvi Git</a>";
-                            echo "</div>";
-                            echo "</li>";
-                        }*/
-                    ?>
                     <li class="nav-item"><a class="nav-link" href="index.php?section=brainfuck">Brainfuck</a></li>
                     <li class="nav-item"><a class="nav-link" href="index.php?section=fruits">Fruits</a></li>
+                    <li class="nav-item"><a class="nav-link" href="index.php?section=endlerbrecer">Endlerbrecer</a></li>
                 </ul>
             </div>
         </nav>    
         <main class="container">
             <?php
-            if(isset($_GET["section"])) 
-            {
-                switch ($_GET["section"]) 
-                {
+            if(isset($_GET["section"])) {
+                switch ($_GET["section"]) {
                     case "snuvi_core":
                         include "snuvi_core.php";
                         break;
@@ -80,9 +60,6 @@
                     case "snuvi_supersnuvi":
                         include "snuvi_supersnuvi.php";
                         break;
-                    //case "snuvi_git":
-                    //    include "snuvi_git.php";
-                    //    break;
                     case "brainfuck":
                         include "brainfuck.php";
                         break;
@@ -95,14 +72,15 @@
                     case "fruits":
                         include "fruits.php";
                         break;
+                    case "endlerbrecer":
+                        include "endlerbrecer.php";
+                        break;
                     case "home":
                     default:
                         include "home.php";
                         break;
                 }
-            }
-            else
-            {
+            } else {
                 include "home.php";
             }
             ?>
@@ -110,12 +88,9 @@
         <footer>
             <span class="footerPipe">Made by Kajetan</span>
             <?php
-                if(isset($_SESSION["user"])) 
-                {
+                if(isset($_SESSION["user"])) {
                     echo "<a class='login' href='index.php?section=logout'>Logout</a>";
-                }
-                else
-                {
+                } else {
                     echo "<a class='login' href='index.php?section=login'>Login</a>";
                 }
             ?>

+ 71 - 0
web/js/endlerbrecer.js

@@ -0,0 +1,71 @@
+function translateText() {
+    let text = document.getElementById("input").value;
+
+    text = text + " ";
+
+    text = text.toLowerCase();
+    text = text.replace("ü", "u");
+    text = text.replace("ö", "o");
+    text = text.replace("ä", "e");
+    text = text.replace("ß", "s");
+    text = text.replace("sch", "s");
+    text = text.replace("ch", "c");
+    text = text.replace("au", "u");
+    text = text.replace("ei", "EI");
+    text = text.replace("eu", "EU");
+    text = text.replace("sp", "p");
+    text = text.replace("st", "t");
+    text = text.replace("pf", "f");
+
+    let permute = "";
+    for (let i = 0; i < text.length; i++) {
+        c = text.charAt(i);
+        switch (c) {
+            case 'a': c = 'e'; break;
+            case 'f': c = 'v'; break;
+            case 'k': c = 'c'; break;
+            case 'p': c = 'b'; break;
+            case 'q': c = 'k'; break;
+            case 't': c = 'd'; break;
+            case 'w': c = 'v'; break;
+            case 'x': c = 'k'; break;
+            case 'y': c = 'u'; break;
+            case 'z': c = 's'; break;
+            case '?': c = ' '; break;
+            case '.': c = ' '; break;
+            case '!': c = ' '; break;
+        }
+        permute += c;
+    }
+    text = permute;
+
+    let letters = [
+        "a", "b", "c", "d", "e", "f",
+        "g", "h", "i", "j", "k", "l",
+        "m", "n", "o", "p", "q", "r",
+        "s", "t", "u", "v", "w", "x",
+        "y", "z"];
+
+    for (let i = 0; i < letters.length; i++) {
+        text = text.replace(letters[i] + letters[i], letters[i]);
+    }
+
+    text = text.replace("r ", "RE ");
+    text = text.replace("e ", "ER ");
+    text = text.replace("a ", "AR ");
+    text = text.replace("d ", "DE ");
+    text = text.replace("l ", "LE ");
+    text = text.replace("m ", "MER ");
+    text = text.replace("n ", "NE ");
+    text = text.replace("s ", "SA ");
+
+    text = text.replace("ie", "IA");
+    text = text.replace("h", "");
+
+    text = text.replace("EI", "a");
+    text = text.replace("EU", "o");
+
+    text = text.toLowerCase();
+
+    document.getElementById("output").innerHTML = text;
+}