feat: 图标策略升级 + 引擎显隐就地切换 + 前后台一致性;界面美化

按反馈逐条处理:

① 界面美化
- 前台重做:品牌区(logo + 站名 + 副标题)、胶囊式引擎切换、圆角卡片与
  悬停浮起、聚焦光晕、合集标签页淡入动画;版心改为 shell 变量
  (--pad-x = max(gutter, (100% - wrap)/2)),与顶栏左右边缘严格对齐。
- 后台:表格窄屏可横向滚动、状态胶囊、自定义徽章、图标预览框。

② 自动更新图标质量差 + 允许自定义图标
- 抓取改为阶梯择优:manifest 512/192 → apple-touch-icon → <link rel=icon>
  (按 sizes 降序,SVG 视为最高清)→ 第三方聚合服务(favicon.yandex.net
  实测 100% 可用;icon.horse 可达时最高 256px)→ 站点自身 /favicon.ico。
- 逐个候选实测像素,达到 120px 即停;候选上限 8 个 + 10s 总预算,避免超时。
- 用 GD 只缩不放,统一存成 128×128 PNG;识别并丢弃第三方服务的
  「灰底字母」占位块。
- 新增 sites.icon_custom 列(带幂等迁移):可上传图标或填图标地址;
  一旦自定义,「全部更新」只刷新名称、跳过图标。

③ 后台引擎「可见/不可见」不好用
- 小图标换成内联 SVG(原来用 emoji,跨字体显示成方块)。
- 切换改为 AJAX 原地生效 + 状态胶囊同步,不再点一下就跳页;
  所有切换/移动表单都带 p 参数,无 JS 时也能正确回到当前页。
- 修掉一个隐蔽的成因:本站此前完全不发 Cache-Control/Expires/ETag,
  浏览器只能自行猜测缓存策略,导致「改完刷新还是旧的」。现在所有动态页
  统一发 no-store/no-cache。

④ deploy/ 与 data/ 误入版本库
- 两目录整目录忽略,部署脚本移出仓库(存 _tooling/),已 git rm --cached。
  (历史提交里仍含这些文件,如需彻底抹除需 git filter-repo,待确认。)

附带修复(线上实测驱动)
- 服务器侧页面缓存:宝塔「网站加速」Apache(mod_lua) 版是一层基于 memcached
  的 30 秒整页缓存,且**读不到 FastCGI 返回的 Cache-Control**,所以 no-store
  挡不住它;唯一信号是请求 cookie X_CACHE=1。已在根 .htaccess 用
  RequestHeader 在请求侧注入该标记(实测任何访客均 X-Cache: MISS),
  PHP 侧另发一颗 cookie 作为 Nginx 环境的兜底(BYPASS_PAGE_CACHE 开关)。
- 静态资源改为「长缓存 + 版本号」:asset()/icon_src() 拼 mtime+size,
  assets/.htaccess 与根 .htaccess 给出 max-age=31536000 immutable。
