Files
WebImageViewer/WebImageViewer/Class/Renderers/HtmlRenderer.cs
T

1990 lines
75 KiB
C#

using System.Text.Encodings.Web;
using System.Text.Json;
using WebImageViewer.Class.Models;
namespace WebImageViewer.Class.Renderers;
/// <summary>
/// WebImageViewerの洗練されたモダンUI HTMLを生成するレンダークラス
/// </summary>
public static class HtmlRenderer
{
private static readonly HtmlEncoder Encoder = HtmlEncoder.Default;
/// <summary>
/// ギャラリー閲覧画面のHTMLを生成します。
/// </summary>
public static string RenderGalleryViewer(GalleryItem gallery)
{
var title = Encoder.Encode(gallery.Title);
var category = Encoder.Encode(gallery.Category);
var circle = !string.IsNullOrEmpty(gallery.Circle) ? Encoder.Encode(gallery.Circle) : null;
var author = !string.IsNullOrEmpty(gallery.Author) ? Encoder.Encode(gallery.Author) : null;
var sourceSite = Encoder.Encode(gallery.SourceSite);
var sourceUrl = Encoder.Encode(gallery.SourceUrl);
var totalPages = gallery.TotalPages;
var galleryJson = JsonSerializer.Serialize(gallery, new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
});
// タグバッジHTMLの生成
var tagsHtml = string.Empty;
if (gallery.Tags.Count > 0)
{
var tagItems = string.Join("\n", gallery.Tags.Select(t => $"<span class=\"tag-pill\">#{Encoder.Encode(t)}</span>"));
tagsHtml = $"""
<div class="info-tags">
{tagItems}
</div>
""";
}
// スクロール用画像リストHTMLの生成
var imagesHtml = string.Join("\n", gallery.Images.Select(img =>
{
var imgUrl = Encoder.Encode(img.ImageUrl);
var altText = Encoder.Encode(img.AltText ?? $"{gallery.Title} {img.PageNumber}ページ");
return $"""
<div class="scroll-image-wrapper" data-page="{img.PageNumber}">
<img src="{imgUrl}" loading="lazy" decoding="async" alt="{altText}" onload="this.classList.add('loaded')" />
<div class="page-badge">{img.PageNumber} / {totalPages}</div>
</div>
""";
}));
// サムネイル一覧HTMLの生成
var thumbsHtml = string.Join("\n", gallery.Images.Select(img =>
{
var thumbUrl = Encoder.Encode(img.ThumbnailUrl ?? img.ImageUrl);
return $"""
<div class="thumb-item" data-page="{img.PageNumber}">
<img src="{thumbUrl}" loading="lazy" alt="{img.PageNumber}" />
<div class="thumb-num">{img.PageNumber}</div>
</div>
""";
}));
var circleHeaderHtml = circle != null ? $"<span>サークル: {circle}</span>" : "";
var authorHeaderHtml = author != null ? $"<span>作者: {author}</span>" : "";
var circleInfoHtml = circle != null ? $"<span>🏢 サークル: <strong>{circle}</strong></span>" : "";
var authorInfoHtml = author != null ? $"<span>✍️ 作者: <strong>{author}</strong></span>" : "";
return $$"""
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=yes">
<title>{{title}} - WebImageViewer</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Noto+Sans+JP:wght@400;500;700&family=Outfit:wght@500;600;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-base: #0a0d14;
--bg-surface: #111726;
--bg-surface-elevated: #1a2236;
--bg-glass: rgba(17, 23, 38, 0.82);
--border-subtle: rgba(255, 255, 255, 0.08);
--border-glow: rgba(99, 102, 241, 0.3);
--accent-primary: #6366f1;
--accent-primary-hover: #4f46e5;
--accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
--text-main: #f8fafc;
--text-muted: #94a3b8;
--text-subtle: #64748b;
--header-height: 64px;
--toolbar-height: 56px;
--radius-md: 12px;
--radius-lg: 16px;
--shadow-float: 0 20px 40px -15px rgba(0, 0, 0, 0.6);
--transition-smooth: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
-webkit-tap-highlight-color: transparent;
}
body {
font-family: 'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
background-color: var(--bg-base);
color: var(--text-main);
line-height: 1.5;
overflow-x: hidden;
user-select: none;
min-height: 100vh;
}
/* ヘッダー */
header.top-header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: var(--header-height);
background: var(--bg-glass);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border-bottom: 1px solid var(--border-subtle);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 20px;
z-index: 100;
transition: transform 0.3s ease;
}
.header-left {
display: flex;
align-items: center;
gap: 16px;
min-width: 0;
}
.back-btn {
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
border-radius: var(--radius-md);
background: var(--bg-surface-elevated);
color: var(--text-main);
text-decoration: none;
border: 1px solid var(--border-subtle);
transition: var(--transition-smooth);
flex-shrink: 0;
}
.back-btn:hover {
background: var(--accent-primary);
border-color: var(--accent-primary);
transform: scale(1.05);
}
.gallery-title-wrapper {
min-width: 0;
}
.gallery-title {
font-size: 1.05rem;
font-weight: 700;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 50vw;
}
.gallery-sub {
font-size: 0.75rem;
color: var(--text-muted);
display: flex;
gap: 10px;
align-items: center;
}
.badge-category {
background: rgba(99, 102, 241, 0.2);
color: #818cf8;
padding: 2px 8px;
border-radius: 6px;
font-size: 0.7rem;
font-weight: 600;
text-transform: uppercase;
}
.header-right {
display: flex;
align-items: center;
gap: 10px;
}
.action-btn {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 14px;
border-radius: var(--radius-md);
background: var(--bg-surface-elevated);
color: var(--text-main);
border: 1px solid var(--border-subtle);
font-size: 0.85rem;
font-weight: 600;
cursor: pointer;
transition: var(--transition-smooth);
}
.action-btn:hover, .action-btn.active {
background: var(--accent-primary);
border-color: var(--accent-primary);
color: #fff;
box-shadow: 0 0 15px var(--border-glow);
}
/* メインビューアーコンテナ */
main.viewer-container {
padding-top: calc(var(--header-height) + 12px);
padding-bottom: calc(var(--toolbar-height) + 24px);
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
}
/* 縦スクロールモード */
.scroll-mode-view {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
width: 100%;
max-width: 1000px;
padding: 0 12px;
}
.scroll-image-wrapper {
position: relative;
width: 100%;
background: var(--bg-surface);
border-radius: var(--radius-md);
overflow: hidden;
box-shadow: var(--shadow-float);
min-height: 300px;
display: flex;
align-items: center;
justify-content: center;
}
.scroll-image-wrapper img {
width: 100%;
height: auto;
display: block;
object-fit: contain;
opacity: 0;
transition: opacity 0.3s ease;
}
.scroll-image-wrapper img.loaded {
opacity: 1;
}
.scroll-image-wrapper .page-badge {
position: absolute;
bottom: 12px;
right: 12px;
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(8px);
color: #fff;
padding: 4px 10px;
border-radius: 6px;
font-size: 0.75rem;
font-weight: 600;
pointer-events: none;
}
/* スライド(単ページ・見開き)モード */
.slide-mode-view {
display: none;
position: fixed;
top: var(--header-height);
bottom: var(--toolbar-height);
left: 0;
right: 0;
align-items: center;
justify-content: center;
overflow: hidden;
}
.slide-mode-view.active {
display: flex;
}
.slide-stage {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.slide-image {
max-width: 100%;
max-height: 100%;
object-fit: contain;
user-select: none;
transition: transform 0.2s ease-out;
box-shadow: var(--shadow-float);
}
.slide-nav-zone {
position: absolute;
top: 0;
bottom: 0;
width: 35%;
z-index: 10;
cursor: pointer;
display: flex;
align-items: center;
opacity: 0;
transition: opacity 0.2s ease;
}
.slide-nav-zone:hover {
opacity: 1;
}
.slide-nav-prev {
left: 0;
justify-content: flex-start;
padding-left: 24px;
background: linear-gradient(to right, rgba(0,0,0,0.4), transparent);
}
.slide-nav-next {
right: 0;
justify-content: flex-end;
padding-right: 24px;
background: linear-gradient(to left, rgba(0,0,0,0.4), transparent);
}
.nav-arrow-icon {
width: 48px;
height: 48px;
border-radius: 50%;
background: var(--bg-glass);
border: 1px solid var(--border-subtle);
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
/* 下部ツールバー */
footer.bottom-toolbar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: var(--toolbar-height);
background: var(--bg-glass);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border-top: 1px solid var(--border-subtle);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 20px;
z-index: 100;
transition: transform 0.3s ease;
}
.page-counter {
font-family: 'Outfit', sans-serif;
font-size: 0.95rem;
font-weight: 600;
color: var(--text-main);
display: flex;
align-items: center;
gap: 6px;
}
.page-counter span.current-page {
color: #818cf8;
font-size: 1.1rem;
}
.progress-bar-container {
flex: 1;
max-width: 450px;
margin: 0 20px;
height: 6px;
background: var(--bg-surface-elevated);
border-radius: 3px;
overflow: hidden;
cursor: pointer;
position: relative;
}
.progress-bar-fill {
height: 100%;
width: 0%;
background: var(--accent-gradient);
transition: width 0.15s ease;
}
/* サムネイル一覧ドロワー */
.drawer-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.6);
backdrop-filter: blur(4px);
opacity: 0;
pointer-events: none;
transition: opacity 0.3s ease;
z-index: 150;
}
.drawer-overlay.active {
opacity: 1;
pointer-events: auto;
}
.thumb-drawer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 240px;
background: var(--bg-surface);
border-top: 1px solid var(--border-subtle);
z-index: 160;
transform: translateY(100%);
transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
display: flex;
flex-direction: column;
padding: 16px;
}
.thumb-drawer.active {
transform: translateY(0);
}
.drawer-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
}
.drawer-header h3 {
font-size: 0.95rem;
font-weight: 700;
}
.thumb-list {
display: flex;
gap: 12px;
overflow-x: auto;
padding-bottom: 8px;
scroll-behavior: smooth;
}
.thumb-item {
flex: 0 0 100px;
height: 145px;
border-radius: 8px;
overflow: hidden;
background: var(--bg-surface-elevated);
border: 2px solid transparent;
cursor: pointer;
position: relative;
transition: var(--transition-smooth);
}
.thumb-item:hover, .thumb-item.active {
border-color: var(--accent-primary);
transform: translateY(-4px);
box-shadow: 0 6px 16px var(--border-glow);
}
.thumb-item img {
width: 100%;
height: 100%;
object-fit: cover;
}
.thumb-item .thumb-num {
position: absolute;
bottom: 4px;
right: 4px;
background: rgba(0, 0, 0, 0.75);
font-size: 0.65rem;
padding: 2px 6px;
border-radius: 4px;
}
/* メタ情報カード(最上部/最下部) */
.info-card {
background: var(--bg-surface);
border: 1px solid var(--border-subtle);
border-radius: var(--radius-lg);
padding: 24px;
margin-bottom: 16px;
width: 100%;
box-shadow: var(--shadow-float);
}
.info-tags {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 14px;
}
.tag-pill {
background: var(--bg-surface-elevated);
border: 1px solid var(--border-subtle);
color: var(--text-muted);
padding: 4px 12px;
border-radius: 20px;
font-size: 0.75rem;
font-weight: 500;
text-decoration: none;
}
/* キーボードショートカットヘルプモーダル */
.modal {
display: none;
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(8px);
align-items: center;
justify-content: center;
z-index: 200;
padding: 20px;
}
.modal.active {
display: flex;
}
.modal-body {
background: var(--bg-surface);
border: 1px solid var(--border-subtle);
border-radius: var(--radius-lg);
padding: 28px;
max-width: 440px;
width: 100%;
box-shadow: var(--shadow-float);
}
.shortcut-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px 0;
border-bottom: 1px solid var(--border-subtle);
}
.kbd-key {
background: var(--bg-surface-elevated);
border: 1px solid rgba(255, 255, 255, 0.15);
padding: 3px 8px;
border-radius: 6px;
font-family: monospace;
font-size: 0.8rem;
color: #818cf8;
}
@media (max-width: 768px) {
.gallery-title { max-width: 38vw; }
.header-right .text-label { display: none; }
.action-btn { padding: 8px 10px; }
.progress-bar-container { max-width: 180px; }
}
</style>
</head>
<body>
<!-- ヘッダー -->
<header class="top-header" id="topHeader">
<div class="header-left">
<a href="/" class="back-btn" title="ホームへ戻る">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
</a>
<div class="gallery-title-wrapper">
<div class="gallery-title" title="{{title}}">{{title}}</div>
<div class="gallery-sub">
<span class="badge-category">{{category}}</span>
{{circleHeaderHtml}}
{{authorHeaderHtml}}
</div>
</div>
</div>
<div class="header-right">
<button class="action-btn" id="modeToggleBtn" title="縦スクロール / スライド表示切替 (M)">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 9h18M9 21V9"/></svg>
<span class="text-label" id="modeLabel">スライド表示へ</span>
</button>
<button class="action-btn" id="thumbToggleBtn" title="サムネイル一覧 (T)">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/></svg>
</button>
<button class="action-btn" id="fullscreenBtn" title="全画面表示 (F)">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/></svg>
</button>
<button class="action-btn" id="helpBtn" title="ショートカット一覧 (?)">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
</button>
</div>
</header>
<!-- メインビューアー -->
<main class="viewer-container">
<!-- 縦スクロールモード表示 -->
<div class="scroll-mode-view" id="scrollModeView">
<!-- メタ情報カード -->
<div class="info-card">
<h2>{{title}}</h2>
<div style="margin-top: 8px; color: var(--text-muted); font-size: 0.85rem; display: flex; gap: 16px; flex-wrap: wrap;">
<span>📁 カテゴリ: <strong>{{category}}</strong></span>
{{circleInfoHtml}}
{{authorInfoHtml}}
<span>📄 総ページ数: <strong>{{totalPages}} ページ</strong></span>
<span>🔗 元サイト: <a href="{{sourceUrl}}" target="_blank" rel="noopener noreferrer" style="color:#818cf8; text-decoration:underline;">{{sourceSite}}</a></span>
</div>
{{tagsHtml}}
</div>
<!-- 画像リスト -->
{{imagesHtml}}
<!-- 終了カード -->
<div class="info-card" style="text-align: center; margin-top: 24px;">
<h3>🎉 最後のページに到達しました(全 {{totalPages}} ページ)</h3>
<p style="color: var(--text-muted); margin-top: 8px; font-size: 0.85rem;">閲覧ありがとうございます!</p>
<div style="margin-top: 16px;">
<a href="/" class="action-btn" style="text-decoration:none;">ホームに戻る</a>
</div>
</div>
</div>
<!-- スライドモード表示 -->
<div class="slide-mode-view" id="slideModeView">
<div class="slide-stage" id="slideStage">
<img class="slide-image" id="currentSlideImage" src="" alt="Slide Image" />
<div class="slide-nav-zone slide-nav-prev" id="slidePrevZone" title="前のページへ (← / A)">
<div class="nav-arrow-icon">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M15 18l-6-6 6-6"/></svg>
</div>
</div>
<div class="slide-nav-zone slide-nav-next" id="slideNextZone" title="次のページへ (→ / D / Space)">
<div class="nav-arrow-icon">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M9 18l6-6-6-6"/></svg>
</div>
</div>
</div>
</div>
</main>
<!-- 下部ツールバー -->
<footer class="bottom-toolbar" id="bottomToolbar">
<div class="page-counter">
<span class="current-page" id="currentPageDisplay">1</span>
<span>/</span>
<span>{{totalPages}}</span>
</div>
<div class="progress-bar-container" id="progressBar">
<div class="progress-bar-fill" id="progressFill"></div>
</div>
<div style="display: flex; gap: 8px;">
<button class="action-btn" id="prevPageBtn" title="前のページ">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M15 18l-6-6 6-6"/></svg>
</button>
<button class="action-btn" id="nextPageBtn" title="次のページ">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 18l6-6-6-6"/></svg>
</button>
</div>
</footer>
<!-- サムネイルドロワー -->
<div class="drawer-overlay" id="drawerOverlay"></div>
<div class="thumb-drawer" id="thumbDrawer">
<div class="drawer-header">
<h3>📖 サムネイル一覧 ({{totalPages}} ページ)</h3>
<button class="action-btn" id="closeDrawerBtn">✕ 閉じる</button>
</div>
<div class="thumb-list" id="thumbList">
{{thumbsHtml}}
</div>
</div>
<!-- ヘルプモーダル -->
<div class="modal" id="helpModal">
<div class="modal-body">
<h3 style="margin-bottom: 16px; font-weight: 700;">⌨️ キーボードショートカット</h3>
<div class="shortcut-row"><span>次のページへ</span><span class="kbd-key">→ / D / Space</span></div>
<div class="shortcut-row"><span>前のページへ</span><span class="kbd-key">← / A</span></div>
<div class="shortcut-row"><span>表示モード切替</span><span class="kbd-key">M</span></div>
<div class="shortcut-row"><span>サムネイル一覧開閉</span><span class="kbd-key">T</span></div>
<div class="shortcut-row"><span>全画面表示切替</span><span class="kbd-key">F</span></div>
<div class="shortcut-row"><span>先頭 / 末尾ページへ</span><span class="kbd-key">Home / End</span></div>
<div class="shortcut-row"><span>マウスホイール (スライド時)</span><span class="kbd-key">上: 前 / 下: 次</span></div>
<div style="margin-top: 20px; text-align: right;">
<button class="action-btn" id="closeHelpBtn">閉じる</button>
</div>
</div>
</div>
<script>
const galleryData = {{galleryJson}};
const totalPages = {{totalPages}};
let currentPage = 1;
let isSlideMode = false;
// 要素参照
const scrollModeView = document.getElementById('scrollModeView');
const slideModeView = document.getElementById('slideModeView');
const modeToggleBtn = document.getElementById('modeToggleBtn');
const modeLabel = document.getElementById('modeLabel');
const currentSlideImage = document.getElementById('currentSlideImage');
const currentPageDisplay = document.getElementById('currentPageDisplay');
const progressFill = document.getElementById('progressFill');
const progressBar = document.getElementById('progressBar');
const thumbToggleBtn = document.getElementById('thumbToggleBtn');
const thumbDrawer = document.getElementById('thumbDrawer');
const drawerOverlay = document.getElementById('drawerOverlay');
const closeDrawerBtn = document.getElementById('closeDrawerBtn');
const thumbItems = document.querySelectorAll('.thumb-item');
const fullscreenBtn = document.getElementById('fullscreenBtn');
const helpBtn = document.getElementById('helpBtn');
const helpModal = document.getElementById('helpModal');
const closeHelpBtn = document.getElementById('closeHelpBtn');
const prevPageBtn = document.getElementById('prevPageBtn');
const nextPageBtn = document.getElementById('nextPageBtn');
const slidePrevZone = document.getElementById('slidePrevZone');
const slideNextZone = document.getElementById('slideNextZone');
// 表示モード切替
function toggleMode() {
isSlideMode = !isSlideMode;
if (isSlideMode) {
scrollModeView.style.display = 'none';
slideModeView.classList.add('active');
modeLabel.textContent = 'スクロール表示へ';
updateSlideImage();
} else {
slideModeView.classList.remove('active');
scrollModeView.style.display = 'flex';
modeLabel.textContent = 'スライド表示へ';
scrollToPage(currentPage);
}
}
// ページ更新
function setPage(page, smoothScroll = true) {
if (page < 1) page = 1;
if (page > totalPages) page = totalPages;
currentPage = page;
currentPageDisplay.textContent = currentPage;
const progress = ((currentPage - 1) / Math.max(1, totalPages - 1)) * 100;
progressFill.style.width = `${progress}%`;
// サムネイルのアクティブ状態更新
thumbItems.forEach(item => {
const itemPage = parseInt(item.dataset.page);
item.classList.toggle('active', itemPage === currentPage);
if (itemPage === currentPage && thumbDrawer.classList.contains('active')) {
item.scrollIntoView({ behavior: 'smooth', inline: 'center', block: 'nearest' });
}
});
if (isSlideMode) {
updateSlideImage();
} else if (smoothScroll) {
scrollToPage(currentPage);
}
}
function scrollToPage(page) {
const el = document.querySelector(`.scroll-image-wrapper[data-page="${page}"]`);
if (el) {
const offset = 80;
const bodyRect = document.body.getBoundingClientRect().top;
const elementRect = el.getBoundingClientRect().top;
const elementPosition = elementRect - bodyRect;
const offsetPosition = elementPosition - offset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}
}
function updateSlideImage() {
if (galleryData.images && galleryData.images[currentPage - 1]) {
const imgObj = galleryData.images[currentPage - 1];
currentSlideImage.src = imgObj.imageUrl;
currentSlideImage.alt = imgObj.altText || `${galleryData.title} ${currentPage}ページ`;
preloadAdjacentImages();
}
}
function preloadAdjacentImages() {
if (!galleryData.images) return;
const nextIdx = currentPage;
if (nextIdx < totalPages) {
const preloadImg = new Image();
preloadImg.src = galleryData.images[nextIdx].imageUrl;
}
const prevIdx = currentPage - 2;
if (prevIdx >= 0) {
const preloadImg = new Image();
preloadImg.src = galleryData.images[prevIdx].imageUrl;
}
}
// サムネイルドロワー開閉
function toggleDrawer(open) {
const shouldOpen = open !== undefined ? open : !thumbDrawer.classList.contains('active');
thumbDrawer.classList.toggle('active', shouldOpen);
drawerOverlay.classList.toggle('active', shouldOpen);
if (shouldOpen) {
const activeThumb = document.querySelector(`.thumb-item[data-page="${currentPage}"]`);
if (activeThumb) {
setTimeout(() => activeThumb.scrollIntoView({ behavior: 'smooth', inline: 'center' }), 100);
}
}
}
// 全画面表示切替
function toggleFullscreen() {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen().catch(() => {});
} else {
document.exitFullscreen().catch(() => {});
}
}
// スクロール検知によるページ番号自動更新
let scrollTimeout;
window.addEventListener('scroll', () => {
if (isSlideMode) return;
clearTimeout(scrollTimeout);
scrollTimeout = setTimeout(() => {
const wrappers = document.querySelectorAll('.scroll-image-wrapper');
let foundPage = currentPage;
const viewCenter = window.innerHeight / 2;
wrappers.forEach(w => {
const rect = w.getBoundingClientRect();
if (rect.top <= viewCenter && rect.bottom >= viewCenter) {
foundPage = parseInt(w.dataset.page);
}
});
if (foundPage !== currentPage) {
setPage(foundPage, false);
}
}, 50);
});
// イベントリスナー
modeToggleBtn.addEventListener('click', toggleMode);
thumbToggleBtn.addEventListener('click', () => toggleDrawer());
closeDrawerBtn.addEventListener('click', () => toggleDrawer(false));
drawerOverlay.addEventListener('click', () => toggleDrawer(false));
fullscreenBtn.addEventListener('click', toggleFullscreen);
helpBtn.addEventListener('click', () => helpModal.classList.add('active'));
closeHelpBtn.addEventListener('click', () => helpModal.classList.remove('active'));
helpModal.addEventListener('click', (e) => { if (e.target === helpModal) helpModal.classList.remove('active'); });
prevPageBtn.addEventListener('click', () => setPage(currentPage - 1));
nextPageBtn.addEventListener('click', () => setPage(currentPage + 1));
slidePrevZone.addEventListener('click', () => setPage(currentPage - 1));
slideNextZone.addEventListener('click', () => setPage(currentPage + 1));
thumbItems.forEach(item => {
item.addEventListener('click', () => {
const p = parseInt(item.dataset.page);
setPage(p);
toggleDrawer(false);
});
});
progressBar.addEventListener('click', (e) => {
const rect = progressBar.getBoundingClientRect();
const ratio = (e.clientX - rect.left) / rect.width;
const targetPage = Math.max(1, Math.min(totalPages, Math.round(ratio * totalPages)));
setPage(targetPage);
});
window.addEventListener('keydown', (e) => {
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;
switch (e.key) {
case 'ArrowRight':
case 'd':
case 'D':
case ' ':
e.preventDefault();
setPage(currentPage + 1);
break;
case 'ArrowLeft':
case 'a':
case 'A':
e.preventDefault();
setPage(currentPage - 1);
break;
case 'm':
case 'M':
toggleMode();
break;
case 't':
case 'T':
toggleDrawer();
break;
case 'f':
case 'F':
toggleFullscreen();
break;
case 'Home':
e.preventDefault();
setPage(1);
break;
case 'End':
e.preventDefault();
setPage(totalPages);
break;
case 'Escape':
toggleDrawer(false);
helpModal.classList.remove('active');
break;
}
});
// マウスホイールによるページ送り(スライド表示モード時のみ)
let wheelCooldown = false;
window.addEventListener('wheel', (e) => {
if (!isSlideMode) return;
// ヘルプモーダルやサムネイルドロワーが開いているときは無視
if (helpModal.classList.contains('active') || thumbDrawer.classList.contains('active')) return;
// 微小なスクロールノイズを無視
if (Math.abs(e.deltaY) < 5) return;
e.preventDefault();
if (wheelCooldown) return;
if (e.deltaY > 0) {
setPage(currentPage + 1);
} else if (e.deltaY < 0) {
setPage(currentPage - 1);
}
wheelCooldown = true;
setTimeout(() => {
wheelCooldown = false;
}, 200);
}, { passive: false });
setPage(1, false);
</script>
</body>
</html>
""";
}
/// <summary>
/// ホーム画面(URL・ID入力フォーム)のHTMLを生成します。
/// </summary>
public static string RenderHomePage()
{
return """
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebImageViewer - プレミアム画像ビューアー</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Noto+Sans+JP:wght@400;500;700&family=Outfit:wght@600;700;800&display=swap" rel="stylesheet">
<style>
:root {
--bg-base: #07090e;
--bg-surface: #0f1420;
--bg-card: rgba(18, 24, 38, 0.7);
--border-subtle: rgba(255, 255, 255, 0.08);
--accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
--accent-primary: #6366f1;
--text-main: #f8fafc;
--text-muted: #94a3b8;
--radius-lg: 18px;
--shadow-glow: 0 0 35px rgba(99, 102, 241, 0.25);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Inter', 'Noto Sans JP', sans-serif;
background-color: var(--bg-base);
color: var(--text-main);
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 24px;
background-image:
radial-gradient(circle at 15% 20%, rgba(99, 102, 241, 0.15), transparent 40%),
radial-gradient(circle at 85% 80%, rgba(236, 72, 153, 0.12), transparent 40%);
}
.container {
max-width: 680px;
width: 100%;
}
.hero {
text-align: center;
margin-bottom: 36px;
}
.hero-title {
font-family: 'Outfit', sans-serif;
font-size: 2.8rem;
font-weight: 800;
background: var(--accent-gradient);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
letter-spacing: -0.02em;
margin-bottom: 8px;
}
.hero-subtitle {
color: var(--text-muted);
font-size: 1.05rem;
}
.search-card {
background: var(--bg-card);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid var(--border-subtle);
border-radius: var(--radius-lg);
padding: 32px;
box-shadow: var(--shadow-glow);
}
.input-group {
display: flex;
gap: 12px;
margin-top: 16px;
}
.url-input {
flex: 1;
background: rgba(0, 0, 0, 0.4);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 12px;
padding: 14px 18px;
color: #fff;
font-size: 1rem;
outline: none;
transition: all 0.2s ease;
}
.url-input:focus {
border-color: var(--accent-primary);
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
}
.submit-btn {
background: var(--accent-gradient);
border: none;
border-radius: 12px;
padding: 14px 28px;
color: #fff;
font-size: 1rem;
font-weight: 700;
cursor: pointer;
transition: all 0.2s ease;
white-space: nowrap;
}
.submit-btn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}
.quick-links {
margin-top: 28px;
padding-top: 20px;
border-top: 1px solid var(--border-subtle);
}
.quick-links-title {
font-size: 0.85rem;
color: var(--text-muted);
margin-bottom: 12px;
text-transform: uppercase;
letter-spacing: 0.05em;
font-weight: 600;
}
.sample-item {
display: flex;
align-items: center;
justify-content: space-between;
background: rgba(255, 255, 255, 0.03);
border: 1px solid var(--border-subtle);
padding: 12px 16px;
border-radius: 10px;
text-decoration: none;
color: var(--text-main);
transition: all 0.2s ease;
}
.sample-item:hover {
background: rgba(99, 102, 241, 0.15);
border-color: rgba(99, 102, 241, 0.4);
transform: translateX(4px);
}
.features-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 16px;
margin-top: 36px;
}
.feature-box {
background: rgba(255, 255, 255, 0.02);
border: 1px solid var(--border-subtle);
border-radius: 14px;
padding: 20px 16px;
text-align: center;
}
.feature-icon {
font-size: 1.8rem;
margin-bottom: 8px;
}
.feature-title {
font-size: 0.95rem;
font-weight: 700;
margin-bottom: 4px;
}
.feature-desc {
font-size: 0.78rem;
color: var(--text-muted);
}
.tabs-nav {
display: flex;
gap: 8px;
margin-bottom: 24px;
background: rgba(0, 0, 0, 0.35);
padding: 5px;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.06);
}
.tab-btn {
flex: 1;
background: transparent;
border: none;
color: var(--text-muted);
padding: 10px 16px;
font-size: 0.9rem;
font-weight: 600;
border-radius: 9px;
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}
.tab-btn:hover {
color: #fff;
background: rgba(255, 255, 255, 0.05);
}
.tab-btn.active {
background: var(--accent-gradient);
color: #fff;
box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}
.tab-panel {
display: none;
}
.tab-panel.active {
display: block;
}
@media (max-width: 600px) {
.hero-title { font-size: 2.2rem; }
.input-group { flex-direction: column; }
.features-grid { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<div class="container">
<div class="hero">
<h1 class="hero-title">WebImageViewer</h1>
<p class="hero-subtitle">高速スクレイピングと洗練されたモダンUIで快適な画像・動画閲覧体験を</p>
</div>
<div class="search-card">
<div class="tabs-nav">
<button type="button" class="tab-btn active" id="tabGalleryBtn" onclick="switchTab('gallery')">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>
<span>画像ギャラリー</span>
</button>
<button type="button" class="tab-btn" id="tabVideoBtn" onclick="switchTab('video')">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"/></svg>
<span>動画プレイヤー (SpankBang)</span>
</button>
</div>
<!-- 画像ギャラリー パネル -->
<div id="galleryPanel" class="tab-panel active">
<form id="viewForm">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
<label for="urlInput" style="font-size: 0.9rem; font-weight: 600; color: var(--text-main);">作品URL または サイト/ID を入力</label>
<span style="font-size: 0.75rem; color: #818cf8; background: rgba(99, 102, 241, 0.15); padding: 2px 8px; border-radius: 6px;">統一URL: /{site}/{id}</span>
</div>
<div style="display: flex; gap: 8px; margin-bottom: 12px;">
<select id="siteSelect" style="background: rgba(0, 0, 0, 0.4); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 10px; color: #f8fafc; padding: 8px 12px; font-size: 0.85rem; outline: none; cursor: pointer;">
<option value="auto">🌐 自動判定 (Auto)</option>
<option value="ehentai">🐼 E-Hentai (/ehentai/{gid}/{token})</option>
<option value="hitomi">📕 Hitomi.la (/hitomi/{id})</option>
<option value="aurahentai">✨ AuraHentai (/aurahentai/{id})</option>
<option value="momonga">🐿️ momon-ga (/momonga/{id})</option>
<option value="mangalear">📖 mangalear (/mangalear/{id})</option>
<option value="spankbang">🎥 SpankBang (/spankbang/{id})</option>
</select>
</div>
<div class="input-group">
<input type="text" id="urlInput" class="url-input" placeholder="例: 4159771/95d2fa13bd, 4159707, 013597, 289385, または元URL" required autocomplete="off" />
<button type="submit" class="submit-btn">閲覧する</button>
</div>
</form>
<div class="quick-links">
<div class="quick-links-title">統一URL クイックアクセス例</div>
<div style="display: flex; flex-direction: column; gap: 10px;">
<a href="/ehentai/4159771/95d2fa13bd/" class="sample-item">
<div>
<div style="display: flex; align-items: center; gap: 8px;">
<span style="background: rgba(16, 185, 129, 0.2); color: #34d399; padding: 1px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: 700;">E-HENTAI</span>
<span style="font-weight: 600; font-size: 0.95rem;">/ehentai/4159771/95d2fa13bd</span>
</div>
<div style="font-size: 0.78rem; color: var(--text-muted); margin-top: 2px;">Marian Kelly Mating / Western (15ページ)</div>
</div>
<div style="color: #818cf8; font-weight: 700;">開く →</div>
</a>
<a href="/hitomi/4159707/" class="sample-item">
<div>
<div style="display: flex; align-items: center; gap: 8px;">
<span style="background: rgba(239, 68, 68, 0.2); color: #f87171; padding: 1px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: 700;">HITOMI</span>
<span style="font-weight: 600; font-size: 0.95rem;">/hitomi/4159707</span>
</div>
<div style="font-size: 0.78rem; color: var(--text-muted); margin-top: 2px;">gzrさんのヘンタイ露出排泄 / 作者: ajisio (27ページ)</div>
</div>
<div style="color: #818cf8; font-weight: 700;">開く →</div>
</a>
<a href="/aurahentai/013597/" class="sample-item">
<div>
<div style="display: flex; align-items: center; gap: 8px;">
<span style="background: rgba(236, 72, 153, 0.2); color: #f472b6; padding: 1px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: 700;">AURA</span>
<span style="font-weight: 600; font-size: 0.95rem;">/aurahentai/013597</span>
</div>
<div style="font-size: 0.78rem; color: var(--text-muted); margin-top: 2px;">作者: ajisio / にじさんじ (17ページ)</div>
</div>
<div style="color: #818cf8; font-weight: 700;">開く →</div>
</a>
<a href="/momonga/mo3469109/" class="sample-item">
<div>
<div style="display: flex; align-items: center; gap: 8px;">
<span style="background: rgba(99, 102, 241, 0.2); color: #818cf8; padding: 1px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: 700;">MOMONGA</span>
<span style="font-weight: 600; font-size: 0.95rem;">/momonga/mo3469109</span>
</div>
<div style="font-size: 0.78rem; color: var(--text-muted); margin-top: 2px;">新妻契約 / サークル: Whisker Pad (52ページ)</div>
</div>
<div style="color: #818cf8; font-weight: 700;">開く →</div>
</a>
<a href="/mangalear/289385/" class="sample-item">
<div>
<div style="display: flex; align-items: center; gap: 8px;">
<span style="background: rgba(245, 158, 11, 0.2); color: #fbbf24; padding: 1px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: 700;">MANGALEAR</span>
<span style="font-weight: 600; font-size: 0.95rem;">/mangalear/289385</span>
</div>
<div style="font-size: 0.78rem; color: var(--text-muted); margin-top: 2px;">これが…本当のセクササイズだ… / 羽川ハスミ (24ページ)</div>
</div>
<div style="color: #818cf8; font-weight: 700;">開く →</div>
</a>
</div>
</div>
</div>
<!-- 動画プレイヤー パネル -->
<div id="videoPanel" class="tab-panel">
<form id="videoForm">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
<label for="videoUrlInput" style="font-size: 0.9rem; font-weight: 600; color: var(--text-main);">SpankBang 動画ページURL または 動画ID を入力</label>
<span style="font-size: 0.75rem; color: #ec4899; background: rgba(236, 72, 153, 0.15); padding: 2px 8px; border-radius: 6px;">URL: /spankbang/{id}</span>
</div>
<p style="font-size: 0.82rem; color: var(--text-muted); margin-bottom: 12px;">jp.spankbang.com の動画URL、埋め込みURL、または動画IDを入力して再生します。</p>
<div class="input-group">
<input type="text" id="videoUrlInput" class="url-input" placeholder="例: https://jp.spankbang.com/56b3d/video/ または 56b3d" required autocomplete="off" />
<button type="submit" class="submit-btn" style="background: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%);">動画を再生</button>
</div>
</form>
<div class="quick-links">
<div class="quick-links-title">SpankBang クイック再生例</div>
<div style="display: flex; flex-direction: column; gap: 10px;">
<a href="/spankbang/56b3d" class="sample-item">
<div>
<div style="display: flex; align-items: center; gap: 8px;">
<span style="background: rgba(236, 72, 153, 0.2); color: #f472b6; padding: 1px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: 700;">SPANKBANG</span>
<span style="font-weight: 600; font-size: 0.95rem;">/spankbang/56b3d</span>
</div>
<div style="font-size: 0.78rem; color: var(--text-muted); margin-top: 2px;">動画ID: 56b3d (サンプル動画プレイヤー)</div>
</div>
<div style="color: #ec4899; font-weight: 700;">再生 →</div>
</a>
</div>
</div>
</div>
</div>
<div class="features-grid">
<div class="feature-box">
<div class="feature-icon">🌐</div>
<div class="feature-title">マルチサイト統一対応</div>
<div class="feature-desc">/{site}/{id} でどのサイトの作品も瞬時に閲覧可能</div>
</div>
<div class="feature-box">
<div class="feature-icon">⚡</div>
<div class="feature-title">超高速キャッシュ</div>
<div class="feature-desc">メモリキャッシュによるストレスフリーな即時表示</div>
</div>
<div class="feature-box">
<div class="feature-icon">📱</div>
<div class="feature-title">2つの閲覧モード</div>
<div class="feature-desc">快適な縦スクロール&コミックスライド表示に対応</div>
</div>
</div>
</div>
<script>
// タブ切り替え処理
function switchTab(tab) {
const galleryBtn = document.getElementById('tabGalleryBtn');
const videoBtn = document.getElementById('tabVideoBtn');
const galleryPanel = document.getElementById('galleryPanel');
const videoPanel = document.getElementById('videoPanel');
if (tab === 'gallery') {
galleryBtn.classList.add('active');
videoBtn.classList.remove('active');
galleryPanel.classList.add('active');
videoPanel.classList.remove('active');
} else {
videoBtn.classList.add('active');
galleryBtn.classList.remove('active');
videoPanel.classList.add('active');
galleryPanel.classList.remove('active');
}
}
// SpankBangのURLまたはIDからIDを抽出する関数
function extractSpankBangId(str) {
if (!str) return null;
str = str.trim();
// https://jp.spankbang.com/{id}/video/... または /embed/ または /play/
const urlMatch = str.match(/spankbang\.(?:com|party)\/([a-z0-9]+)(?:\/(?:video|play|embed)|\/|$)/i);
if (urlMatch) return urlMatch[1];
// spankbang/{id}
const pathMatch = str.match(/^spankbang\/([a-z0-9]+)/i);
if (pathMatch) return pathMatch[1];
// IDのみ (例: 56b3d)
const idMatch = str.match(/^[a-z0-9]{3,12}$/i);
if (idMatch) return idMatch[0];
return null;
}
// 動画用フォーム送信イベント
document.getElementById('videoForm').addEventListener('submit', function(e) {
e.preventDefault();
const input = document.getElementById('videoUrlInput').value.trim();
if (!input) return;
const id = extractSpankBangId(input);
if (id) {
window.location.href = '/spankbang/' + id;
} else {
window.location.href = '/video?url=' + encodeURIComponent(input);
}
});
// 画像用フォーム送信イベント
document.getElementById('viewForm').addEventListener('submit', function(e) {
e.preventDefault();
let input = document.getElementById('urlInput').value.trim();
const siteSelect = document.getElementById('siteSelect').value;
if (!input) return;
// SpankBang の判定(画像入力フォームに入力された場合でも自動遷移)
const sbId = extractSpankBangId(input);
if (sbId && (input.includes('spankbang') || siteSelect === 'spankbang')) {
window.location.href = '/spankbang/' + sbId;
return;
}
// 完全URLの場合
if (input.startsWith('http://') || input.startsWith('https://')) {
try {
const url = new URL(input);
const host = url.hostname.toLowerCase();
const path = url.pathname.replace(/^\/+|\/+$/g, '');
if (host.includes('e-hentai.org') || host.includes('exhentai.org')) {
const gm = path.match(/g\/(\d+)\/([a-z0-9]+)/i);
if (gm) {
window.location.href = '/ehentai/' + gm[1] + '/' + gm[2] + '/';
return;
}
const sm = path.match(/s\/([a-z0-9]+)\/(\d+)-/i);
if (sm) {
window.location.href = '/view?url=' + encodeURIComponent(input);
return;
}
}
if (host.includes('hitomi.la')) {
const m = path.match(/(?:-|\/)(\d{5,8})(?:\.html)?$/) || path.match(/\d{5,8}/);
const id = m ? m[1] || m[0] : path;
window.location.href = '/hitomi/' + id + '/';
return;
}
if (host.includes('aurahentai.com')) {
const segs = path.split('/');
const id = segs.length >= 2 ? segs[1] : segs[0];
window.location.href = '/aurahentai/' + id + '/';
return;
}
if (host.includes('momon-ga.com')) {
const segs = path.split('/');
const id = segs.length >= 2 ? segs[1] : segs[0];
window.location.href = '/momonga/' + id + '/';
return;
}
if (host.includes('mangalear.blog')) {
const p = url.searchParams.get('p');
if (p) {
window.location.href = '/mangalear/' + p + '/';
return;
}
const segs = path.split('/');
const id = segs.length >= 2 ? segs[1] : segs[0];
window.location.href = '/mangalear/' + id + '/';
return;
}
// 汎用ビューアーへ
window.location.href = '/view?url=' + encodeURIComponent(input);
return;
} catch(err) {
window.location.href = '/view?url=' + encodeURIComponent(input);
return;
}
}
// サイト選択が明示されている場合
if (siteSelect !== 'auto') {
const cleanId = input.replace(/^\/+|\/+$/g, '');
window.location.href = '/' + siteSelect + '/' + cleanId + '/';
return;
}
// E-Hentai の gid/token 形式 (例: 4159771/95d2fa13bd または 4159771_95d2fa13bd)
const ehPair = input.match(/^(\d+)[/_ -]([a-z0-9]{10})$/i);
if (ehPair) {
window.location.href = '/ehentai/' + ehPair[1] + '/' + ehPair[2] + '/';
return;
}
// スラッシュが含まれる場合 (例: ehentai/4159771/95d2fa13bd や hitomi/4159707 や momonga/mo3469109)
if (input.includes('/')) {
window.location.href = '/' + input.replace(/^\/+|\/+$/g, '') + '/';
return;
}
// 自動判定
if (/^\d{7,}$/.test(input)) {
// 7桁以上の数字 -> hitomi
window.location.href = '/hitomi/' + input + '/';
} else if (/^\d+$/.test(input)) {
// 6桁以下の数字 -> aurahentai
window.location.href = '/aurahentai/' + input + '/';
} else if (input.startsWith('mo') || input.startsWith('MO')) {
// moで始まる -> momonga
window.location.href = '/momonga/' + input + '/';
} else {
window.location.href = '/view?id=' + encodeURIComponent(input);
}
});
</script>
</body>
</html>
""";
}
/// <summary>
/// エラー画面(ギャラリーが見つからない場合等)のHTMLを生成します。
/// </summary>
public static string RenderErrorPage(string message, int statusCode = 404)
{
return $$"""
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>エラー {{statusCode}} - WebImageViewer</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&family=Noto+Sans+JP:wght@400;700&family=Outfit:wght@700&display=swap" rel="stylesheet">
<style>
body {
background-color: #0a0d14;
color: #f8fafc;
font-family: 'Inter', 'Noto Sans JP', sans-serif;
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
padding: 20px;
}
.card {
background: #111726;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 16px;
padding: 40px;
max-width: 480px;
text-align: center;
box-shadow: 0 20px 40px rgba(0,0,0,0.6);
}
.code {
font-family: 'Outfit', sans-serif;
font-size: 4rem;
font-weight: 800;
color: #ef4444;
line-height: 1;
margin-bottom: 12px;
}
.msg {
color: #94a3b8;
margin-bottom: 24px;
font-size: 1rem;
}
.btn {
display: inline-block;
background: #6366f1;
color: #fff;
padding: 12px 24px;
border-radius: 10px;
text-decoration: none;
font-weight: 600;
transition: 0.2s;
}
.btn:hover { background: #4f46e5; }
</style>
</head>
<body>
<div class="card">
<div class="code">{{statusCode}}</div>
<h2>ギャラリーを取得できませんでした</h2>
<p class="msg">{{Encoder.Encode(message)}}</p>
<a href="/" class="btn">ホームへ戻る</a>
</div>
</body>
</html>
""";
}
/// <summary>
/// SpankBang動画プレイヤー画面のHTMLを生成します。
/// </summary>
public static string RenderVideoPlayer(string videoId, string? originalUrl = null)
{
var safeId = Encoder.Encode(videoId);
var safeOriginalUrl = !string.IsNullOrWhiteSpace(originalUrl) ? Encoder.Encode(originalUrl) : $"https://jp.spankbang.com/{safeId}/video/";
var embedUrl = $"https://spankbang.com/{safeId}/embed/";
return $$"""
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SpankBang 動画プレイヤー (ID: {{safeId}}) - WebImageViewer</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Noto+Sans+JP:wght@400;500;700&family=Outfit:wght@600;700;800&display=swap" rel="stylesheet">
<style>
:root {
--bg-base: #07090e;
--bg-surface: #0f1420;
--bg-card: rgba(18, 24, 38, 0.85);
--border-subtle: rgba(255, 255, 255, 0.08);
--border-glow: rgba(236, 72, 153, 0.3);
--accent-primary: #ec4899;
--accent-secondary: #8b5cf6;
--accent-gradient: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%);
--text-main: #f8fafc;
--text-muted: #94a3b8;
--header-height: 60px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Inter', 'Noto Sans JP', sans-serif;
background-color: var(--bg-base);
color: var(--text-main);
min-height: 100vh;
display: flex;
flex-direction: column;
background-image:
radial-gradient(circle at 15% 15%, rgba(236, 72, 153, 0.12), transparent 40%),
radial-gradient(circle at 85% 85%, rgba(99, 102, 241, 0.12), transparent 40%);
}
.header {
height: var(--header-height);
background: rgba(15, 20, 32, 0.85);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border-bottom: 1px solid var(--border-subtle);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 24px;
position: sticky;
top: 0;
z-index: 100;
}
.header-left {
display: flex;
align-items: center;
gap: 16px;
}
.brand-link {
display: flex;
align-items: center;
gap: 8px;
text-decoration: none;
color: #fff;
font-family: 'Outfit', sans-serif;
font-weight: 700;
font-size: 1.15rem;
}
.brand-badge {
background: var(--accent-gradient);
color: #fff;
font-size: 0.7rem;
padding: 2px 8px;
border-radius: 6px;
font-family: 'Inter', sans-serif;
font-weight: 700;
letter-spacing: 0.05em;
}
.header-actions {
display: flex;
align-items: center;
gap: 10px;
}
.btn-action {
display: inline-flex;
align-items: center;
gap: 6px;
background: rgba(255, 255, 255, 0.06);
border: 1px solid var(--border-subtle);
color: var(--text-main);
padding: 8px 14px;
border-radius: 8px;
font-size: 0.85rem;
font-weight: 600;
cursor: pointer;
text-decoration: none;
transition: all 0.2s ease;
}
.btn-action:hover {
background: rgba(255, 255, 255, 0.12);
border-color: rgba(255, 255, 255, 0.2);
transform: translateY(-1px);
}
.btn-action.active {
background: var(--accent-gradient);
color: #fff;
border-color: transparent;
}
.main-content {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
padding: 24px;
width: 100%;
max-width: 1200px;
margin: 0 auto;
transition: max-width 0.3s ease;
}
.main-content.theater-mode {
max-width: 96vw;
padding: 12px 16px;
}
.player-container {
width: 100%;
position: relative;
background: #000;
border-radius: 16px;
overflow: hidden;
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.8), 0 0 30px rgba(236, 72, 153, 0.15);
border: 1px solid var(--border-subtle);
aspect-ratio: 16 / 9;
}
.player-iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
}
.video-meta-card {
width: 100%;
margin-top: 20px;
background: var(--bg-card);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border: 1px solid var(--border-subtle);
border-radius: 14px;
padding: 20px 24px;
display: flex;
flex-direction: column;
gap: 16px;
}
.meta-top-row {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 12px;
}
.meta-tags {
display: flex;
align-items: center;
gap: 10px;
}
.meta-tag-site {
background: rgba(236, 72, 153, 0.18);
color: #f472b6;
padding: 4px 10px;
border-radius: 6px;
font-size: 0.8rem;
font-weight: 700;
}
.meta-tag-id {
background: rgba(255, 255, 255, 0.07);
color: var(--text-main);
padding: 4px 10px;
border-radius: 6px;
font-size: 0.8rem;
font-family: monospace;
}
.quick-switch-form {
display: flex;
gap: 10px;
margin-top: 4px;
}
.quick-input {
flex: 1;
background: rgba(0, 0, 0, 0.4);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 10px;
padding: 10px 14px;
color: #fff;
font-size: 0.9rem;
outline: none;
transition: 0.2s;
}
.quick-input:focus {
border-color: var(--accent-primary);
box-shadow: 0 0 0 2px rgba(236, 72, 153, 0.3);
}
.quick-submit-btn {
background: var(--accent-gradient);
border: none;
border-radius: 10px;
padding: 10px 18px;
color: #fff;
font-size: 0.85rem;
font-weight: 700;
cursor: pointer;
transition: 0.2s;
white-space: nowrap;
}
.quick-submit-btn:hover {
transform: translateY(-1px);
box-shadow: 0 4px 14px rgba(236, 72, 153, 0.4);
}
@media (max-width: 768px) {
.header { padding: 0 16px; }
.main-content { padding: 12px; }
.quick-switch-form { flex-direction: column; }
}
</style>
</head>
<body>
<header class="header">
<div class="header-left">
<a href="/" class="brand-link">
<span>WebImageViewer</span>
<span class="brand-badge">SPANKBANG VIDEO</span>
</a>
</div>
<div class="header-actions">
<button class="btn-action" id="theaterBtn" title="シアターモード切替">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="4" width="20" height="16" rx="2"/><line x1="2" y1="10" x2="22" y2="10"/></svg>
<span>シアター</span>
</button>
<button class="btn-action" id="fullscreenBtn" title="全画面切替">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/></svg>
<span>全画面</span>
</button>
<a href="/" class="btn-action">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
<span>ホームへ戻る</span>
</a>
</div>
</header>
<main class="main-content" id="mainContainer">
<div class="player-container" id="playerWrapper">
<iframe
id="videoIframe"
src="{{embedUrl}}"
class="player-iframe"
frameborder="0"
scrolling="no"
allowfullscreen="true"
webkitallowfullscreen="true"
mozallowfullscreen="true"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen">
</iframe>
</div>
<div class="video-meta-card">
<div class="meta-top-row">
<div class="meta-tags">
<span class="meta-tag-site">SpankBang</span>
<span class="meta-tag-id">ID: {{safeId}}</span>
</div>
<div style="display: flex; gap: 10px;">
<a href="{{safeOriginalUrl}}" target="_blank" rel="noopener noreferrer" class="btn-action" style="font-size: 0.8rem;">
<span>公式ページを開く ↗</span>
</a>
</div>
</div>
<div>
<label style="font-size: 0.85rem; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: 6px;">別の動画を再生する</label>
<form id="switchForm" class="quick-switch-form">
<input type="text" id="switchInput" class="quick-input" placeholder="動画URL または ID (例: 56b3d)" required autocomplete="off" />
<button type="submit" class="quick-submit-btn">再生切り替え</button>
</form>
</div>
</div>
</main>
<script>
const theaterBtn = document.getElementById('theaterBtn');
const fullscreenBtn = document.getElementById('fullscreenBtn');
const mainContainer = document.getElementById('mainContainer');
const playerWrapper = document.getElementById('playerWrapper');
const videoIframe = document.getElementById('videoIframe');
// シアターモード切替
theaterBtn.addEventListener('click', () => {
mainContainer.classList.toggle('theater-mode');
theaterBtn.classList.toggle('active');
});
// 全画面表示切替
fullscreenBtn.addEventListener('click', () => {
if (!document.fullscreenElement) {
if (playerWrapper.requestFullscreen) {
playerWrapper.requestFullscreen().catch(() => {});
}
} else {
document.exitFullscreen().catch(() => {});
}
});
// 動画切り替えフォーム
document.getElementById('switchForm').addEventListener('submit', (e) => {
e.preventDefault();
const input = document.getElementById('switchInput').value.trim();
if (!input) return;
// ID抽出
const urlMatch = input.match(/spankbang\.(?:com|party)\/([a-z0-9]+)(?:\/(?:video|play|embed)|\/|$)/i);
const id = urlMatch ? urlMatch[1] : input.replace(/^spankbang\//i, '').replace(/^\/+|\/+$/g, '');
if (id) {
window.location.href = '/spankbang/' + id;
}
});
</script>
</body>
</html>
""";
}
}