随机图片

✨ 点击图片换一张(老婆/猫/狗/二次元) ✨

加载中...


---
layout: hacker/default
---

<style>
/* ========== 主题颜色变量 ========== */
/* 暗色模式(默认) */
:root,
[data-theme="dark"] {
  --bg-color: #0a0a0a;
  --text-color: #e0e0e0;
  --link-color: #0f0;
  --link-hover: #ffcc00;
  --nav-bg: rgba(10, 10, 10, 0.4);
  --border-color: #333;
}

/* 亮色模式 */
[data-theme="light"] {
  --bg-color: #f5f5f5;
  --text-color: #222;
  --link-color: #0066cc;
  --link-hover: #ff6600;
  --nav-bg: rgba(245, 245, 245, 0.9);
  --border-color: #ddd;
}

/* 全局样式 */
body {
  background-color: var(--bg-color);
  color: var(--text-color);
  transition: background-color 0.3s ease, color 0.3s ease;
}

a {
  color: var(--link-color);
  transition: color 0.2s ease;
}

a:hover {
  color: var(--link-hover);
}

/* 导航栏样式 */
.navbar {
  position: sticky;
  top: 0;
  background-color: var(--nav-bg);
  backdrop-filter: blur(4px);
  z-index: 99;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

.nav-links {
  display: flex;
  gap: 20px;
}

.nav-links a {
  text-decoration: none;
  font-size: 1.2rem;
}

.navbar-theme-btn {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  color: var(--link-color);
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s ease;
}

.navbar-theme-btn:hover {
  background-color: rgba(0, 255, 0, 0.2);
  transform: scale(1.02);
}

/* 一言模块样式 */
.hitokoto-box {
  text-align: center;
  margin: 20px auto;
  padding: 10px 20px;
  max-width: 600px;
  font-size: 0.9rem;
  color: var(--text-color);
  opacity: 0.8;
  border-left: 3px solid var(--link-color);
  border-right: 3px solid var(--link-color);
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
}

/* 代码块复制按钮样式 */
.highlight {
  position: relative;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background-color: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--link-color);
  color: var(--link-color);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  font-family: monospace;
  transition: all 0.2s ease;
  z-index: 10;
}

.copy-btn:hover {
  background-color: rgba(0, 255, 0, 0.2);
  color: var(--text-color);
}

.copy-btn.copied {
  border-color: #ffcc00;
  color: #ffcc00;
}
</style>

<!-- 导航栏 -->
<nav class="navbar">
  <div class="nav-links">
    <a href="/bg/">🏠</a>
    <a href="/bg/search/">🔍</a>
    <a href="/bg/about/">📖</a>
  </div>
  <button class="navbar-theme-btn" id="themeToggle" title="切换亮色/暗色模式">🌓</button>
</nav>

<!-- 随机图片(混合多种 API,点击换图) -->
<div style="text-align: center; margin: 10px auto;">
  <img id="randomImg" src="" alt="随机图片" style="max-width: 100%; max-height: 200px; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.2); cursor: pointer;">
  <p style="font-size: 12px; color: #888; margin-top: 5px;">✨ 点击图片换一张(老婆/猫/狗/二次元) ✨</p>
</div>

<script>
// ========== 随机图片功能(混合多种 API) ==========
const imgElement = document.getElementById('randomImg');

// 混合 API 列表 - 每次随机选一个
const mixedApis = [
  // 二次元老婆图(waifu)
  { type: 'direct', name: '老婆图', url: 'https://api.waifu.pics/sfw/waifu?t=' },
  { type: 'direct', name: '猫耳娘', url: 'https://api.waifu.pics/sfw/neko?t=' },
  { type: 'direct', name: '摸头图', url: 'https://api.waifu.pics/sfw/pat?t=' },
  { type: 'direct', name: '拥抱图', url: 'https://api.waifu.pics/sfw/hug?t=' },
  // 随机猫图
  { type: 'direct', name: '猫图', url: 'https://cataas.com/cat?t=' },
  // 随机狗狗图(需要特殊处理,因为返回的是图片URL)
  { type: 'special', name: '狗狗图', url: 'https://random.dog/woof?t=' },
  // 随机狐狸图
  { type: 'json', name: '狐狸图', url: 'https://randomfox.ca/floof/', imgField: 'image' },
  // 原有的二次元 API
  { type: 'json', name: '二次元图1', url: 'https://api.xygeng.cn/img/', imgField: 'img' },
  { type: 'json', name: '二次元图2', url: 'https://api.btstu.cn/sjbz/api.php?lx=dongman&format=json', imgField: 'imgurl' },
  { type: 'direct', name: '二次元图3', url: 'https://www.dmoe.cc/random.php?t=' },
  { type: 'direct', name: '东方Project', url: 'https://img.paulzzh.tech/touhou/random?t=' }
];

const fallbackImages = [
  'https://picsum.photos/id/100/400/200',
  'https://picsum.photos/id/104/400/200',
  'https://picsum.photos/id/106/400/200',
  'https://picsum.photos/id/169/400/200'
];

function useFallbackImage() {
  const randomIndex = Math.floor(Math.random() * fallbackImages.length);
  imgElement.src = fallbackImages[randomIndex];
  console.log('使用备用图片');
}

async function loadRandomImage() {
  // 随机选一个 API
  const api = mixedApis[Math.floor(Math.random() * mixedApis.length)];
  console.log('尝试加载:', api.name, api.url);
  
  try {
    if (api.type === 'direct') {
      // 直接使用 URL(图片本身)
      imgElement.src = api.url + Date.now();
    } else if (api.type === 'special' && api.name === '狗狗图') {
      // 狗狗图 API 返回的是图片文件名,需要拼接完整 URL
      const response = await fetch(api.url + Date.now());
      const filename = await response.text();
      imgElement.src = 'https://random.dog/' + filename;
    } else if (api.type === 'json') {
      // JSON 类型 API,需要解析
      const response = await fetch(api.url + '&t=' + Date.now());
      const data = await response.json();
      let imgUrl = '';
      
      if (api.imgField) {
        imgUrl = data[api.imgField];
      } else if (data.img) {
        imgUrl = data.img;
      } else if (data.url) {
        imgUrl = data.url;
      } else if (data.imgurl) {
        imgUrl = data.imgurl;
      } else if (data.image) {
        imgUrl = data.image;
      } else if (data.file) {
        imgUrl = data.file;
      }
      
      if (imgUrl && imgUrl.startsWith('http')) {
        imgElement.src = imgUrl;
      } else {
        useFallbackImage();
      }
    }
  } catch (error) {
    console.error('API 加载失败:', api.name, error);
    useFallbackImage();
  }
}

// 图片加载失败时的处理
imgElement.onerror = function() {
  console.log('图片加载失败,使用备用');
  useFallbackImage();
};

// 页面加载时随机一张
loadRandomImage();

// 点击图片重新加载
imgElement.addEventListener('click', function() {
  loadRandomImage();
});
</script>

<!-- 一言模块 -->
<div class="hitokoto-box">
  <span id="hitokoto_text">加载中...</span>
</div>

<script>
// 一言功能
fetch('https://v1.hitokoto.cn/')
  .then(response => response.json())
  .then(data => {
    const hitokotoSpan = document.getElementById('hitokoto_text');
    if (hitokotoSpan) {
      hitokotoSpan.innerHTML = `「${data.hitokoto}」 — ${data.from}`;
    }
  })
  .catch(error => {
    console.error('一言加载失败:', error);
    const hitokotoSpan = document.getElementById('hitokoto_text');
    if (hitokotoSpan) {
      hitokotoSpan.innerHTML = '「代码就像写诗,简洁即力量」 — 佚名';
    }
  });
</script>

<!-- 页面内容 -->
<h1 id="静默播放">静默播放</h1>
<p><code class="language-plaintext highlighter-rouge">--no-video --really-quiet</code></p>

<h1 id="设置播放列表循环">设置播放列表循环</h1>
<p><code class="language-plaintext highlighter-rouge">loop-playlist=inf</code></p>

<h1 id="开启播放列表随机播放洗牌">开启播放列表随机播放(洗牌)</h1>
<p><code class="language-plaintext highlighter-rouge">shuffle</code></p>

