Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

复制生成的 URL 时,为 URL 添加 https:// #40

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ <h5 class="modal-title" id="exampleModalLabel">Result</h5>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js" integrity="sha256-pasqAKBDmFT4eHoN2ndd6lN370kFiGUFyTiUHWhU7k8=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha256-WqU1JavFxSAMcLP2WIOI+GB2zWmShMI82mTpLDcqFUg=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/main.js" crossorigin="anonymous"></script>
<script src="https://gcore.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js" integrity="sha256-pasqAKBDmFT4eHoN2ndd6lN370kFiGUFyTiUHWhU7k8=" crossorigin="anonymous"></script>
<script src="https://gcore.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://gcore.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha256-WqU1JavFxSAMcLP2WIOI+GB2zWmShMI82mTpLDcqFUg=" crossorigin="anonymous"></script>
<script src="https://gcore.jsdelivr.net/gh/xyTom/Url-Shorten-Worker@gh-pages/main.js" crossorigin="anonymous"></script>
</body>
</html>
</html>
68 changes: 68 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
let res
function shorturl() {
if (document.querySelector("#text").value == "") {
alert("Url cannot be empty!")
return
}

document.getElementById("searchbtn").disabled = true;
document.getElementById("searchbtn").innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>Please wait...';
fetch(window.location.pathname, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url: document.querySelector("#text").value })
}).then(function (response) {
return response.json();
})
.then(function (myJson) {
res = myJson;
document.getElementById("searchbtn").disabled = false;
document.getElementById("searchbtn").innerHTML = ' Shorten it';
if (res.key !== "")
document.getElementById("result").innerHTML = window.location.host + res.key;
$('#exampleModal').modal('show')
}).catch(function (err) {
alert("Unknow error. Please retry!");
console.log(err);
document.getElementById("searchbtn").disabled = false;
document.getElementById("searchbtn").innerHTML = ' Shorten it';
})
}
function copyurl(id, attr) {
let target = null;

if (attr) {
target = document.createElement('div');
target.id = 'tempTarget';
target.style.opacity = '0';
if (id) {
let curNode = document.querySelector('#' + id);
target.innerText = curNode[attr];
} else {
target.innerText = attr;
}
document.body.appendChild(target);
} else {
target = document.querySelector('#' + id);
}

try {
navigator.clipboard.writeText("https://" + target.innerText);
console.log('Page URL copied to clipboard');
} catch (err) {
console.error('Failed to copy: ', err);
}

if (attr) {
// remove temp target
target.parentElement.removeChild(target);
}
}
$(function () {
$('[data-toggle="popover"]').popover()
})
console.log("https://github.com/xyTom/Url-Shorten-Worker/")
let notice = "Notice: This service is for demonstration purposes only and the generated short links will automatically expire after 24 hours."
if (window.location.host == "5it.me") {
document.getElementById("notice").innerHTML = notice
}