|
1 | | -{{ $title := .Get "title" }} {{ $link := .Get "link" }} {{ $timer := .Get |
2 | | -"timer" | default "false" }} {{ if eq $timer "true" }} |
3 | | -<button class="timer-btn" data-link="{{ $link }}">{{ $title }}</button> |
4 | | -<span class="timer-label"></span> |
| 1 | +{{ $title := .Get "title" }} |
| 2 | +{{ $link := .Get "link" }} |
| 3 | +{{ $timer := .Get "timer" | default "false" }} |
| 4 | +{{ $showbutton := .Get "showbutton" | default "true" }} |
| 5 | + |
| 6 | +{{ if eq $timer "true" }} |
| 7 | +<div class="timer-container"> |
| 8 | + {{/* {{ if eq $showbutton "true" }} |
| 9 | + <button class="timer-btn" data-link="{{ $link }}">{{ $title }}</button> |
| 10 | + {{ end }} */}} |
| 11 | + <span class="timer-label"></span> |
| 12 | + <progress class="timer-progress" value="0" max="20"></progress> |
| 13 | +</div> |
| 14 | + |
| 15 | +{{ else if eq $showbutton "true" }} |
| 16 | + <a href="{{ $link }}" class="timer-btn"> |
| 17 | + {{ $title }} |
| 18 | + </a> |
| 19 | +{{ end }} |
| 20 | + |
5 | 21 | <script> |
6 | | - (function () { |
| 22 | + (function link_timer() { |
7 | 23 | var btns = document.querySelectorAll(".timer-btn"); |
8 | 24 | btns.forEach(function (btn) { |
9 | 25 | if (btn.dataset.timerAttached) return; |
10 | 26 | btn.dataset.timerAttached = "true"; |
11 | | - btn.addEventListener("click", function () { |
| 27 | + btn.addEventListener("click", function timer() { |
12 | 28 | if (btn.disabled) return; |
13 | 29 | btn.disabled = true; |
14 | 30 | var label = btn.nextElementSibling; |
15 | | - var countdown = 30; |
| 31 | + var countdown = 20; |
16 | 32 | label.textContent = " Downloading in " + countdown + "sec ..."; |
17 | 33 | var timer = setInterval(function () { |
18 | 34 | countdown--; |
|
25 | 41 | }); |
26 | 42 | }); |
27 | 43 | })(); |
| 44 | + |
| 45 | + window.addEventListener("load", function () { |
| 46 | + var btn = document.querySelector(".timer-btn"); |
| 47 | + var label = document.querySelector(".timer-label"); |
| 48 | + var progress = document.querySelector(".timer-progress"); |
| 49 | + var link = "{{ $link }}"; |
| 50 | + var countdown = 20; |
| 51 | + label.textContent = " Redirecting in " + countdown + "s..."; |
| 52 | + progress.value = 0; |
| 53 | + var timer = setInterval(function () { |
| 54 | + countdown--; |
| 55 | + label.textContent = " Redirecting in " + countdown + "s..."; |
| 56 | + progress.value = 20 - countdown; |
| 57 | + if (countdown <= 0) { |
| 58 | + clearInterval(timer); |
| 59 | + window.location.href = link; |
| 60 | + } |
| 61 | + }, 1000); |
| 62 | + }); |
28 | 63 | </script> |
29 | | -{{ else }} |
30 | | -<a href="{{ $link }}" class="timer-btn"> {{ $title }} </a> |
31 | | -{{ end }} |
| 64 | + |
32 | 65 |
|
33 | 66 | <style> |
34 | 67 | .timer-btn { |
35 | 68 | margin-top: 1.5rem; |
36 | 69 | display: block; |
37 | 70 | padding: 0.5em 1.2em; |
38 | | - background: #007bff; |
| 71 | + background: #d45039; |
39 | 72 | color: #fff; |
40 | 73 | border-radius: 4px; |
41 | 74 | border: none; |
|
58 | 91 | text-align: center; |
59 | 92 | } |
60 | 93 |
|
| 94 | + .timer-progress { |
| 95 | + width: 100%; |
| 96 | + height: 1em; |
| 97 | + border-radius: 6px; |
| 98 | + appearance: none; |
| 99 | + background-color: #e0e0e0; |
| 100 | + overflow: hidden; |
| 101 | + } |
| 102 | + .timer-progress::-webkit-progress-bar { |
| 103 | + background-color: #e0e0e0; |
| 104 | + border-radius: 6px; |
| 105 | + } |
| 106 | + .timer-progress::-webkit-progress-value { |
| 107 | + background-color: #d45039; |
| 108 | + border-radius: 6px; |
| 109 | + transition: width 0.2s; |
| 110 | + } |
| 111 | + .timer-progress::-moz-progress-bar { |
| 112 | + background-color: #d45039; |
| 113 | + border-radius: 6px; |
| 114 | + transition: width 0.2s; |
| 115 | + } |
| 116 | + |
61 | 117 | html:is(.dark) { |
62 | 118 | .timer-btn { |
63 | | - background: #3399ff; |
| 119 | + background: #d45039; |
64 | 120 | color: #eee; |
65 | 121 | border: none; |
66 | 122 | } |
|
71 | 127 | .timer-label { |
72 | 128 | color: #ccc; |
73 | 129 | } |
| 130 | + .timer-progress, |
| 131 | + .timer-progress::-webkit-progress-bar { |
| 132 | + background-color: #222; |
| 133 | + } |
| 134 | + .timer-progress::-webkit-progress-value, |
| 135 | + .timer-progress::-moz-progress-bar { |
| 136 | + background-color: #d45039; |
| 137 | + } |
74 | 138 | } |
75 | 139 | </style> |
0 commit comments