Advertisement
Filexdoj

Application class

Dec 15th, 2019
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const lineX = [20, 50, 80]
  2. const lineY = [14, 31, 48, 67]
  3. const config = {
  4.     "lockPage": [`
  5.     <h3 id="time">24:24 </h3>
  6.     <div class="pagesPoints"></div>
  7.     `
  8.     ],
  9.     "homePage": [`
  10.     <h3 id="time">24:24 </h3>
  11.     <div class="pagesPoints"></div>
  12.     <div class="homeTab">
  13.         <img class="shape" src="icons/settings.png">
  14.         <img class="shape" src="icons/phone.png">
  15.         <img class="shape" src="icons/time.png">
  16.     </div>
  17.     `
  18.     ],
  19.     "bank": [
  20.         `<div class="Balance">
  21.         <img id="accountPic" src="imgs/accountDefaultPic.png">
  22.         <p id="accountName">Account Name medtheman</p>
  23.         <p id="accountBalance">Balance: 100.000.000 USD</p>
  24.         <p id="accountStatus">Social Status: Rich</p>
  25.     </div>
  26.     <div class="bankButtons">
  27.         <div>
  28.             <label>Username</label>
  29.             <input id="usernameOfTransaction" />
  30.         </div>
  31.         <div id="amountDiv">
  32.             <label>Amount</label>
  33.             <input id="amountOfTransaction">
  34.         </div>
  35.         <div class="bothDivs">
  36.             <div id="applyTransaction">Apply Transaction</div>
  37.             <div class="ATMs">Look For Nearby ATMs</div>
  38.         </div>
  39.     </div>`,
  40.         `.mainContainer {
  41.         position: absolute;
  42.         border-radius: 26px;
  43.         background: rgba(40,40,40,1);
  44.         top: 50%;
  45.         left: 50%;
  46.         transform: translate(-50%, -50%);
  47.         width: 220px;
  48.         height: 476px;
  49.     }
  50.    
  51.    
  52.     .mainContainer .topBar {
  53.         position: absolute;
  54.         width: 125px;
  55.         height: 18px;
  56.         top: 1.9%;
  57.         left: 50%;
  58.         transform: translate(-50%, -50%);
  59.     }
  60.    
  61.     .Balance {
  62.         background: radial-gradient(white,gray);
  63.         border-radius: 20px ;
  64.         box-shadow: gray 10px ;
  65.         width: 100%;
  66.         height: 170px;
  67.     }
  68.    
  69.     #accountPic {
  70.         width: 60px;
  71.         border-radius: 5px;
  72.         margin-top: 30px;
  73.         margin-left: 20px;
  74.     }
  75.    
  76.     #accountName{
  77.         text-align: center;
  78.         position: absolute;
  79.         top: 40px;
  80.         margin-left: 90px;
  81.         width: 120px;
  82.     }
  83.    
  84.     #accountBalance {
  85.         font-size: 15px;
  86.         margin-top: 5px;
  87.         width: 190px;
  88.         margin-left:20px;
  89.     }
  90.    
  91.     #accountStatus {
  92.         font-size: 15px;
  93.         margin-top: 5px;
  94.         width: 190px;
  95.         margin-left:20px;
  96.     }
  97.    
  98.     .bankButtons {
  99.         position: absolute;
  100.         left: 50%;
  101.         top: 63%;
  102.         transform: translate(-50%,-50%);
  103.         align-items: center;
  104.         text-align: center;
  105.     }
  106.    
  107.     .bankButtons #applyTransaction , .ATMs  {
  108.         background: rgba(243, 124, 13,1);
  109.         width: 100%;
  110.         margin-top: 3px;
  111.         padding-top: 10px;
  112.         padding-bottom: 10px;
  113.         transition:800ms;
  114.     }
  115.     #amountDiv {
  116.         margin-top: 8px;
  117.     }
  118.     .bankButtons label {
  119.         color: white;
  120.     }
  121.     .bankButtons input  {
  122.         border: 0;
  123.         height: 35px;
  124.         text-align: center;
  125.         color: white;
  126.         background: rgba(30,30,30,1);transition:800ms;
  127.     }
  128.     .bankButtons input:hover , input:focus {
  129.         background: rgba(255,255,255,1);
  130.         color: black;
  131.     }
  132.    
  133.     .bankButtons  #applyTransaction:hover  , .ATMs:hover {
  134.         background: rgb(32, 126, 202);
  135.     }
  136.    
  137.     .bothDivs {
  138.         margin-top: 15px;
  139.     }`
  140.     ]
  141. }
  142. var apps = [[]]
  143. var currentStyle
  144. var timeInterval
  145. var pagesCount = 1
  146. var currentPage = 1
  147. var previousPage = 0
  148.  
  149.  
  150. class Application {
  151.     constructor(name, iconPath, scriptPath) {
  152.         this.name = name
  153.         this.iconPath = iconPath
  154.         this.scriptPath = scriptPath
  155.     }
  156.     static registreApp(app) {
  157.         if (apps[pagesCount - 1].length == 12) {
  158.             apps[pagesCount] = []
  159.             pagesCount++
  160.         }
  161.         app.lineY = lineY[Math.trunc(apps[pagesCount - 1].length / 3)]
  162.         app.lineX = lineX[(apps[pagesCount - 1].length % 3)]
  163.         apps[pagesCount - 1].push(app)
  164.     }
  165.  
  166.     static initialize(app) {
  167.         let mainContainer = document.querySelector(".mainContainer")
  168.         let appTag = document.createElement("div");
  169.         appTag.className = app.name.replace(" ", "")
  170.         let img = document.createElement("img");
  171.         let p = document.createElement("p");
  172.         img.src = app.iconPath
  173.         appTag.appendChild(img)
  174.         p.innerHTML = app.name
  175.         appTag.appendChild(p)
  176.         mainContainer.appendChild(appTag)
  177.         let style = document.createElement('style');
  178.         style.innerHTML = `
  179.         .${appTag.className} {
  180.             position: absolute;
  181.             width: 50px;
  182.             height: 50px;
  183.             top: ${app.lineY}%;
  184.             left: ${app.lineX}%;
  185.             transform: translate(-50%, -50%);
  186.             z-index: 999;
  187.         }
  188.         .${appTag.className} p {
  189.             font-size: 11px;
  190.             text-align: center;
  191.             color: white;
  192.             margin-top:2px;
  193.             font-weight: bold;
  194.             word-wrap: break-word
  195.         }
  196.         .${appTag.className} img {
  197.             margin-left: auto;
  198.             margin-right: auto;
  199.             display: block;
  200.             border-radius: 8px;
  201.             width: 50px;
  202.             transition:500ms;
  203.         }
  204.         .${appTag.className}:hover  {
  205.             width: 55px;
  206.         }
  207.         .${appTag.className}:hover img {
  208.             width: 55px;
  209.         }
  210.         `;
  211.         document.head.appendChild(style);
  212.         app.style = style
  213.     }
  214.  
  215.     static addEvent(app) {
  216.         let mainContainer = document.querySelector(".mainContainer")
  217.         let appTag = document.querySelector("." + app.name.replace(" ", ""))
  218.         appTag.addEventListener("click", function () {
  219.             mainContainer.innerHTML = app.scriptPath[0]
  220.             mainContainer.innerHTML += `
  221.             <img class="topBar" src="topBar.png"/>
  222.             <div class="homeButton"></div>
  223.             `
  224.             document.querySelector(".homeButton").addEventListener("click", unlockPhone)
  225.             let style = document.createElement('style');
  226.             style.innerHTML = app.scriptPath[1];
  227.             document.head.appendChild(style);
  228.             for (i = 0; i < apps[currentPage - 1].length; i++) {
  229.                 document.head.removeChild(apps[currentPage - 1][i].style)
  230.             }
  231.             clearInterval(timeInterval)
  232.             currentStyle = style
  233.         })
  234.     }
  235.  
  236.     static removeApp(app) {
  237.         var appTag = document.querySelector("." + app.name.replace(" ", ""))
  238.         appTag.parentNode.removeChild(appTag)
  239.         document.head.removeChild(app.style)
  240.     }
  241. }
  242.  
  243. function registreApps() {
  244.     let Bank = new Application("Bank", "icons/bank.png", config.bank)
  245.     Application.registreApp(Bank)
  246.     let FlappyBird = new Application("Flappy Bird", "icons/flappybird.png")
  247.     Application.registreApp(FlappyBird)
  248.     let Housing = new Application("Housing", "icons/housing.png")
  249.     Application.registreApp(Housing)
  250.     let Messages = new Application("Messages", "icons/messages.png")
  251.     Application.registreApp(Messages)
  252.     let Music = new Application("Music", "icons/music.png")
  253.     Application.registreApp(Music)
  254.     let Notes = new Application("Notes", "icons/notes.png")
  255.     Application.registreApp(Notes)
  256.     let SAES = new Application("SAES", "icons/saes.png")
  257.     Application.registreApp(SAES)
  258.     let Youtube = new Application("Youtube", "icons/youtube.png")
  259.     Application.registreApp(Youtube)
  260.  
  261. }
  262.  
  263. function changePage() {
  264.     if (currentPage == pagesCount) {
  265.         currentPage = 1
  266.         previousPage = pagesCount
  267.         for (i = 0; i < apps[currentPage - 1].length; i++) {
  268.             Application.initialize(apps[currentPage - 1][i])
  269.         }
  270.         for (i = 0; i < apps[pagesCount - 1].length; i++) {
  271.             Application.removeApp(apps[pagesCount - 1][i])
  272.         }
  273.     } else {
  274.         currentPage++
  275.         previousPage = currentPage - 1
  276.         for (i = 0; i < apps[currentPage - 1].length; i++) {
  277.             Application.initialize(apps[currentPage - 1][i])
  278.         }
  279.         for (i = 0; i < apps[currentPage - 2].length; i++) {
  280.             Application.removeApp(apps[currentPage - 2][i])
  281.         }
  282.     }
  283.     document.querySelector(`#pagePoint${currentPage}`).style.opacity = "1.0"
  284.     document.querySelector(`#pagePoint${previousPage}`).style.opacity = "0.5"
  285. }
  286.  
  287. function updateTime() {
  288.     let timeText = document.querySelector('#time')
  289.     let d = new Date();
  290.     let hours = d.getHours()
  291.     let minutes = d.getMinutes()
  292.     if (hours < 10) {
  293.         hours = "0" + hours
  294.     }
  295.     if (minutes < 10) {
  296.         minutes = "0" + minutes
  297.     }
  298.     timeText.innerHTML = hours + ":" + minutes
  299. }
  300.  
  301. function updateTimeTextPosition() {
  302.     let timeText = document.querySelector('#time')
  303.     timeText.style.fontSize = "12px"
  304.     timeText.style.top = "4.5%"
  305.     timeText.style.left = "82%"
  306. }
  307.  
  308. function setPagesDisplay() {
  309.     let pagesPoints = document.querySelector(".pagesPoints")
  310.     for (i = 0; i < pagesCount; i++) {
  311.         let div = document.createElement("div")
  312.         div.id = "pagePoint" + (i + 1)
  313.         pagesPoints.appendChild(div)
  314.         if (i == currentPage - 1) {
  315.             div.style.opacity = "1.0"
  316.         }
  317.     }
  318.     pagesPoints.addEventListener("click", changePage)
  319. }
  320.  
  321. function unlockPhone() {
  322.     if (currentStyle) {
  323.         currentStyle.parentNode.removeChild(currentStyle)
  324.     }
  325.     var mainContainer = document.querySelector(".mainContainer")
  326.     mainContainer.removeEventListener("click", unlockPhone)
  327.     mainContainer.innerHTML = config.homePage[0]
  328.     updateTime()
  329.     updateTimeTextPosition()
  330.     setPagesDisplay()
  331.     timeInterval = setInterval(updateTime, 30000)
  332.     for (i = 0; i < apps[currentPage - 1].length; i++) {
  333.         Application.initialize(apps[currentPage - 1][i])
  334.         Application.addEvent(apps[currentPage - 1][i])
  335.     }
  336. }
  337.  
  338. function onWindowLoad() {
  339.     var mainContainer = document.querySelector(".mainContainer")
  340.     mainContainer.addEventListener("click", unlockPhone)
  341.     mainContainer.innerHTML = config.lockPage
  342.     updateTime()
  343.     timeInterval = setInterval(updateTime, 30000)
  344.     registreApps()
  345. }
  346. window.addEventListener("load", onWindowLoad)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement