"url shortner"
Bootstrap 3.0.0 Snippet by evarevirus

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <!DOCTYPE html><html lang='en' class=''> <head><script src='//production-assets.codepen.io/assets/editor/live/console_runner-079c09a0e3b9ff743e39ee2d5637b9216b3545af0de366d4b9aad9dc87e26bfd.js'></script><script src='//production-assets.codepen.io/assets/editor/live/events_runner-73716630c22bbc8cff4bd0f07b135f00a0bdc5d14629260c3ec49e5606f98fdd.js'></script><script src='//production-assets.codepen.io/assets/editor/live/css_live_reload_init-2c0dc5167d60a5af3ee189d570b1835129687ea2a61bee3513dee3a50c115a77.js'></script><meta charset='UTF-8'><meta name="robots" content="noindex"><link rel="shortcut icon" type="image/x-icon" href="//production-assets.codepen.io/assets/favicon/favicon-8ea04875e70c4b0bb41da869e81236e54394d63638a1ef12fa558a4a835f1164.ico" /><link rel="mask-icon" type="" href="//production-assets.codepen.io/assets/favicon/logo-pin-f2d2b6d2c61838f7e76325261b7195c27224080bc099486ddd6dccb469b8e8e6.svg" color="#111" /><link rel="canonical" href="https://codepen.io/yasminzy/pen/jaXBvX" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://fonts.googleapis.com/css?family=Roboto:400" rel="stylesheet"> <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css'> <style class="cp-pen-styles">*, *::before, *::after { -webkit-box-sizing: border-box; box-sizing: border-box; } body { font-family: "Roboto", sans-serif; font-weight: 400; line-height: 1.5; text-align: center; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cg fill-rule='evenodd'%3E%3Cg id='Artboard-5' fill='%23111111' fill-opacity='0.1' fill-rule='nonzero'%3E%3Cpath d='M6 18h12V6H6v12zM4 4h16v16H4V4z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"); color: #111; opacity: 0; -webkit-animation: fade 2.5s 0s forwards normal running; animation: fade 2.5s 0s forwards normal running; } @-webkit-keyframes fade { 100% { opacity: 1; } } @keyframes fade { 100% { opacity: 1; } } @media (min-width: 576px) { body { text-align: left; } } #app { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-align: center; -ms-flex-align: center; align-items: center; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; height: 100vh; width: 100vw; padding: 1rem; } main { max-width: 720px; width: 100%; display: grid; grid-row-gap: 1rem; background-color: white; -webkit-box-shadow: 0 10px 20px rgba(17, 17, 17, 0.125), 0 5px 5px rgba(17, 17, 17, 0.25); box-shadow: 0 10px 20px rgba(17, 17, 17, 0.125), 0 5px 5px rgba(17, 17, 17, 0.25); } @media (min-width: 576px) { main { grid-row-gap: 0; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 3fr 1fr; } } @media (min-width: 576px) { h1, .buttons { grid-column: 1/3; } } h1, label { padding: 0.5rem 1rem; } label { display: block; background-color: #111; color: white; } input, button { font-family: inherit; line-height: inherit; color: inherit; border: 0; padding: 1rem; } input { -webkit-box-sizing: border-box; box-sizing: border-box; width: 100%; } section { height: 100%; max-width: calc(100vw - 2rem); display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -ms-flex-align: center; align-items: center; background-color: #111; color: white; } section p { margin-bottom: 0; margin-top: 0; padding: 1rem; word-break: break-all; } .buttons { display: -webkit-box; display: -ms-flexbox; display: flex; } button { cursor: pointer; -webkit-box-flex: 1; -ms-flex: 1; flex: 1; background-color: transparent; } button:hover { background-color: rgba(17, 17, 17, 0.75); color: white; -webkit-transition: all 0.25s; transition: all 0.25s; } </style></head><body> <div id="app"> <main> <h1>URL Shortener</h1> <div> <label>URL</label> <input type="text" placeholder="https://www.yasminzy.com" v-model="inputUrl"> </div> <section v-html="result"></section> <div class="buttons"> <button v-on:click="expandUrl">Expand</button> <button v-on:click="shortenUrl">Shorten</button> </div> </main> </div> <script src='//production-assets.codepen.io/assets/common/stopExecutionOnTimeout-b2a7b3fe212eaa732349046d8416e00a9dec26eb7fd347590fbced3ab38af52e.js'></script><script src='https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.3/vue.min.js'></script> <script >new Vue({ el: "#app", data: { apiKey: "AIzaSyCSetuPyxYQDVm7ZDIov4uujZZAz8U13uE", inputUrl: "", result: "" }, methods: { expandUrl: async function() { try { const urlToExpand = `https://www.googleapis.com/urlshortener/v1/url?shortUrl=${this .inputUrl}&key=${this.apiKey}`; let response = await fetch(urlToExpand); if (response.ok) { let jsonResponse = await response.json(); this.result = `<p>${jsonResponse.longUrl}</p>`; return jsonResponse; } } catch (error) { console.log(error); } }, shortenUrl: async function() { try { const url = `https://www.googleapis.com/urlshortener/v1/url?key=${this .apiKey}`; let response = await fetch(url, { method: "POST", headers: { "Content-type": "application/json" }, body: JSON.stringify({ longUrl: this.inputUrl }) }); if (response.ok) { let jsonResponse = await response.json(); this.result = `<p>${jsonResponse.id}</p>`; return jsonResponse; } } catch (error) { console.log(error); } } } }); //# sourceURL=pen.js </script> </body></html>

Related: See More


Questions / Comments: