index.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>MyUrls</title>
  5. <meta charset="utf-8" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
  7. <link rel="icon" href="./favicon.ico">
  8. <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/stilleshan/dockerfiles/myurls/public/css/main.css" />
  9. <script src="https://unpkg.com/[email protected]/dist/vue.min.js"></script>
  10. <script src="https://unpkg.com/[email protected]/dist/axios.min.js"></script>
  11. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  12. <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  13. </head>
  14. <body class="is-preload">
  15. <div id="app">
  16. <div id="page-wrapper">
  17. <!-- Header -->
  18. <header id="header">
  19. <h1><a href="index.html">MyUrls</a></h1>
  20. <nav id="nav">
  21. <ul>
  22. <li><a href="index.html">首页</a></li>
  23. <li><a href="https://sub.ops.ci" target="_blank">订阅转换</a></li>
  24. <li><a href="https://github.com/stilleshan/dockerfiles/tree/main/myurls" target="_blank">GitHub</a></li>
  25. </ul>
  26. </nav>
  27. </header>
  28. <!-- Main -->
  29. <section id="main" class="container medium">
  30. <header>
  31. <h2>MyUrls</h2>
  32. <p>一个轻量级短链接服务</p>
  33. </header>
  34. <div class="box">
  35. <form method="post" action="#">
  36. <div class="row gtr-50 gtr-uniform">
  37. <div class="col-9 col-8-mobilep">
  38. <input type="text" ref="long" v-model="longUrl" value="" placeholder="输入长链接" />
  39. </div>
  40. <div class="col-3 col-4-mobilep">
  41. <ul class="actions special">
  42. <li><input type="button" value="生成链接" @click="doShort()" /></li>
  43. </ul>
  44. </div>
  45. <div class="col-9 col-8-mobilep">
  46. <input type="text" v-model="shortUrl" value="" placeholder="生成短链接" />
  47. </div>
  48. <div class="col-3 col-4-mobilep">
  49. <ul class="actions special">
  50. <li><input type="button" value="复制链接" @click="toCopy(shortUrl)" /></li>
  51. </ul>
  52. </div>
  53. </div>
  54. </form>
  55. </div>
  56. </section>
  57. <!-- Footer -->
  58. <footer id="footer">
  59. <ul class="copyright">
  60. <li>&copy; <a href="https://github.com/stilleshan/dockerfiles/tree/main/myurls" target="_blank">MyUrls</a>.
  61. All rights reserved.</li>
  62. </ul>
  63. </footer>
  64. </div>
  65. </div>
  66. <script>
  67. const backend = 'https://s.ops.ci'
  68. let app = new Vue({
  69. el: "#app",
  70. data() {
  71. return {
  72. longUrl: '',
  73. shortUrl: '',
  74. }
  75. },
  76. methods: {
  77. showDialog(title, msg, level) {
  78. this.$confirm(title, msg, {
  79. showCancelButton: false,
  80. showConfirmButton: false,
  81. type: level,
  82. center: true,
  83. callback: action => {
  84. // console.log('显示成功')
  85. }
  86. })
  87. },
  88. doShort() {
  89. let re = new RegExp('http(s*)://[^\s]*')
  90. if (re.exec(this.longUrl) === null) {
  91. this.showDialog('请输入正确格式的长链接', '错误', 'error');
  92. return
  93. }
  94. let data = new FormData();
  95. data.append("longUrl", btoa(this.longUrl));
  96. data.append("shortKey", this.shortUrl.indexOf('http') < 0 ? this.shortUrl : '');
  97. axios.post(backend + '/short', data, {
  98. header: {
  99. "Content-Type": "application/form-data; charset=utf-8"
  100. }
  101. })
  102. .then(res => {
  103. if (res.data.Code === 1 && res.data.ShortUrl !== "") {
  104. this.shortUrl = res.data.ShortUrl;
  105. this.toCopy(this.shortUrl)
  106. } else {
  107. this.showDialog('短链接获取失败', '错误', 'error');
  108. }
  109. })
  110. .catch(() => {
  111. this.showDialog('短链接获取失败', '错误', 'error');
  112. });
  113. },
  114. toCopy(url) {
  115. if (!url) {
  116. this.showDialog('复制失败 内容为空', '错误', 'error');
  117. } else {
  118. var copyInput = document.createElement('input');
  119. copyInput.setAttribute('value', url);
  120. document.body.appendChild(copyInput);
  121. copyInput.select();
  122. try {
  123. var copyed = document.execCommand('copy');
  124. if (copyed) {
  125. document.body.removeChild(copyInput);
  126. this.showDialog('复制成功 ' + this.shortUrl, '成功', 'success');
  127. }
  128. } catch {
  129. this.showDialog('复制失败', '错误', 'error');
  130. }
  131. }
  132. },
  133. },
  134. })
  135. </script>
  136. <script src="https://cdn.jsdelivr.net/gh/stilleshan/dockerfiles/myurls/public/js/jquery.min.js"></script>
  137. <script src="https://cdn.jsdelivr.net/gh/stilleshan/dockerfiles/myurls/public/js/jquery.dropotron.min.js"></script>
  138. <script src="https://cdn.jsdelivr.net/gh/stilleshan/dockerfiles/myurls/public/js/jquery.scrollex.min.js"></script>
  139. <script src="https://cdn.jsdelivr.net/gh/stilleshan/dockerfiles/myurls/public/js/browser.min.js"></script>
  140. <script src="https://cdn.jsdelivr.net/gh/stilleshan/dockerfiles/myurls/public/js/breakpoints.min.js"></script>
  141. <script src="https://cdn.jsdelivr.net/gh/stilleshan/dockerfiles/myurls/public/js/util.js"></script>
  142. <script src="https://cdn.jsdelivr.net/gh/stilleshan/dockerfiles/myurls/public/js/main.js"></script>
  143. </body>
  144. </html>