- 修 absolutize() 未还原 JSON 转义 \/ 导致部分图标 URL 抓不下来的问题。
- 修部署脚本 md5sum 在 Git Bash 下输出 "hash *path" 导致 38 项假「缺失文件」。
This commit is contained in:
2026-09-28 16:43:10 +08:00
parent b4b81ec45e
commit 853e4dd7c6
18 changed files with 1301 additions and 305 deletions
+29
View File
@@ -0,0 +1,29 @@
# ---------------------------------------------------------------------------
# SimpleNav —— assets/ 静态资源缓存策略
#
# 背景与理由:
# PHP 动态页面统一用 send_no_cache() 声明「不要缓存」;而 CSS / JS / 图标 /
# 字体这类静态资源如果也不缓存,每次访问都要重新下载一遍,白白浪费带宽。
# 这里采用「长缓存 + 版本号」策略:页面引用资源时一律带 ?v=<mtime>-<size>
# (见 functions.php 的 asset() / icon_src()),文件内容一变版本号就变,
# 浏览器自然会重新拉取,所以可以放心地给一年缓存。
#
# 注意:本目录下的文件不会被 Nginx 的 fastcgi_cache 影响(不经过 PHP)。
# ---------------------------------------------------------------------------
<IfModule mod_headers.c>
<FilesMatch "\.(css|js|mjs|png|jpg|jpeg|gif|svg|webp|avif|ico|woff|woff2|ttf|otf|eot|webmanifest)$">
Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>
</IfModule>
# 禁止在静态目录执行脚本
<FilesMatch "\.(php|phtml|phar|pl|py|cgi|asp|jsp|sh)$">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Deny from all
</IfModule>
</FilesMatch>
Options -ExecCGI
+72 -4
View File
@@ -1,7 +1,12 @@
/* 简航 SimpleNav —— 后台样式 */
:root {
--wrap: 1140px;
--gutter: 16px;
--pad-x: max(var(--gutter), calc((100% - var(--wrap)) / 2));
}
body.admin { background: #eef0f3; color: #333; font-size: 14px; }
.topbar {
display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 56px;
display: flex; align-items: center; gap: 16px; padding: 0 var(--pad-x); height: 56px;
background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.06); position: sticky; top: 0; z-index: 50;
}
.topbar .brand { font-size: 17px; font-weight: 700; }
@@ -12,7 +17,7 @@ body.admin { background: #eef0f3; color: #333; font-size: 14px; }
.topnav a:hover { background: #f2f4f7; }
.topnav a.active { background: #2F6BF7; color: #fff; }
.topright { display: flex; align-items: center; gap: 10px; color: #666; }
.wrap { max-width: 1140px; margin: 20px auto 60px; padding: 0 16px; }
.wrap { padding: 0 var(--pad-x); margin: 20px 0 60px; }
.card { background: #fff; border-radius: 12px; padding: 18px; margin-bottom: 18px; box-shadow: 0 2px 10px rgba(0,0,0,.04); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
@@ -43,6 +48,8 @@ body.admin { background: #eef0f3; color: #333; font-size: 14px; }
.alert.err { background: #fdecec; color: #c0392b; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
/* 窄屏下表格自己横向滚动,绝不撑破页面 */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl th, .tbl td { padding: 9px 8px; text-align: left; border-bottom: 1px solid #f0f1f3; vertical-align: middle; }
.tbl th { color: #888; font-weight: 500; }
.tbl tr:hover td { background: #fafbfc; }
@@ -52,11 +59,68 @@ body.admin { background: #eef0f3; color: #333; font-size: 14px; }
.mini { width: 26px; height: 26px; border-radius: 6px; object-fit: contain; background: #f4f5f7; }
.mini.letter { display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: 13px; }
.inline { display: inline; }
.ico-btn { border: none; background: #f2f4f7; width: 28px; height: 28px; border-radius: 6px; cursor: pointer; color: #555; margin: 0 1px; }
.ico-btn {
display: inline-flex; align-items: center; justify-content: center;
border: none; background: #f2f4f7; width: 28px; height: 28px; border-radius: 6px;
cursor: pointer; color: #555; margin: 0 1px; padding: 0; transition: background .15s, color .15s;
}
.ico-btn:hover { background: #e6e9ee; }
.ico-btn:disabled { opacity: .5; cursor: default; }
.ico-btn.danger { color: #c0392b; }
.ico-btn.danger:hover { background: #fdecec; }
.ok-dot { color: #1a7f45; font-size: 12px; }
/* 显示 / 隐藏 切换按钮:绿=显示中,灰=已隐藏 */
.ico-btn.toggle { color: #9aa3af; }
.ico-btn.toggle:hover { background: #e6e9ee; color: #555; }
.ico-btn.toggle.on { color: #1a7f45; background: #e8f6ee; }
.ico-btn.toggle.on:hover { background: #d6efe1; }
.ico-btn.toggle svg { display: block; }
/* 状态胶囊 */
.state {
display: inline-block; min-width: 52px; padding: 2px 8px; border-radius: 10px;
font-size: 12px; line-height: 18px; text-align: center; vertical-align: middle;
}
.state.on { background: #e8f6ee; color: #1a7f45; }
.state.off { background: #f1f3f5; color: #98a2b3; }
/* 「自定义图标」标记 */
.badge {
display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 8px;
background: #eef3ff; color: #2F6BF7; font-size: 11px; line-height: 16px; vertical-align: middle;
}
/* 图数字段 */
.icon-field {
display: flex; gap: 16px; align-items: flex-start; padding: 12px;
border: 1px dashed #d9dde3; border-radius: 10px; background: #fafbfc;
}
.icon-field-preview { flex: 0 0 72px; }
.icon-preview {
display: flex; align-items: center; justify-content: center; width: 72px; height: 72px;
border-radius: 14px; background: #fff; border: 1px solid #e6e9ee; overflow: hidden;
}
.icon-preview img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.icon-preview .ph { color: #bbb; font-size: 12px; }
.icon-field-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.icon-field-title { font-size: 13px; color: #555; font-weight: 600; }
.icon-field-body input[type=text] {
height: 38px; padding: 0 10px; border: 1px solid #d9dde3; border-radius: 8px; font-size: 14px; width: 100%;
}
.icon-field-body input[type=text]:focus { outline: none; border-color: #2F6BF7; }
.icon-row2 { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.icon-row2 .chk { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: #555; }
.icon-row2 input[type=file] {
font-size: 13px; color: #666; background: #fff; border: 1px solid #d9dde3;
border-radius: 8px; padding: 6px 8px; max-width: 300px;
}
.icon-field .hint { line-height: 1.75; margin: 0; }
.icon-field .hint b { color: #2F6BF7; }
/* 已隐藏的行稍作弱化 */
.tbl tr.row-off td:first-child, .tbl tr.row-off td:nth-child(2) { color: #98a2b3; }
/* 登录页 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 340px; background: #fff; border-radius: 14px; padding: 30px 26px; box-shadow: 0 10px 30px rgba(0,0,0,.08); text-align: center; }
@@ -69,6 +133,10 @@ body.admin { background: #eef0f3; color: #333; font-size: 14px; }
@media (max-width: 720px) {
.grid-form { grid-template-columns: 1fr; }
.topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; }
.topbar { flex-wrap: wrap; height: auto; padding: 10px var(--pad-x); }
.tbl { min-width: 620px; }
.tbl .ell { max-width: 120px; }
.icon-field { flex-direction: column; }
.icon-field-preview { flex: 0 0 auto; }
.icon-row2 input[type=file] { max-width: 100%; }
}
+138 -62
View File
@@ -1,116 +1,192 @@
/* 简航 SimpleNav —— 样式(复刻 n.yangyq.net 的灰底白卡片风格,去 Bootstrap 依赖) */
:root { --primary: #2F6BF7; }
/* 简航 SimpleNav —— 前台样式
在 n.yangyq.net「浅灰底 + 白卡片」基础上做了现代化处理:
圆角更大、阴影分层、悬停微动效、顶部品牌区与胶囊式搜索引擎切换。 */
:root {
--primary: #2F6BF7;
--primary-dark: #2456cc;
--primary-soft: #eef3ff;
--bg-1: #f4f6fa;
--bg-2: #e8ecf4;
--card: #ffffff;
--text: #22262b;
--muted: #7b8794;
--line: #eaedf3;
--radius-lg: 18px;
--radius: 12px;
/* 版心:只推一次 —— 顶栏与正文共用同一个左右内边距,两边算出来严格相等 */
--wrap: 1140px;
--gutter: 16px;
--pad-x: max(var(--gutter), calc((100% - var(--wrap)) / 2));
--shadow-sm: 0 1px 2px rgba(23, 43, 77, .05), 0 4px 12px rgba(23, 43, 77, .05);
--shadow: 0 2px 4px rgba(23, 43, 77, .04), 0 10px 30px rgba(23, 43, 77, .08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
margin: 0;
min-height: 100vh;
font-size: 14px;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
background: #d8d9da;
color: #333;
color: var(--text);
background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 100%) fixed;
overflow-x: hidden;
-webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
.container { max-width: 1140px; margin: 50px auto 40px; padding: 0 15px; }
.container { padding: 0 var(--pad-x); margin: 0 0 40px; }
/* ---------- 顶部品牌区 ---------- */
.hero { text-align: center; padding: 52px 0 22px; }
.hero .logo {
display: block; width: 60px; height: 60px; margin: 0 auto 14px; border-radius: 18px;
box-shadow: 0 8px 22px rgba(47, 107, 247, .28);
}
.hero h1 { margin: 0; font-size: 25px; font-weight: 600; letter-spacing: .5px; }
.hero p { margin: 7px 0 0; font-size: 13px; color: var(--muted); }
/* ---------- 搜索 ---------- */
.s-search { position: relative; z-index: 2000; margin-bottom: 10px; }
.search-type { margin-bottom: 0; }
.s-search { position: relative; z-index: 2000; max-width: 760px; margin: 0 auto 6px; }
.search-type { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 14px; }
.s-engine {
display: inline-block; padding: 6px 14px; margin: 0 2px 0 0;
background: rgba(255,255,255,.45); border-radius: 5px 5px 0 0; cursor: pointer;
font-size: 14px; line-height: 20px; transition: background .2s;
display: inline-block; padding: 6px 16px; border-radius: 999px; cursor: pointer;
background: rgba(255, 255, 255, .72); border: 1px solid rgba(255, 255, 255, .9);
font-size: 14px; line-height: 20px; color: #4a5568;
transition: transform .18s, box-shadow .18s, background .18s, color .18s;
user-select: none;
}
.s-engine span { color: var(--ec, #555); }
.s-engine:hover { background: rgba(255,255,255,.75); }
.s-engine.active { background: #fff; }
.s-engine:hover { background: #fff; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.s-engine.active {
background: var(--ec, var(--primary)); border-color: var(--ec, var(--primary));
box-shadow: 0 6px 16px rgba(47, 107, 247, .26);
}
.s-engine.active span { color: #fff; }
#search-form { position: relative; }
#search-text {
width: 100%; height: 50px; line-height: 50px; text-indent: 14px; font-size: 16px;
border: none; border-radius: 5px; background: #fff; outline: 0;
box-shadow: 0 0.5rem 0.625rem rgba(212,212,212,.3); transition: box-shadow .3s;
width: 100%; height: 56px; line-height: 56px; text-indent: 22px; padding-right: 64px;
font-size: 16px; border: 2px solid transparent; border-radius: 28px; background: #fff;
color: var(--text); outline: 0; box-shadow: var(--shadow);
transition: border-color .2s, box-shadow .25s;
}
#search-text::placeholder { color: #a9b3c0; }
#search-text:focus {
border-color: var(--primary);
box-shadow: 0 0 0 5px rgba(47, 107, 247, .12), var(--shadow);
}
#search-text:focus { box-shadow: 0 0 24px 0 rgba(50,50,50,.08); }
#search button.submit {
position: absolute; top: 7px; right: 7px; width: 60px; height: 36px;
background: none; border: 0; border-radius: 3px; cursor: pointer; outline: none;
}
#search button.submit::after {
content: ""; display: block; width: 16px; height: 16px; margin: 0 auto;
border: 2px solid #c9c9c9; border-radius: 50%; position: relative;
}
#search button.submit::before {
content: ""; position: absolute; right: 20px; bottom: 9px; width: 7px; height: 2px;
background: #c9c9c9; transform: rotate(45deg);
position: absolute; top: 8px; right: 8px; width: 40px; height: 40px;
display: flex; align-items: center; justify-content: center;
border: 0; border-radius: 50%; background: var(--primary); color: #fff;
cursor: pointer; outline: none; transition: background .2s, transform .2s;
}
#search button.submit:hover { background: var(--primary-dark); transform: scale(1.05); }
#search button.submit:active { transform: scale(.96); }
#word {
position: absolute; list-style: none; top: 55px; left: 0; width: 100%; margin: 0;
background: #fff; border-radius: 5px; z-index: 20000; padding: 10px;
box-shadow: 0 0 10px #bbb; display: none;
position: absolute; list-style: none; top: 64px; left: 0; width: 100%; margin: 0;
background: #fff; border-radius: 16px; z-index: 20000; padding: 8px;
box-shadow: 0 16px 44px rgba(23, 43, 77, .16); display: none;
max-height: 336px; overflow-y: auto;
}
#word li { height: 35px; padding: 0 8px; line-height: 35px; cursor: pointer; font-size: 16px; border-radius: 5px; }
#word li:hover { background: #eee; }
#word li {
padding: 0 14px; height: 38px; line-height: 38px; cursor: pointer;
font-size: 15px; border-radius: 10px; color: #3d4753;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#word li:hover { background: var(--primary-soft); color: var(--primary); }
/* ---------- 板块卡片 ---------- */
.mylist {
list-style: none; margin: 16px 0; padding: 12px 20px;
background: #fff; border-radius: 15px; box-shadow: 0 0.5rem 0.625rem rgba(212,212,212,.3);
display: flex; flex-wrap: wrap;
list-style: none; margin: 18px 0; padding: 16px 20px 14px;
background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow);
display: flex; flex-wrap: wrap; transition: box-shadow .25s;
}
.mylist:hover { box-shadow: 0 4px 8px rgba(23, 43, 77, .05), 0 14px 38px rgba(23, 43, 77, .1); }
.mylist > li.title {
width: 100%; margin: 0 0 10px; padding: 0 0 8px 10px; height: auto;
font-size: 16px; font-weight: 600; line-height: 24px;
border-bottom: 1px solid #eee; position: relative;
width: 100%; margin: 0 0 12px; padding: 0 0 10px 14px; height: auto;
font-size: 16px; font-weight: 600; line-height: 22px; color: #1f2733;
border-bottom: 1px solid var(--line); position: relative;
}
.mylist > li.title::before {
content: ""; position: absolute; left: 0; top: 3px; width: 4px; height: 18px;
background: var(--primary); border-radius: 2px;
content: ""; position: absolute; left: 0; top: 3px; width: 4px; height: 17px;
background: linear-gradient(180deg, var(--primary), #6f9bff);
border-radius: 2px;
}
.mylist > li.site { margin: 2px; }
.mylist li.site a {
display: flex; flex-direction: column; align-items: center; width: 100px; padding: 10px 4px;
border-radius: 10px; transition: background .2s;
display: flex; flex-direction: column; align-items: center; width: 104px;
padding: 12px 6px 10px; border-radius: 14px;
transition: background .2s, transform .2s;
}
.mylist li.site a:hover { background: #f0f1f2; }
.mylist li.site .icon { width: 45px; height: 45px; border-radius: 10px; background: #fff; object-fit: contain; }
.mylist li.site a:hover { background: linear-gradient(180deg, #f7f9ff, var(--primary-soft)); transform: translateY(-3px); }
.mylist li.site .icon {
width: 46px; height: 46px; border-radius: 12px; background: #fff;
object-fit: contain; box-shadow: 0 2px 8px rgba(23, 43, 77, .09);
transition: transform .2s;
}
.mylist li.site a:hover .icon { transform: scale(1.07); }
.mylist li.site .ico-letter {
width: 45px; height: 45px; border-radius: 10px; color: #fff; font-size: 20px; font-weight: 600;
width: 46px; height: 46px; border-radius: 12px; color: #fff; font-size: 20px; font-weight: 600;
display: flex; align-items: center; justify-content: center;
box-shadow: 0 2px 8px rgba(23, 43, 77, .14); transition: transform .2s;
}
.mylist li.site a:hover .ico-letter { transform: scale(1.07); }
.mylist li.site .name {
width: 100%; margin-top: 6px; text-align: center; font-size: 13px; color: #555;
width: 100%; margin-top: 8px; text-align: center; font-size: 13px; color: #5b6673;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
transition: color .2s;
}
.mylist li.site a:hover .name { color: var(--primary); }
/* ---------- 合集标签页 ---------- */
.collections { margin: 16px 0; }
.collections { margin: 24px 0 0; }
.collections-title {
font-size: 16px; font-weight: 600; padding: 0 0 8px 10px; margin: 0 0 10px;
position: relative;
font-size: 16px; font-weight: 600; color: #1f2733;
padding: 0 0 10px 14px; margin: 0 0 14px; position: relative;
}
.collections-title::before {
content: ""; position: absolute; left: 0; top: 3px; width: 4px; height: 18px;
background: var(--primary); border-radius: 2px;
content: ""; position: absolute; left: 0; top: 3px; width: 4px; height: 17px;
background: linear-gradient(180deg, var(--primary), #6f9bff); border-radius: 2px;
}
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.tabs { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 14px; }
.tabs .tab {
border: none; background: rgba(255,255,255,.65); color: #444; cursor: pointer;
padding: 7px 16px; border-radius: 18px; font-size: 14px; transition: all .2s;
border: 1px solid rgba(255, 255, 255, .9); background: rgba(255, 255, 255, .72);
color: #4a5568; cursor: pointer; padding: 8px 18px; border-radius: 999px;
font-size: 14px; transition: all .18s;
}
.tabs .tab:hover { background: #fff; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.tabs .tab.active {
background: var(--primary); border-color: var(--primary); color: #fff;
box-shadow: 0 6px 16px rgba(47, 107, 247, .26);
}
.tabs .tab:hover { background: #fff; }
.tabs .tab.active { background: var(--primary); color: #fff; }
.tab-panel { display: none; }
.tab-panel.active { display: flex; }
.tab-panel.active { display: flex; animation: fadeUp .28s ease both; }
@keyframes fadeUp {
from { opacity: 0; transform: translateY(8px); }
to { opacity: 1; transform: none; }
}
/* ---------- 页脚 ---------- */
.foot { text-align: center; color: #8a8a8a; font-size: 12px; margin: 24px 0 0; }
.foot a { color: #8a8a8a; }
.foot {
text-align: center; color: #97a1ae; font-size: 12px; margin: 30px 0 0;
padding-top: 18px; border-top: 1px solid rgba(23, 43, 77, .06);
}
.foot a { color: #97a1ae; transition: color .2s; }
.foot a:hover { color: var(--primary); }
/* ---------- 响应式 ---------- */
@media (max-width: 767px) {
.container { margin-top: 24px; }
.mylist { border-radius: 10px; padding: 10px 12px; }
.mylist li.site a { width: 25%; }
.mylist li.site .icon, .mylist li.site .ico-letter { width: 40px; height: 40px; }
.hero { padding: 28px 0 16px; }
.hero .logo { width: 52px; height: 52px; border-radius: 15px; }
.hero h1 { font-size: 21px; }
.s-search { margin-bottom: 2px; }
.search-type { gap: 6px; margin-bottom: 10px; }
.s-engine { padding: 5px 13px; font-size: 13px; }
#search-text { height: 50px; line-height: 50px; font-size: 15px; text-indent: 18px; }
#word { top: 58px; }
.mylist { border-radius: 14px; padding: 12px 12px 10px; }
.mylist li.site a { width: 25%; padding: 10px 2px 8px; }
.mylist li.site .icon, .mylist li.site .ico-letter { width: 42px; height: 42px; }
.mylist li.site .name { font-size: 12px; }
}
+142 -16
View File
@@ -1,7 +1,15 @@
/* 简航 SimpleNav —— 后台交互 */
(function () {
'use strict';
var $ = function (s) { return document.querySelector(s); };
var $ = function (s, r) { return (r || document).querySelector(s); };
var $$ = function (s, r) { return Array.prototype.slice.call((r || document).querySelectorAll(s)); };
/* ---------- 显示图标预览 ---------- */
function setPreview(src) {
var box = $('#f-icon-preview');
if (!box) return;
box.innerHTML = src ? '<img src="' + src + '" alt="">' : '<span class="ph">无</span>';
}
/* ---------- 自动获取网站信息 ---------- */
var fetchBtn = $('#btn-fetch');
@@ -10,7 +18,7 @@
var url = ($('#f-url') || {}).value || '';
var hint = $('#fetch-hint');
if (!url) { if (hint) hint.textContent = '请先填写网址'; return; }
if (hint) hint.textContent = '正在获取…';
if (hint) hint.textContent = '正在获取标题与高清图标…';
fetchBtn.disabled = true;
fetch(fetchBtn.getAttribute('data-url') + '?url=' + encodeURIComponent(url))
.then(function (r) { return r.json(); })
@@ -19,23 +27,73 @@
if (!d.ok) { if (hint) hint.textContent = d.msg || '获取失败'; return; }
if ($('#f-name')) $('#f-name').value = d.name || '';
if ($('#f-short') && !$('#f-short').value) $('#f-short').value = d.short || d.name || '';
if ($('#f-icon')) $('#f-icon').value = d.icon || '';
if (hint) hint.textContent = (d.icon ? '已获取名称与图标' : '已获取名称(未找到图标)') + (d.url ? ':' + d.url : '');
var auto = $('#f-icon-auto');
var locked = auto && !auto.checked;
if (!locked) {
if ($('#f-icon')) $('#f-icon').value = d.icon || '';
setPreview(d.icon_url || '');
}
var parts = ['已获取名称'];
parts.push(d.icon ? ('已获取图标(候选 ' + (d.candidates || 1) + ' 个)') : '未找到图标,将回退为首字母块');
if (locked) parts.push('(当前为自定义图标,未覆盖)');
if (hint) hint.textContent = parts.join(',');
})
.catch(function () { fetchBtn.disabled = false; if (hint) hint.textContent = '网络错误'; });
});
}
/* ---------- 图标:上传文件 / 自定义地址 ---------- */
var fileInput = $('#f-icon-file');
if (fileInput) {
fileInput.addEventListener('change', function () {
var f = fileInput.files && fileInput.files[0];
if (!f) return;
var auto = $('#f-icon-auto');
if (auto) auto.checked = false; // 一旦自定义,自动取消「允许自动更新」
if (window.URL && URL.createObjectURL) { setPreview(URL.createObjectURL(f)); }
var hint = $('#fetch-hint');
if (hint) hint.textContent = '已选择本地图标:' + f.name + '(保存后生效,并将锁定不再自动更新)';
});
}
var urlInput = $('#f-icon-url');
if (urlInput) {
urlInput.addEventListener('change', function () {
var v = urlInput.value.trim();
if (!v) return;
var auto = $('#f-icon-auto');
if (auto) auto.checked = false;
setPreview(v);
});
}
var autoBox = $('#f-icon-auto');
if (autoBox) {
autoBox.addEventListener('change', function () {
var hint = $('#fetch-hint');
if (!hint) return;
hint.textContent = autoBox.checked
? '已开启自动更新:该网站图标会在「全部更新」时刷新'
: '已关闭自动更新:该网站图标将被锁定';
});
}
/* ---------- 清空表单 ---------- */
var resetBtn = $('#btn-reset');
if (resetBtn) {
resetBtn.addEventListener('click', function () {
['f-id', 'f-url', 'f-name', 'f-short', 'f-icon'].forEach(function (id) { var el = $('#' + id); if (el) el.value = id === 'f-id' ? '0' : ''; });
['f-id', 'f-url', 'f-name', 'f-short', 'f-icon', 'f-icon-url'].forEach(function (id) {
var el = $('#' + id); if (el) el.value = id === 'f-id' ? '0' : '';
});
var fi = $('#f-icon-file'); if (fi) fi.value = '';
var v = $('#f-visible'); if (v) v.checked = true;
var a = $('#f-icon-auto'); if (a) a.checked = true;
var h = $('#fetch-hint'); if (h) h.textContent = '';
setPreview('');
});
}
/* ---------- 编辑网站:回填表单 ---------- */
document.querySelectorAll('.edit-site').forEach(function (btn) {
$$('.edit-site').forEach(function (btn) {
btn.addEventListener('click', function () {
var d = btn.dataset;
$('#f-id').value = d.id;
@@ -44,13 +102,19 @@
$('#f-name').value = d.name;
$('#f-short').value = d.short;
$('#f-icon').value = d.icon;
if ($('#f-icon-url')) $('#f-icon-url').value = '';
if ($('#f-icon-file')) $('#f-icon-file').value = '';
if ($('#f-icon-auto')) $('#f-icon-auto').checked = d.custom !== '1';
$('#f-visible').checked = d.visible === '1';
setPreview(d.iconUrl || '');
var hint = $('#fetch-hint');
if (hint) hint.textContent = d.custom === '1' ? '该网站图标为自定义,不会被「全部更新」覆盖' : '';
window.scrollTo({ top: 0, behavior: 'smooth' });
});
});
/* ---------- 编辑板块 / 引擎 ---------- */
document.querySelectorAll('.edit-group').forEach(function (btn) {
$$('.edit-group').forEach(function (btn) {
btn.addEventListener('click', function () {
var d = btn.dataset;
$('#g-id').value = d.id; $('#g-name').value = d.name;
@@ -61,7 +125,7 @@
var gReset = $('#g-reset');
if (gReset) gReset.addEventListener('click', function () { $('#g-id').value = '0'; $('#g-name').value = ''; $('#g-display').value = 'grid'; $('#g-visible').checked = true; });
document.querySelectorAll('.edit-engine').forEach(function (btn) {
$$('.edit-engine').forEach(function (btn) {
btn.addEventListener('click', function () {
var d = btn.dataset;
$('#e-id').value = d.id; $('#e-name').value = d.name; $('#e-slug').value = d.slug;
@@ -76,29 +140,91 @@
$('#e-param').value = 'q'; $('#e-active').checked = false;
});
/* ---------- 一键“全部更新”(分批循环) ---------- */
/* ---------- 列表内「显示 / 隐藏」原地切换(不跳页) ---------- */
$$('form.js-toggle').forEach(function (form) {
form.addEventListener('submit', function (ev) {
var btn = $('button.toggle', form);
if (btn) btn.disabled = true;
ev.preventDefault();
fetch(form.getAttribute('action'), {
method: 'POST',
body: new FormData(form),
credentials: 'same-origin',
headers: { 'X-Requested-With': 'XMLHttpRequest' }
})
.then(function (r) { return r.json(); })
.then(function (d) {
if (btn) btn.disabled = false;
if (!d || !d.ok) { alert((d && d.msg) || '切换失败'); return; }
applyToggleState(form, d.state);
})
.catch(function () {
if (btn) btn.disabled = false;
// AJAX 失败时退回普通提交,保证功能可用(表单已带 p,会回到当前页)
var ajax = form.querySelector('input[name="ajax"]');
if (ajax) { ajax.parentNode.removeChild(ajax); }
form.submit();
});
});
});
function applyToggleState(form, state) {
var on = state === 1;
var btn = $('button.toggle', form);
if (btn) {
btn.classList.toggle('on', on);
btn.setAttribute('data-on', on ? '1' : '0');
btn.setAttribute('title', on ? '当前:显示中(点击隐藏)' : '当前:已隐藏(点击显示)');
var svg = btn.querySelector('path[stroke]');
var circle = btn.querySelector('circle');
if (on) {
if (svg) svg.remove();
} else if (circle && !svg) {
var p = document.createElementNS('http://www.w3.org/2000/svg', 'path');
p.setAttribute('d', 'M3 3l18 18');
p.setAttribute('stroke', 'currentColor');
p.setAttribute('stroke-width', '2');
p.setAttribute('stroke-linecap', 'round');
btn.querySelector('svg').appendChild(p);
}
}
// 同行的状态文字(如搜索引擎的「已显示 / 已隐藏」)
var cell = form.closest('td') || form.parentNode;
var st = cell ? $('.js-state', cell) : null;
if (st) {
st.textContent = on ? (st.dataset.onText || '已显示') : (st.dataset.offText || '已隐藏');
st.classList.toggle('on', on);
st.classList.toggle('off', !on);
}
var row = form.closest('tr');
if (row) {
row.classList.toggle('row-off', !on);
}
}
/* ---------- 一键「全部更新」(分批循环) ---------- */
var upBtn = $('#btn-update-all');
if (upBtn) {
upBtn.addEventListener('click', function () {
if (!confirm('将批量刷新所有网站的图标与名称(用户自定义简称不受影响),确定继续?')) return;
if (!confirm('将批量刷新所有网站的名称与自动图标。\n用户自定义简称不受影响;标记为「自定义」的图标会被跳过。\n确定继续?')) return;
var base = upBtn.getAttribute('data-url');
var total = 0, updated = 0, failed = 0, offset = 0;
var total = 0, updated = 0, failed = 0, skipped = 0, offset = 0;
upBtn.disabled = true;
function step() {
fetch(base + '?offset=' + offset + '&limit=6')
fetch(base + '?offset=' + offset + '&limit=3', { credentials: 'same-origin' })
.then(function (r) { return r.json(); })
.then(function (d) {
total = d.total; updated += d.updated; failed += d.failed; offset = d.offset;
total = d.total; updated += d.updated; failed += d.failed; skipped += (d.skipped || 0); offset = d.offset;
upBtn.textContent = '⟳ 更新中 ' + Math.min(offset, total) + '/' + total;
if (!d.done) { step(); }
else {
upBtn.disabled = false;
upBtn.textContent = '⟳ 全部更新(图标+名称)';
alert('更新完成:成功 ' + updated + ',失败/无变化 ' + failed + ',共 ' + total + ' 个网站。');
upBtn.textContent = '⟳ 全部更新(名称 + 自动图标)';
alert('更新完成:\n成功 ' + updated + ' 个\n跳过(自定义图标)' + skipped + ' 个\n失败/无变化 ' + failed + ' 个\n共 ' + total + ' 个网站。');
location.reload();
}
})
.catch(function () { upBtn.disabled = false; upBtn.textContent = '⟳ 全部更新(图标+名称)'; alert('更新中断,请重试。'); });
.catch(function () { upBtn.disabled = false; upBtn.textContent = '⟳ 全部更新(名称 + 自动图标)'; alert('更新中断,请重试。'); });
}
step();
});
+30 -6
View File
@@ -15,9 +15,8 @@
var param = el.getAttribute('data-param');
var slug = el.getAttribute('data-slug');
var ph = el.getAttribute('data-placeholder') || '搜索';
if (form) { form.setAttribute('action', search); }
if (form) { form.setAttribute('action', search); form.setAttribute('data-slug', slug); }
if (input) { input.setAttribute('name', param); input.setAttribute('placeholder', ph); }
form.setAttribute('data-slug', slug);
hideWord();
}
tabs.forEach(function (el) {
@@ -34,9 +33,9 @@
if (!word) return;
if (!items || !items.length) { hideWord(); return; }
word.innerHTML = items.map(function (t) {
var d = document.createElement('div');
var d = document.createElement('li');
d.textContent = t;
return '<li>' + d.innerHTML + '</li>';
return d.outerHTML;
}).join('');
word.style.display = 'block';
}
@@ -69,7 +68,7 @@
document.addEventListener('click', function (e) {
if (word && !word.contains(e.target) && e.target !== input) { hideWord(); }
var li = e.target.closest ? e.target.closest('#word li') : null;
if (li) {
if (li && input) {
input.value = li.textContent;
hideWord();
if (form) { form.submit(); }
@@ -80,11 +79,36 @@
var collTabs = document.querySelectorAll('#coll-tabs .tab');
collTabs.forEach(function (tab) {
tab.addEventListener('click', function () {
collTabs.forEach(function (t) { t.classList.remove('active'); });
collTabs.forEach(function (t) {
t.classList.remove('active');
t.setAttribute('aria-selected', 'false');
});
tab.classList.add('active');
tab.setAttribute('aria-selected', 'true');
document.querySelectorAll('.tab-panel').forEach(function (p) { p.classList.remove('active'); });
var panel = document.getElementById(tab.getAttribute('data-target'));
if (panel) { panel.classList.add('active'); }
});
});
/* ---------- 图标加载失败 → 退回首字母块(与 PHP 端配色一致) ---------- */
var PALETTE = ['#2F6BF7', '#5B8DEF', '#0EA5E9', '#10B981', '#F59E0B', '#EF4444', '#8B5CF6', '#EC4899', '#14B8A6', '#F97316'];
function colorOf(s) {
var h = 0;
for (var i = 0; i < s.length; i++) { h = (h * 31 + s.charCodeAt(i)) | 0; }
return PALETTE[Math.abs(h) % PALETTE.length];
}
document.querySelectorAll('.mylist img.icon').forEach(function (img) {
img.addEventListener('error', function () {
var a = img.closest('a');
if (!a) { img.style.visibility = 'hidden'; return; }
var nameEl = a.querySelector('.name');
var label = (nameEl ? nameEl.textContent : '?').trim() || '?';
var span = document.createElement('span');
span.className = 'ico-letter';
span.style.background = colorOf(label);
span.textContent = label.charAt(0);
img.parentNode.replaceChild(span, img);
}, { once: true });
});
})();