有需要的朋友可以拿去试试:
// ==UserScript==
// @name 煎蛋网帖子强制屏蔽及管理面板 (精简版)
// @namespace http://tampermonkey.net/
// @version 4.1
// @description 精简高效的煎蛋网帖子屏蔽与管理脚本
// @match https://*.jandan.net/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const KEY = 'jandan_blocked_posts_v2';
const getData = () => JSON.parse(localStorage.getItem(KEY) || '[]');
const setData = (d) => localStorage.setItem(KEY, JSON.stringify(d));
// 核心通用:隐藏与过滤
const applyBlock = () => {
const ids = getData().map(i => i.id);
document.querySelectorAll('a.comment-num, a[href*="/t/"]').forEach(a => {
const m = (a.getAttribute('href') || '').match(/\/t\/(\d+)/);
if (m && ids.includes(m[1])) {
const row = a.closest('.comment-row, li, .row');
if (row) row.style.display = 'none';
}
});
};
// 更新下拉菜单 UI
window.updateManagerUI = () => {
const sel = document.getElementById('blocked-select');
if (!sel) return;
const data = getData().sort((a, b) => b.time - a.time);
sel.innerHTML = data.length ? '' : '(暂无屏蔽帖子)';
sel.disabled = !data.length;
data.forEach(i => {
const opt = document.createElement('option');
opt.value = i.id;
opt.textContent = `ID: #${i.id}`;
sel.appendChild(opt);
});
};
// 页面交互逻辑监听
document.addEventListener('click', (e) => {
// 1. 点击“强制屏蔽”按钮
if (e.target.classList.contains('custom-block-btn')) {
e.preventDefault();
const row = e.target.closest('.comment-row, li, .row');
const link = row?.querySelector('a.comment-num, a[href*="/t/"]');
const id = (link?.getAttribute('href') || '').match(/\/t\/(\d+)/)?.[1];
if (id) {
const list = getData();
if (!list.some(i => i.id === id)) {
list.push({ id, time: Date.now() });
setData(list);
}
if (row) row.style.display = 'none';
updateManagerUI();
} else {
alert('未能识别该帖子的ID');
}
return;
}
// 2. 顶部管理面板按钮操作
if (e.target.id === 'visit-btn' || e.target.id === 'unblock-btn') {
const val = document.getElementById('blocked-select')?.value;
if (!val) return alert('当前没有选中任何被屏蔽的帖子');
if (e.target.id === 'visit-btn') {
window.open(`https://jandan.net/t/${val}`, '_blank');
} else {
setData(getData().filter(i => i.id !== val));
updateManagerUI();
alert(`已解除对 #${val} 的屏蔽,刷新页面后恢复显示`);
}
}
});
// 动态注入菜单项与顶栏面板
const observer = new MutationObserver(() => {
applyBlock();
// 注入帖子的“强制屏蔽”按钮
document.querySelectorAll('a, li, div').forEach(el => {
if ((el.textContent.trim() === '举报' || el.textContent.trim() === '收藏')) {
const menu = el.closest('ul, div.dropdown-menu') || el.parentElement;
if (menu && !menu.querySelector('.custom-block-btn')) {
const btn = document.createElement('a');
btn.textContent = '强制屏蔽';
btn.className = 'custom-block-btn';
btn.style.cssText = 'color:#ff4d4f;cursor:pointer;display:block;padding:6px 12px;border-top:1px solid #eee;';
menu.appendChild(btn);
}
}
});
// 注入顶部管理面板
const nav = document.querySelector('div.top-nav');
if (nav && !nav.querySelector('#custom-block-manager')) {
const wrap = document.createElement('div');
wrap.id = 'custom-block-manager';
wrap.style.cssText = 'margin-left:auto;display:flex;align-items:center;gap:8px;font-size:13px;padding-right:10px;';
wrap.innerHTML = `
前往帖子
解除屏蔽
`;
nav.appendChild(wrap);
updateManagerUI();
}
});
observer.observe(document.body, { childList: true, subtree: true });
})();
写了一个屏蔽无聊图一些不能被屏蔽的帖子的篡改猴脚本
#3564 / 举报 / OO [2] / XX [0]
排序:
- 1/1
- 1/1
字数统计: 0