vite-plugin-sw-offline 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-sw-offline",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Vite 插件:Service Worker、离线页模板与构建注入(适用于 Vite H5 / uni-app H5 等)",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -86,6 +86,8 @@
86
86
  display: flex;
87
87
  align-items: center;
88
88
  justify-content: center;
89
+ cursor: pointer;
90
+ -webkit-tap-highlight-color: transparent;
89
91
  }
90
92
 
91
93
  .search-bar-btn svg {
@@ -164,6 +166,27 @@
164
166
  color: #ffffff;
165
167
  box-shadow: 0 4px 16px rgba(74, 124, 255, 0.3);
166
168
  }
169
+
170
+ .copy-toast {
171
+ position: fixed;
172
+ left: 50%;
173
+ bottom: 48px;
174
+ transform: translateX(-50%);
175
+ padding: 10px 20px;
176
+ border-radius: 8px;
177
+ background: rgba(0, 0, 0, 0.78);
178
+ color: #ffffff;
179
+ font-size: 14px;
180
+ line-height: 1.4;
181
+ opacity: 0;
182
+ pointer-events: none;
183
+ transition: opacity 0.2s ease;
184
+ z-index: 1000;
185
+ }
186
+
187
+ .copy-toast.show {
188
+ opacity: 1;
189
+ }
167
190
  </style>
168
191
  </head>
169
192
  <body>
@@ -178,7 +201,7 @@
178
201
  <div class="search-bar-input">
179
202
  <span id="typingText"></span><span class="typing-cursor">|</span>
180
203
  </div>
181
- <div class="search-bar-btn">
204
+ <div class="search-bar-btn" id="copyDomainBtn" role="button" tabindex="0" aria-label="复制域名">
182
205
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
183
206
  <circle cx="11" cy="11" r="7"></circle>
184
207
  <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
@@ -195,10 +218,14 @@
195
218
  </div>
196
219
  </div>
197
220
 
221
+ <div class="copy-toast" id="copyToast" aria-live="polite">复制成功!</div>
222
+
198
223
  <script>
224
+ var offlineDomainText = '__OFFLINE_DOMAIN__';
225
+
199
226
  // 打字机动画
200
227
  (function() {
201
- var text = '__OFFLINE_DOMAIN__';
228
+ var text = offlineDomainText;
202
229
  var el = document.getElementById('typingText');
203
230
  var i = 0;
204
231
  var isDeleting = false;
@@ -232,6 +259,60 @@
232
259
  setTimeout(tick, 600);
233
260
  })();
234
261
 
262
+ // 搜索按钮:复制域名到剪贴板
263
+ (function() {
264
+ var copyBtn = document.getElementById('copyDomainBtn');
265
+ var toast = document.getElementById('copyToast');
266
+ var toastTimer = null;
267
+
268
+ function showCopyToast() {
269
+ toast.classList.add('show');
270
+ if (toastTimer) clearTimeout(toastTimer);
271
+ toastTimer = setTimeout(function() {
272
+ toast.classList.remove('show');
273
+ }, 2000);
274
+ }
275
+
276
+ function copyToClipboard(text) {
277
+ if (navigator.clipboard && navigator.clipboard.writeText) {
278
+ return navigator.clipboard.writeText(text);
279
+ }
280
+ return new Promise(function(resolve, reject) {
281
+ var ta = document.createElement('textarea');
282
+ ta.value = text;
283
+ ta.setAttribute('readonly', '');
284
+ ta.style.position = 'fixed';
285
+ ta.style.left = '-9999px';
286
+ document.body.appendChild(ta);
287
+ ta.select();
288
+ try {
289
+ var ok = document.execCommand('copy');
290
+ document.body.removeChild(ta);
291
+ ok ? resolve() : reject(new Error('copy failed'));
292
+ } catch (err) {
293
+ document.body.removeChild(ta);
294
+ reject(err);
295
+ }
296
+ });
297
+ }
298
+
299
+ function handleCopy() {
300
+ var text = (offlineDomainText || '').trim();
301
+ if (!text) return;
302
+ copyToClipboard(text).then(showCopyToast).catch(function() {
303
+ alert('复制失败,请手动复制');
304
+ });
305
+ }
306
+
307
+ copyBtn.addEventListener('click', handleCopy);
308
+ copyBtn.addEventListener('keydown', function(e) {
309
+ if (e.key === 'Enter' || e.key === ' ') {
310
+ e.preventDefault();
311
+ handleCopy();
312
+ }
313
+ });
314
+ })();
315
+
235
316
  // 尝试从 localStorage 获取客服链接
236
317
  document.getElementById('contactBtn').addEventListener('click', function() {
237
318
  var customerServiceUrl = localStorage.getItem('customerServiceUrl');