// ==UserScript== // @name 嘉立创社区布局优化 // @namespace http://tampermonkey.net/ // @version 1.5.0 // @description 优化嘉立创社区(jlc-bbs.com)布局:隐藏右侧低价值模块、内容区扩展、合并操作行、删除问题状态、紧凑间距、官方筛选 // @author You // @match https://www.jlc-bbs.com/* // @icon https://www.jlc-bbs.com/ssr/img/logo.970c992.svg // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @run-at document-idle // ==/UserScript== (function () { 'use strict'; // ========== 配置项 ========== const CONFIG = { // 右侧边栏各个模块的可见性(默认全部隐藏) sidebarBlocks: { '社区数据': false, // 今日帖子/互动量/在线人数等统计 '活动日历': false, // 活动日历 '推荐话题': false, // 推荐话题标签 '打赏记录': false, // 打赏记录列表 '涨分锦囊': false, // 积分任务 '广告横幅': false, // 积分抽奖等广告图 '页脚链接': false, // 备案信息等 }, // 是否隐藏整个右侧边栏 hideRightSidebar: true, // 主内容区最大宽度(null 表示不限,随屏幕自适应) contentMaxWidth: null, // 是否显示切换按钮(允许临时恢复右侧边栏) showToggleButton: true, }; // 从存储加载用户配置 const savedConfig = GM_getValue('layoutConfig', null); if (savedConfig) { try { const parsed = JSON.parse(savedConfig); if (parsed.sidebarBlocks) { CONFIG.sidebarBlocks = { ...CONFIG.sidebarBlocks, ...parsed.sidebarBlocks }; } if (parsed.hideRightSidebar !== undefined) { CONFIG.hideRightSidebar = parsed.hideRightSidebar; } if (parsed.contentMaxWidth !== undefined) { CONFIG.contentMaxWidth = parsed.contentMaxWidth; } } catch (e) { /* 忽略解析错误,使用默认配置 */ } } // 保存配置到存储 function saveConfig() { GM_setValue('layoutConfig', JSON.stringify({ sidebarBlocks: CONFIG.sidebarBlocks, hideRightSidebar: CONFIG.hideRightSidebar, contentMaxWidth: CONFIG.contentMaxWidth, })); } // ========== 样式注入 ========== function applyStyles() { // 移除旧的样式 const oldStyle = document.getElementById('jlc-layout-optimize-style'); if (oldStyle) oldStyle.remove(); let css = ''; if (CONFIG.hideRightSidebar) { // 隐藏右侧边栏容器 css += ` /* 隐藏右侧 sticky-wrap(第2个) */ .content.flex.relative > .sticky-wrap:nth-child(3) { display: none !important; } /* 移除主内容区最大宽度限制,让它填充 */ .content.flex.relative > .flex-1 { max-width: none !important; } `; } else { // 按模块逐个控制可见性 const rightSidebar = document.querySelector('.position-sticky.w-\\[310px\\]'); if (rightSidebar) { const blocks = rightSidebar.children; for (let i = 0; i < blocks.length; i++) { const block = blocks[i]; const titleEl = block.querySelector('h3, h4, [class*="title"]'); const title = titleEl ? titleEl.textContent.trim() : ''; const preview = block.textContent.substring(0, 50).trim(); // 匹配模块名称 let matched = false; for (const [name, visible] of Object.entries(CONFIG.sidebarBlocks)) { if (preview.includes(name) && !visible) { block.style.display = 'none'; matched = true; break; } } if (!matched) { block.style.display = ''; } } } } // 如果设置了自定义最大宽度 if (CONFIG.contentMaxWidth) { css += ` .content.flex.relative > .flex-1 { max-width: ${CONFIG.contentMaxWidth}px !important; } `; } // 通用优化:发帖区域也扩大 css += ` /* 发帖框宽度自适应 */ .content.flex.relative > .flex-1 .mt-\\[20px\\] { max-width: 100% !important; } /* ===== 搜索框加宽 + 颜色增强 ===== */ .search-input.el-input { width: 500px !important; } .search-input .el-input__inner { background-color: #fff !important; border: 1.5px solid #c0c4cc !important; border-radius: 20px !important; height: 36px !important; line-height: 36px !important; padding-left: 36px !important; font-size: 14px !important; color: #333 !important; } .search-input .el-input__inner::placeholder { color: #909399 !important; } .search-input .el-input__inner:focus { border-color: #1890ff !important; box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.15) !important; } .search-input .el-input__prefix { left: 12px !important; } /* ===== 紧凑间距:20px → 8px ===== */ /* 主内容区内边距 */ .flex-1.bg-\\[\\#f2f3f5\\] { padding-left: 8px !important; padding-right: 8px !important; } /* 发帖框顶部间距 */ .flex-1.bg-\\[\\#f2f3f5\\] > .mt-\\[20px\\] { margin-top: 8px !important; } /* 卡片内边距 上下 */ .borderb, .borderb.px-0.relative { padding-top: 8px !important; padding-bottom: 8px !important; } /* 卡片内容区信息行间距 */ .borderb .mr-\\[20px\\] { margin-right: 8px !important; } /* 左侧/右侧导航 pt-20 → 8px */ .sticky-wrap.pt-20, .sticky-wrap.pt-\\[20px\\] { padding-top: 8px !important; } /* 发帖编辑区内边距 */ .px-\\[20px\\].pt-\\[20px\\] { padding-left: 8px !important; padding-right: 8px !important; padding-top: 8px !important; } /* ===== 合并操作行后的样式 ===== */ /* info-part-2 容器:允许换行,对齐 */ .info-part-2.flex.items-center { flex-wrap: wrap !important; gap: 0 4px !important; } /* 合并进来的 menu 容器 */ .info-part-2 .menu { display: inline-flex !important; align-items: center !important; } .info-part-2 .menu .flex.items-center { display: inline-flex !important; align-items: center !important; } /* 合并后的按钮缩小间距和字号 */ .info-part-2 .menu .el-tooltip, .info-part-2 .menu .share-btn, .info-part-2 .menu .flag-btn { margin-right: 12px !important; font-size: 12px !important; color: #899099 !important; display: inline-flex !important; align-items: center !important; gap: 3px !important; } .info-part-2 .menu .el-tooltip img, .info-part-2 .menu .share-btn img, .info-part-2 .menu .flag-btn img { width: 14px !important; height: 14px !important; } .info-part-2 .menu .el-tooltip span, .info-part-2 .menu .share-btn span, .info-part-2 .menu .flag-btn span { font-size: 12px !important; } /* 分隔符 */ .jlc-separator { color: #d0d5da; margin: 0 6px; font-size: 12px; } /* ===== 官方筛选按钮选中样式 ===== */ .jlc-official-filter.question-type-active { color: #1890ff !important; font-weight: 600 !important; } /* 合并进来的标签(如"嘉立创EDA") */ .info-part-2 > .text-\\[\\#899099\\] { margin-left: 4px !important; font-size: 12px !important; } /* 切换按钮样式 */ #jlc-sidebar-toggle { position: fixed; right: 16px; bottom: 80px; z-index: 9999; width: 40px; height: 40px; border-radius: 50%; background: #fff; border: 1px solid #e0e0e0; box-shadow: 0 2px 8px rgba(0,0,0,0.15); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 18px; transition: all 0.2s ease; color: #666; line-height: 1; } #jlc-sidebar-toggle:hover { background: #f5f5f5; box-shadow: 0 4px 12px rgba(0,0,0,0.2); color: #333; } #jlc-sidebar-toggle.sidebar-visible { background: #1890ff; color: #fff; border-color: #1890ff; } #jlc-sidebar-toggle.sidebar-visible:hover { background: #40a9ff; } /* 设置面板样式 */ #jlc-settings-panel { position: fixed; right: 16px; bottom: 130px; z-index: 9999; background: #fff; border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,0.18); padding: 20px; width: 280px; font-size: 13px; display: none; } #jlc-settings-panel.visible { display: block; } #jlc-settings-panel h4 { margin: 0 0 12px 0; font-size: 15px; font-weight: 600; color: #333; border-bottom: 1px solid #eee; padding-bottom: 8px; } .jlc-setting-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; color: #555; } .jlc-setting-row label { cursor: pointer; user-select: none; } .jlc-setting-row input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: #1890ff; } .jlc-setting-divider { height: 1px; background: #eee; margin: 10px 0; } .jlc-setting-btn { display: inline-block; padding: 4px 12px; border-radius: 4px; border: 1px solid #d9d9d9; background: #fff; cursor: pointer; font-size: 12px; color: #555; margin-right: 6px; margin-top: 8px; transition: all 0.15s; } .jlc-setting-btn:hover { border-color: #1890ff; color: #1890ff; } `; // 注入样式 const styleEl = document.createElement('style'); styleEl.id = 'jlc-layout-optimize-style'; styleEl.textContent = css; document.head.appendChild(styleEl); } // ========== UI 控件 ========== // 创建切换按钮 function createToggleButton() { if (!CONFIG.showToggleButton) return; if (document.getElementById('jlc-sidebar-toggle')) return; const btn = document.createElement('button'); btn.id = 'jlc-sidebar-toggle'; btn.title = CONFIG.hideRightSidebar ? '显示右侧边栏' : '隐藏右侧边栏'; btn.innerHTML = CONFIG.hideRightSidebar ? '📱' : '📐'; btn.addEventListener('click', () => { CONFIG.hideRightSidebar = !CONFIG.hideRightSidebar; btn.innerHTML = CONFIG.hideRightSidebar ? '📱' : '📐'; btn.title = CONFIG.hideRightSidebar ? '显示右侧边栏' : '隐藏右侧边栏'; applyStyles(); saveConfig(); }); document.body.appendChild(btn); } // 创建设置面板 function createSettingsPanel() { if (document.getElementById('jlc-settings-panel')) return; const panel = document.createElement('div'); panel.id = 'jlc-settings-panel'; let html = '