Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 8.10 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>project 2</title>
  7. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  8. <link href="https://fonts.googleapis.com/css?family=Karla|Yantramanav|Open+Sans|Roboto:400,900" rel="stylesheet">
  9. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  10. <style>
  11.    
  12.     * {
  13.         box-sizing: border-box;
  14.         margin: 0;
  15.         outline: 0;
  16.     }
  17.    
  18.     a,a:link,a:visited,.a:hover,.a:focus,a:active{
  19.         color: inherit;
  20.         text-decoration: none;
  21.     }
  22.    
  23.     body {
  24.         margin: 0;
  25.     }
  26.    
  27.     .content {
  28.         margin: 0 auto;
  29.         max-width: 500px;
  30.         padding: 40px;
  31.     }
  32.    
  33.     h1 {
  34.         font-family: 'Roboto';
  35.         padding: 10px 0;
  36.     }
  37.    
  38.     .entry,.new,.item {
  39.         padding: 10px 0;
  40.         border-top: 1px solid #e6e6e6;
  41.         position: relative;
  42.     }
  43.    
  44.     .new {
  45.         display: flex;
  46.         border-bottom: 1px solid #e6e6e6
  47.     }  
  48.    
  49.     .entry p,.item p {
  50.         font-family: 'Yantramanav';
  51.         padding: 0 10px;
  52.     }
  53.    
  54.     .new input {
  55.         border: 0;
  56.         font-family: 'Yantramanav';
  57.         outline: 0;
  58.         font-size: 16px;
  59.         border: 1px solid #e6e6e6;
  60.         border-right: 0;
  61.         padding: 5px;
  62.     }
  63.    
  64.     .new button {
  65.         background: #35f;
  66.         color: #fff;
  67.         padding: 5px 8px;
  68.         border: 0;
  69.         font-size: 16px;
  70.         font-family: 'Yantramanav'
  71.     }
  72.    
  73.     .user .item::before,.entry::before {
  74.         content: '';
  75.         background: #e74c3c;
  76.         height: 2px;
  77.         width: 100%;
  78.         position: absolute;
  79.         top: 50%;
  80.         left: 0;
  81.         transform: translateY(-50%);
  82.         width: 0;
  83.         transition: all 0.3s ease
  84.     }
  85.    
  86.     .user .item:hover,.entry:hover {
  87.         cursor: pointer;
  88.     }
  89.    
  90.     .user .item:hover::before,.entry:hover::before {
  91.         width: 100%;
  92.     }
  93.    
  94.     h2 {
  95.         font-family: 'Roboto';
  96.         padding: 10px 0
  97.     }
  98.    
  99.     .item {
  100.         padding: 10px 0;
  101.         border-top: 1px solid #e6e6e6;
  102.         position: relative;
  103.     }
  104.    
  105.     .pro {
  106.         border-bottom: 1px solid #e6e6e6
  107.     }
  108.        
  109. </style>
  110.    
  111. </head>
  112. <body>
  113.  
  114.     <div class="content">
  115.         <h1>Todo</h1>
  116.         <div class="notes">
  117.             <div class="entry">
  118.                 <p>Nothing yet :)</p>
  119.             </div>
  120.         </div>
  121.         <div class="new">
  122.             <input type="text" placeholder="Add another task" id="add">
  123.             <button onclick="newTodo()">Submit</button>
  124.         </div>
  125.         <div class="pro">
  126.             <h2>Pro</h2>
  127.             <div class="item">
  128.                 <p>Dark mode</p>
  129.             </div>
  130.         </div>
  131.         <div class="user">
  132.             <h2>Account</h2>
  133.             <div class="item">
  134.                 <p onclick="signIn()">Sign in</p>
  135.             </div>
  136.         </div>
  137.     </div>
  138.    
  139.  
  140.     <!-- Insert these scripts at the bottom of the HTML, but before you use any Firebase services -->
  141.  
  142.       <!-- Firebase App (the core Firebase SDK) is always required and must be listed first -->
  143.       <script src="https://www.gstatic.com/firebasejs/7.7.0/firebase-app.js"></script>
  144.  
  145.       <!-- If you enabled Analytics in your project, add the Firebase SDK for Analytics -->
  146.       <script src="https://www.gstatic.com/firebasejs/7.7.0/firebase-analytics.js"></script>
  147.  
  148.       <!-- Add Firebase products that you want to use -->
  149.       <script src="https://www.gstatic.com/firebasejs/7.7.0/firebase-database.js"></script>
  150.       <script src="https://www.gstatic.com/firebasejs/7.7.0/firebase-auth.js"></script>
  151.       <script src="https://www.gstatic.com/firebasejs/7.7.0/firebase-firestore.js"></script>
  152.  
  153.     <script>
  154.         // Your web app's Firebase configuration
  155.         var firebaseConfig = {
  156.             apiKey: "AIzaSyAN0uz5sGcLzG-JskcSGLg0Ij5KG1nU9as",
  157.             authDomain: "todo-3b3a1.firebaseapp.com",
  158.             databaseURL: "https://todo-3b3a1.firebaseio.com",
  159.             projectId: "todo-3b3a1",
  160.             storageBucket: "todo-3b3a1.appspot.com",
  161.             messagingSenderId: "421815974833",
  162.             appId: "1:421815974833:web:b7e25b468079da609a5b90",
  163.             measurementId: "G-HZBRNZ112R"
  164.         };
  165.         var userId;
  166.         // Initialize Firebase
  167.         firebase.initializeApp(firebaseConfig);
  168.         firebase.analytics();
  169.        
  170.         function signIn(){
  171.             var provider = new firebase.auth.GoogleAuthProvider();
  172.             firebase.auth().signInWithRedirect(provider);
  173.         }
  174.        
  175.         firebase.auth().onAuthStateChanged(function(user) {
  176.           if (user) {
  177.               userId = user["uid"];
  178.             firebase.database().ref('users/' + user["uid"] + '/notes').once('value').then(function(snapshot) {
  179.                 items = snapshot.val();
  180.                 $(".notes").empty();
  181.                 for(note in items){
  182.                     append = '<div class="entry" data-key="'+note+'"><p>'+items[note]+'</p></div>';
  183.                     $(".notes").append(append)
  184.                 }
  185.             });
  186.           } else {
  187.             firebase.auth().getRedirectResult().then(function(result) {
  188.                 if (result.credential) {
  189.                 // This gives you a Google Access Token. You can use it to access the Google API.
  190.                     var token = result.credential.accessToken;
  191.                 // ...
  192.                 }
  193.               // The signed-in user info.
  194.                 var user = result.user;
  195.                 console.log(user);
  196.                 console.log(user["uid"]);
  197.                 userId = user["uid"];
  198.                 firebase.database().ref('users/' + user["uid"]).once('value').then(function(snapshot) {
  199.                     if(snapshot.val() == null){
  200.                         alert("new");
  201.                         firebase.database().ref('users/' + user["uid"]).set({
  202.                             email: user["email"],
  203.                             photo: user["photoURL"],
  204.                         });
  205.                     } else {
  206.                         firebase.database().ref('users/' + userId + '/notes').once('value').then(function(snapshot) {
  207.                             items = snapshot.val();
  208.                             $(".notes").empty();
  209.                             for(note in items){
  210.                                 append = '<div class="entry"><p>'+items[note]+'</p></div>';
  211.                                 $(".notes").append(append);
  212.                             }
  213.                         });
  214.                     }
  215.                 });
  216.  
  217.             }).catch(function(error) {
  218.               // Handle Errors here.
  219.                 var errorCode = error.code;
  220.                 var errorMessage = error.message;
  221.                 // The email of the user's account used.
  222.                 var email = error.email;
  223.                 // The firebase.auth.AuthCredential type that was used.
  224.                 var credential = error.credential;
  225.               // ...
  226.             });
  227.        
  228.           }
  229.         });    
  230.            
  231.        
  232.         function newTodo(){
  233.             getVal = document.getElementById("add").value;
  234.             firebase.database().ref('users/' + userId + '/notes').push(getVal);
  235.             document.getElementsByClassName("notes")[0].innerHTML += '<div class="entry"><p>'+getVal+'</p></div>';
  236.         }
  237.        
  238.         function del(e){
  239.             getKey = $(e).data("key");
  240.             firebase.database().ref('users/' + userId + '/notes').child(getKey).remove();
  241.             $(e).hide(200);
  242.         }
  243.        
  244.         document.addEventListener('click',function(e){
  245.             if(e.target && e.target.className == 'entry'){
  246.                getKey = e.target.getAttribute("data-key");
  247.                 firebase.database().ref('users/' + userId + '/notes').child(getKey).remove();
  248.                 e.target.style.display = "none";
  249.              }
  250.          });
  251.  
  252.     </script>
  253.    
  254. </body>
  255. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement