index.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Docker 镜像代理加速</title>
  7. <link rel="icon" href="https://cdn.jsdelivr.net/gh/dqzboy/Blog-Image/BlogCourse/docker-proxy.png" type="image/png">
  8. <style>
  9. body {
  10. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Lato', 'Helvetica', 'Arial', sans-serif;
  11. line-height: 1.6;
  12. color: #24292e;
  13. margin: 0;
  14. padding: 0;
  15. background-color: #f6f8fa;
  16. display: flex;
  17. flex-direction: column;
  18. min-height: 100vh;
  19. }
  20. .header {
  21. background-color: #ffffff;
  22. box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  23. padding: 10px 30px;
  24. display: flex;
  25. justify-content: center;
  26. align-items: center;
  27. flex-wrap: wrap;
  28. }
  29. .header-content {
  30. display: flex;
  31. align-items: center;
  32. justify-content: space-between;
  33. width: 100%;
  34. max-width: 1200px;
  35. }
  36. .logo {
  37. max-height: 70px;
  38. }
  39. .nav-menu {
  40. display: flex;
  41. gap: 20px;
  42. font-size: 18px;
  43. margin-left: auto;
  44. }
  45. .nav-menu a {
  46. color: #0366d6;
  47. text-decoration: none;
  48. font-weight: 500;
  49. transition: color 0.3s;
  50. }
  51. .nav-menu a:hover {
  52. color: #0056b3;
  53. }
  54. .container {
  55. max-width: 800px;
  56. width: 90%;
  57. margin: 20px auto;
  58. background: white;
  59. padding: 20px;
  60. border-radius: 8px;
  61. box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  62. flex-grow: 1;
  63. position: relative;
  64. }
  65. h1, h2 {
  66. border-bottom: 2px solid #eaecef;
  67. padding-bottom: 0.5em;
  68. margin-bottom: 1em;
  69. color: #0366d6;
  70. }
  71. .input-group {
  72. margin-bottom: 30px;
  73. display: flex;
  74. flex-direction: column;
  75. }
  76. input[type="text"] {
  77. width: 100%;
  78. padding: 12px;
  79. font-size: 16px;
  80. border: 1px solid #d1d5da;
  81. border-radius: 4px;
  82. margin-bottom: 15px;
  83. box-sizing: border-box;
  84. }
  85. button {
  86. padding: 12px 20px;
  87. background-color: #2ea44f;
  88. color: white;
  89. border: none;
  90. border-radius: 4px;
  91. cursor: pointer;
  92. font-size: 16px;
  93. transition: background-color 0.3s;
  94. align-self: flex-start;
  95. }
  96. button:hover {
  97. background-color: #2c974b;
  98. }
  99. .carousel {
  100. width: 100%;
  101. height: 300px;
  102. display: flex;
  103. justify-content: center;
  104. align-items: center;
  105. perspective: 1000px;
  106. position: relative;
  107. margin-top: 30px;
  108. margin-bottom: 30px;
  109. }
  110. .carousel-inner {
  111. position: relative;
  112. width: 50%;
  113. height: 100%;
  114. transform-style: preserve-3d;
  115. transform: translateZ(-300px);
  116. transition: transform 1s;
  117. }
  118. .carousel-item {
  119. position: absolute;
  120. width: 70%;
  121. height: 100%;
  122. left: 50%;
  123. top: 0;
  124. transform-origin: center center;
  125. transition: transform 1s, opacity 1s;
  126. opacity: 0.5;
  127. }
  128. .carousel-item.active {
  129. transform: translateX(-50%) translateZ(300px);
  130. opacity: 1;
  131. }
  132. .carousel-item.left {
  133. transform: translateX(-150%) translateZ(100px) rotateY(30deg);
  134. }
  135. .carousel-item.right {
  136. transform: translateX(50%) translateZ(100px) rotateY(-30deg);
  137. }
  138. .carousel-control {
  139. position: absolute;
  140. top: 50%;
  141. transform: translateY(-50%);
  142. font-size: 2em;
  143. cursor: pointer;
  144. }
  145. .carousel-control.left {
  146. left: 10px;
  147. }
  148. .carousel-control.right {
  149. right: 10px;
  150. }
  151. pre {
  152. background-color: #f6f8fa;
  153. border-radius: 4px;
  154. padding: 16px;
  155. overflow: auto;
  156. font-size: 14px;
  157. border: 1px solid #e1e4e8;
  158. position: relative;
  159. }
  160. .copy-btn {
  161. position: absolute;
  162. top: 8px;
  163. right: 8px;
  164. padding: 6px 12px;
  165. font-size: 12px;
  166. background-color: #f0f0f0;
  167. color: #333;
  168. border: none;
  169. border-radius: 4px;
  170. cursor: pointer;
  171. transition: background-color 0.3s, color 0.3s;
  172. font-family: 'Arial', sans-serif;
  173. font-weight: 500;
  174. border-radius: 12px;
  175. }
  176. .copy-btn:hover {
  177. background-color: #e0e0e0;
  178. color: #000;
  179. }
  180. .step {
  181. margin-bottom: 25px;
  182. background-color: #fff;
  183. border: 1px solid #e1e4e8;
  184. border-radius: 6px;
  185. padding: 20px;
  186. }
  187. .step h3 {
  188. margin-top: 0;
  189. color: #24292e;
  190. }
  191. .footer {
  192. background-color: #f6f8fa;
  193. color: #6a737d;
  194. text-align: center;
  195. padding: 20px;
  196. margin-top: 20px;
  197. }
  198. .footer a {
  199. color: #58a6ff;
  200. text-decoration: none;
  201. }
  202. .footer a:hover {
  203. text-decoration: underline;
  204. }
  205. #backToTopBtn {
  206. display: none;
  207. position: fixed;
  208. bottom: 20px;
  209. right: 20px;
  210. z-index: 100;
  211. font-size: 16px;
  212. padding: 10px;
  213. background-color: #0366d6;
  214. color: white;
  215. border: none;
  216. border-radius: 50%;
  217. cursor: pointer;
  218. box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  219. }
  220. #backToTopBtn:hover {
  221. background-color: #0256b9;
  222. }
  223. #backToTopBtn::after {
  224. content: '返回顶部';
  225. display: none;
  226. position: absolute;
  227. bottom: 50px;
  228. right: 0;
  229. padding: 5px 10px;
  230. background-color: #333;
  231. color: white;
  232. border-radius: 5px;
  233. white-space: nowrap;
  234. }
  235. #backToTopBtn:hover::after {
  236. display: block;
  237. }
  238. @media (max-width: 768px) {
  239. .nav-menu {
  240. display: none;
  241. }
  242. .header-content {
  243. flex-direction: column;
  244. }
  245. .logo {
  246. margin-bottom: 10px;
  247. }
  248. .input-group {
  249. flex-direction: column;
  250. }
  251. .container {
  252. width: 100%;
  253. padding: 10px;
  254. }
  255. .carousel {
  256. height: 300px;
  257. }
  258. .carousel-item {
  259. width: 80%;
  260. height: 70%;
  261. left: 10%;
  262. }
  263. }
  264. @media (min-width: 769px) {
  265. .nav-menu {
  266. display: flex;
  267. }
  268. }
  269. .notification {
  270. display: none;
  271. position: absolute;
  272. top: 7px;
  273. left: 87%;
  274. transform: translateX(-50%);
  275. background-color: #333;
  276. color: #fff;
  277. padding: 5px 10px;
  278. border-radius: 5px;
  279. font-size: 12px;
  280. opacity: 0;
  281. transition: opacity 0.5s ease-in-out;
  282. z-index: 1000;
  283. }
  284. </style>
  285. </head>
  286. <body>
  287. <!-- 页眉 -->
  288. <header class="header">
  289. <div class="header-content">
  290. <img src="https://cdn.jsdelivr.net/gh/dqzboy/Blog-Image/BlogCourse/docker-proxy.png" alt="Logo" class="logo">
  291. <nav class="nav-menu" id="navMenu">
  292. <!-- 菜单项将通过 JavaScript 动态加载 -->
  293. </nav>
  294. </div>
  295. </header>
  296. <!-- 内容容器 -->
  297. <div class="container">
  298. <h1>Docker 镜像代理加速</h1>
  299. <div class="input-group">
  300. <input type="text" id="imageInput" placeholder="输入 Docker 镜像,例如:nginx 或 mysql:5.7">
  301. <button onclick="generateCommands()">获取加速命令</button>
  302. </div>
  303. <!-- 广告容器 -->
  304. <div class="carousel" id="carousel">
  305. <div class="carousel-inner" id="carouselInner">
  306. <!-- 图片将在 JavaScript 中加载 -->
  307. </div>
  308. <div class="carousel-control left" onclick="prevSlide()">&#10094;</div>
  309. <div class="carousel-control right" onclick="nextSlide()">&#10095;</div>
  310. </div>
  311. <!-- 结果容器 -->
  312. <div id="result" style="display:none;">
  313. <h2>加速命令</h2>
  314. <div id="commandsContainer"></div>
  315. </div>
  316. </div>
  317. <!-- 页脚 -->
  318. <footer class="footer">
  319. <p>Copyright © <span id="currentYear"></span> All Rights Reserved. <a href="https://github.com/dqzboy/Docker-Proxy" target="_blank" rel="noopener noreferrer">Docker-Proxy</a> 版权所有</p>
  320. </footer>
  321. <!-- 返回顶部按钮 -->
  322. <button id="backToTopBtn" onclick="scrollToTop()">⌃</button>
  323. <script>
  324. // 设置当前年份
  325. document.getElementById('currentYear').textContent = new Date().getFullYear();
  326. let proxyDomain = ''; // 默认代理加速地址
  327. let currentIndex = 0;
  328. let items = [];
  329. // 生成加速命令
  330. function generateCommands() {
  331. const imageInput = document.getElementById('imageInput').value.trim();
  332. if (!imageInput) {
  333. alert('请输入 Docker 镜像');
  334. return;
  335. }
  336. let [imageName, tag] = imageInput.split(':');
  337. tag = tag || 'latest';
  338. let originalImage = `${imageName}:${tag}`;
  339. let proxyImage = '';
  340. if (!imageName.includes('/')) {
  341. proxyImage = `${proxyDomain}/library/${imageName}:${tag}`;
  342. } else {
  343. proxyImage = `${proxyDomain}/${imageName}:${tag}`;
  344. }
  345. const commands = [
  346. { title: "原始拉取命令", cmd: `docker pull ${originalImage}` },
  347. { title: "代理拉取镜像", cmd: `docker pull ${proxyImage}` },
  348. { title: "重命名镜像", cmd: `docker tag ${proxyImage} ${originalImage}` },
  349. { title: "删除代理镜像", cmd: `docker rmi ${proxyImage}` }
  350. ];
  351. const resultDiv = document.getElementById('result');
  352. const container = document.getElementById('commandsContainer');
  353. container.innerHTML = '';
  354. // 将生成的命令添加到结果容器中
  355. commands.forEach((command, index) => {
  356. const cmdDiv = document.createElement('div');
  357. cmdDiv.className = 'step';
  358. cmdDiv.innerHTML = `
  359. <h3>${index + 1}. ${command.title}</h3> <pre><code>${command.cmd}</code><div id="copyNotification${index}" class="notification">已复制!</div><button class="copy-btn" onclick="copyToClipboard('${command.cmd}', 'copyNotification${index}')">复制</button></pre>
  360. `;
  361. container.appendChild(cmdDiv);
  362. });
  363. // 显示结果并隐藏广告
  364. resultDiv.style.display = 'block';
  365. document.getElementById('carousel').style.display = 'none';
  366. document.getElementById('backToTopBtn').style.display = 'block';
  367. }
  368. // 复制命令到剪贴板
  369. function copyToClipboard(text, notificationId) {
  370. if (navigator.clipboard && navigator.clipboard.writeText) {
  371. navigator.clipboard.writeText(text).then(() => {
  372. showNotification(notificationId);
  373. }, (err) => {
  374. console.error('无法复制文本: ', err);
  375. });
  376. } else {
  377. const textarea = document.createElement('textarea');
  378. textarea.value = text;
  379. document.body.appendChild(textarea);
  380. textarea.select();
  381. document.execCommand('copy');
  382. document.body.removeChild(textarea);
  383. showNotification(notificationId);
  384. }
  385. }
  386. function showNotification(notificationId) {
  387. var notification = document.getElementById(notificationId);
  388. notification.style.display = 'block';
  389. notification.style.opacity = '1';
  390. // 在2秒后隐藏提示
  391. setTimeout(function() {
  392. notification.style.opacity = '0';
  393. setTimeout(function() {
  394. notification.style.display = 'none';
  395. }, 500);
  396. }, 2000);
  397. }
  398. // 滚动到顶部
  399. function scrollToTop() {
  400. window.scrollTo({
  401. top: 0,
  402. behavior: 'smooth'
  403. });
  404. }
  405. let autoPlayTimer; // 用于存储自动播放的定时器
  406. // 更新轮播图
  407. function updateCarousel() {
  408. items.forEach((item, index) => {
  409. item.classList.remove('active', 'left', 'right');
  410. if (index === currentIndex) {
  411. item.classList.add('active');
  412. } else if (index === (currentIndex - 1 + items.length) % items.length) {
  413. item.classList.add('left');
  414. } else if (index === (currentIndex + 1) % items.length) {
  415. item.classList.add('right');
  416. }
  417. });
  418. }
  419. function prevSlide() {
  420. currentIndex = (currentIndex - 1 + items.length) % items.length;
  421. updateCarousel();
  422. resetAutoPlay(); // 重置自动播放计时器
  423. }
  424. function nextSlide() {
  425. currentIndex = (currentIndex + 1) % items.length;
  426. updateCarousel();
  427. resetAutoPlay(); // 重置自动播放计时器
  428. }
  429. // 开始自动播放
  430. function startAutoPlay() {
  431. autoPlayTimer = setInterval(nextSlide, 10000); // 每10秒自动切换到下一张
  432. }
  433. // 重置自动播放计时器
  434. function resetAutoPlay() {
  435. clearInterval(autoPlayTimer);
  436. startAutoPlay();
  437. }
  438. // 获取并加载配置
  439. async function loadConfig() {
  440. try {
  441. const response = await fetch('/api/config');
  442. const config = await response.json();
  443. if (config.logo) {
  444. document.querySelector('.logo').src = config.logo;
  445. }
  446. if (config.menuItems && Array.isArray(config.menuItems)) {
  447. const navMenu = document.getElementById('navMenu');
  448. navMenu.innerHTML = ''; // 清空菜单
  449. config.menuItems.forEach(item => {
  450. const a = document.createElement('a');
  451. a.href = item.link;
  452. a.textContent = item.text;
  453. if (item.newTab) {
  454. a.target = '_blank';
  455. }
  456. navMenu.appendChild(a);
  457. });
  458. }
  459. if (config.adImages && Array.isArray(config.adImages)) {
  460. const carouselInner = document.getElementById('carouselInner');
  461. carouselInner.innerHTML = ''; // 清空广告容器
  462. config.adImages.forEach((ad, index) => {
  463. const adItem = document.createElement('div');
  464. adItem.className = 'carousel-item';
  465. if (index === 0) {
  466. adItem.classList.add('active');
  467. }
  468. const adImage = document.createElement('img');
  469. adImage.src = ad.url;
  470. adImage.alt = ad.alt || '广告图片';
  471. adImage.style.width = "100%";
  472. adImage.style.height = "100%";
  473. adItem.appendChild(adImage);
  474. carouselInner.appendChild(adItem);
  475. // 添加点击事件监听器
  476. adItem.addEventListener('click', function() {
  477. window.open(ad.link, '_blank');
  478. });
  479. // 改变鼠标样式,表明可以点击
  480. adItem.style.cursor = 'pointer';
  481. });
  482. items = document.querySelectorAll('.carousel-item');
  483. updateCarousel();
  484. startAutoPlay(); // 启动自动播放
  485. }
  486. if (config.proxyDomain) {
  487. proxyDomain = config.proxyDomain;
  488. }
  489. } catch (error) {
  490. console.error('加载配置失败:', error);
  491. }
  492. }
  493. loadConfig();
  494. // 当页面不可见时暂停自动播放,可见时恢复
  495. document.addEventListener("visibilitychange", function() {
  496. if (document.hidden) {
  497. clearInterval(autoPlayTimer);
  498. } else {
  499. startAutoPlay();
  500. }
  501. });
  502. </script>
  503. </body>
  504. </html>