新增縮網址服務
This commit is contained in:
@ -3,6 +3,25 @@ body {
|
|||||||
background-size: cover;
|
background-size: cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#urlBox {
|
||||||
|
padding: 10px 0 0 5px;
|
||||||
|
border: 1px solid rgba(0,0,0,.125);
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#urlBox .url {
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#urlBox .url input {
|
||||||
|
width: 100%;
|
||||||
|
font-size: 16px;
|
||||||
|
line-height: 32px;
|
||||||
|
color: #000;
|
||||||
|
border: none;
|
||||||
|
border-bottom: 1px solid rgba(0,0,0,.125);
|
||||||
|
}
|
||||||
|
|
||||||
#content {
|
#content {
|
||||||
background-color: white;
|
background-color: white;
|
||||||
opacity: 0.87;
|
opacity: 0.87;
|
||||||
|
33
index.html
33
index.html
@ -7,11 +7,10 @@
|
|||||||
<title>我們都是企業家!</title>
|
<title>我們都是企業家!</title>
|
||||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
||||||
<link rel="stylesheet" href="css/style.css" type="text/css">
|
<link rel="stylesheet" href="css/style.css" type="text/css">
|
||||||
|
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div id="content" class="container">
|
<div id="content" class="container">
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<h1 class="text-center">工業推手一世紀,企業搖籃一百年</h1>
|
<h1 class="text-center">工業推手一世紀,企業搖籃一百年</h1>
|
||||||
<marquee scrollamount="12">北科畢業人才企業最愛用!!!</marquee>
|
<marquee scrollamount="12">北科畢業人才企業最愛用!!!</marquee>
|
||||||
@ -26,6 +25,27 @@
|
|||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
<h2 class="text-center"><code>縮網址服務</code></h2>
|
||||||
|
<div id="urlBox" class="container">
|
||||||
|
<div class="urls"></div>
|
||||||
|
<div class="url row">
|
||||||
|
<p class="col-md-4 col-6">
|
||||||
|
<input class="text-center short-code" name="short-code" type="text" placeholder="別名,可留空">
|
||||||
|
</p>
|
||||||
|
<p class="col-md-8 col-6">
|
||||||
|
<input class="text-center target-url" name="target-url" type="text" placeholder="網址,例如:https://www.ntut.edu.tw/">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p class="col-12"></p>
|
||||||
|
|
||||||
|
<p class="col-md-4 col-sm-2"></p>
|
||||||
|
<p class="col-md-4 col-sm-8 col-12">
|
||||||
|
<a class="btn btn-primary" style="width: 100%;" href="javascript:" onclick="shortenUrl()">縮起來!</a>
|
||||||
|
</p>
|
||||||
|
<p class="col-md-4 col-sm-2"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="websites col-lg-6">
|
<div class="websites col-lg-6">
|
||||||
<h2 class="text-center"><code>好玩ㄉ網站</code></h2>
|
<h2 class="text-center"><code>好玩ㄉ網站</code></h2>
|
||||||
@ -35,11 +55,6 @@
|
|||||||
<br>
|
<br>
|
||||||
<span>程式碼託管平台</span>
|
<span>程式碼託管平台</span>
|
||||||
</li>
|
</li>
|
||||||
<li class="list-group-item list-group-item-action">
|
|
||||||
<a href="https://ntut.com.tw/url" target="_blank">NTUT URL Shortener</a>
|
|
||||||
<br>
|
|
||||||
<span>縮網址服務</span>
|
|
||||||
</li>
|
|
||||||
<li class="list-group-item list-group-item-action">
|
<li class="list-group-item list-group-item-action">
|
||||||
<a href="https://yuren-tw.github.io/textRevealer/" target="_blank">Text Revealer</a>
|
<a href="https://yuren-tw.github.io/textRevealer/" target="_blank">Text Revealer</a>
|
||||||
<br>
|
<br>
|
||||||
@ -54,7 +69,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="gist col-lg-6">
|
<div class="gist col-lg-6">
|
||||||
<h2 class="text-center"><code>好用ㄉ Script</code></h2>
|
<h2 class="text-center"><code>好用 Script</code></h2>
|
||||||
<script src="https://gist.github.com/PinLin/3f6c1885d3c22d9fbf6a726788778112.js"></script>
|
<script src="https://gist.github.com/PinLin/3f6c1885d3c22d9fbf6a726788778112.js"></script>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -71,7 +86,7 @@
|
|||||||
<footer>
|
<footer>
|
||||||
<p class="text-center">(ˊ・ω・ˋ)(ˊ・ω・ˋ)(ˊ・ω・ˋ)(ˊ・ω・ˋ)(ˊ・ω・ˋ)(ˊ・ω・ˋ)</p>
|
<p class="text-center">(ˊ・ω・ˋ)(ˊ・ω・ˋ)(ˊ・ω・ˋ)(ˊ・ω・ˋ)(ˊ・ω・ˋ)(ˊ・ω・ˋ)</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
<script src="js/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
54
js/main.js
Normal file
54
js/main.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
let backend = 'https://ntut.com.tw'
|
||||||
|
|
||||||
|
const shortenUrl = async () => {
|
||||||
|
let shortCode = $('#urlBox .short-code')[0].value || null
|
||||||
|
let url = $('#urlBox .target-url')[0].value
|
||||||
|
|
||||||
|
if (!url) {
|
||||||
|
alert("URL is empty!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
request({ shortCode, url })
|
||||||
|
.done((res) => {
|
||||||
|
console.log(res)
|
||||||
|
|
||||||
|
addNewRow(res)
|
||||||
|
})
|
||||||
|
.fail((err) => {
|
||||||
|
console.log(err)
|
||||||
|
|
||||||
|
if (err.status == 409) {
|
||||||
|
alert("This code has been used.")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alert("Failed to establish connection.")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const addNewRow = (data) => {
|
||||||
|
let view = $('#urlBox .urls')
|
||||||
|
|
||||||
|
view.append($(`
|
||||||
|
<div class="url row">
|
||||||
|
<p class="text-center col-md-4 col-6">ntut.com.tw/${data.shortCode}</p>
|
||||||
|
<p class="text-center col-md-8 col-6">${data.url}</p>
|
||||||
|
</div>
|
||||||
|
`))
|
||||||
|
}
|
||||||
|
|
||||||
|
const request = ({ shortCode, url }) => {
|
||||||
|
return $.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
url: `${backend}/api/shortUrl`,
|
||||||
|
data: JSON.stringify({
|
||||||
|
shortCode, url
|
||||||
|
}),
|
||||||
|
processData: false,
|
||||||
|
contentType: 'application/json; charset=UTF-8'
|
||||||
|
})
|
||||||
|
}
|
Reference in New Issue
Block a user