<h1 id="可选-保存当前的播放列表顺序下次启动时恢复">(可选) 保存当前的播放列表顺序,下次启动时恢复</h1>
<h1 id="write-filename-in-watch-later-configyes">write-filename-in-watch-later-config=yes</h1>
<h1 id="save-position-on-quityes">save-position-on-quit=yes</h1>

<h1 id="可选-当播放列表中的文件播放失败时自动跳到下一个">(可选) 当播放列表中的文件播放失败时,自动跳到下一个</h1>
<h1 id="load-unsafe-playlistsyes">load-unsafe-playlists=yes</h1>

<h1 id="可选-禁用软字幕选择避免字幕选项干扰连续播放">(可选) 禁用软字幕选择,避免字幕选项干扰连续播放</h1>
<h1 id="sidno">sid=no</h1>

<h1 id="可选-禁止在播放开始时暂停确保流畅的随机播放体验">(可选) 禁止在播放开始时暂停,确保流畅的随机播放体验</h1>
<h1 id="no-pause">no-pause</h1>


<!-- 文章最后更新时间 -->

<div style="margin-top: 40px; padding-top: 15px; border-top: 1px solid var(--border-color); font-size: 0.85rem; color: #888; text-align: right;">
  📅 最后更新:2026-04-20 00:00
</div>


<!-- 返回顶部按钮 -->
<button onclick="topFunction()" id="backToTop" title="返回顶部" style="display: none; position: fixed; bottom: 30px; right: 30px; z-index: 99; border: 1px solid #666; outline: none; background-color: rgba(0, 0, 0, 0.5); color: #888; cursor: pointer; padding: 12px 16px; border-radius: 8px; font-size: 16px; font-weight: bold; backdrop-filter: blur(4px);">↑ 顶部</button>

<script>
// ========== 主题切换功能 ==========
(function() {
  const savedTheme = localStorage.getItem('theme') || 'dark';
  document.documentElement.setAttribute('data-theme', savedTheme);
  
  const themeToggle = document.getElementById('themeToggle');
  if (themeToggle) {
    const currentTheme = document.documentElement.getAttribute('data-theme');
    themeToggle.textContent = currentTheme === 'dark' ? '🌓' : '🌞';
    
    // 移除可能存在的旧事件,重新绑定
    const newToggle = themeToggle.cloneNode(true);
    themeToggle.parentNode.replaceChild(newToggle, themeToggle);
    
    const finalToggle = document.getElementById('themeToggle');
    finalToggle.addEventListener('click', function(e) {
      e.preventDefault();
      const current = document.documentElement.getAttribute('data-theme');
      const newTheme = current === 'dark' ? 'light' : 'dark';
      document.documentElement.setAttribute('data-theme', newTheme);
      localStorage.setItem('theme', newTheme);
      finalToggle.textContent = newTheme === 'dark' ? '🌓' : '🌞';
      console.log('主题切换为:', newTheme);
    });
  }
})();

// ========== 代码复制功能 ==========
(function() {
  const codeBlocks = document.querySelectorAll('.highlight');
  codeBlocks.forEach(function(block) {
    if (block.querySelector('.copy-btn')) return;
    
    const btn = document.createElement('button');
    btn.className = 'copy-btn';
    btn.textContent = '复制';
    block.style.position = 'relative';
    block.appendChild(btn);
    
    btn.addEventListener('click', function() {
      const code = block.querySelector('code');
      const text = code ? code.innerText : block.innerText;
      navigator.clipboard.writeText(text).then(function() {
        btn.textContent = '已复制 ✓';
        btn.classList.add('copied');
        setTimeout(function() {
          btn.textContent = '复制';
          btn.classList.remove('copied');
        }, 2000);
      }).catch(function(err) {
        console.error('复制失败:', err);
        btn.textContent = '失败';
        setTimeout(function() {
          btn.textContent = '复制';
        }, 1500);
      });
    });
  });
})();

// ========== 返回顶部功能 ==========
const backToTopBtn = document.getElementById("backToTop");
if (backToTopBtn) {
  window.onscroll = function() {
    if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 300) {
      backToTopBtn.style.display = "block";
    } else {
      backToTopBtn.style.display = "none";
    }
  };
}

function topFunction() {
  window.scrollTo({ top: 0, behavior: 'smooth' });
}
</script>

📅 最后更新:2026-04-20 00:00