// ==UserScript== // @name 百度贴吧皮肤屏蔽器 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 移除百度贴吧楼里的皮肤 // @author necrodancer // @match https://tieba.baidu.com/* // @grant none // ==/UserScript== (function() { 'use strict'; // 从皮肤中提取内容并重建结构 function extractContentFromSkin(postElement) { // 验证是否为帖子内容元素 if (!postElement || !postElement.id || !postElement.id.startsWith('post_content_')) { return false; } // 找到最内层的内容容器(文字和图片所在的地方) const contentInner = postElement.querySelector('div.post_bubble_middle_inner'); if (!contentInner) { return false; } // 克隆内容,避免直接操作原元素 const contentClone = contentInner.cloneNode(true); // 清除所有样式,避免继承皮肤样式 contentClone.removeAttribute('style'); contentClone.style.cssText = ` margin: 10px 0 !important; padding: 0 !important; background: none !important; border: none !important; `; // 清除帖子容器中所有内容(包括皮肤) while (postElement.firstChild) { postElement.removeChild(postElement.firstChild); } // 创建一个干净的容器来放置内容 const cleanContainer = document.createElement('div'); cleanContainer.className = 'clean-post-content'; cleanContainer.style.cssText = ` margin: 15px 0; line-height: 1.6; `; // 将克隆的内容放入干净的容器 cleanContainer.appendChild(contentClone); // 添加到帖子容器 postElement.appendChild(cleanContainer); // 添加分隔线 const separator = document.createElement('div'); separator.style.cssText = ` height: 1px; background: #f0f0f0; margin: 10px 0; `; postElement.appendChild(separator); return true; } // 处理页面上所有帖子 function processAllPosts() { const posts = document.querySelectorAll('[id^="post_content_"]'); let processedCount = 0; posts.forEach(post => { if (extractContentFromSkin(post)) { processedCount++; } }); console.log(`已从 ${processedCount} 个帖子中提取内容并移除皮肤`); } // 监控动态加载的内容 function setupObserver() { const observer = new MutationObserver((mutations) => { mutations.forEach(mutation => { mutation.addedNodes.forEach(node => { if (node.nodeType === 1) { // 元素节点 // 检查是否是帖子内容 if (node.id && node.id.startsWith('post_content_')) { extractContentFromSkin(node); } else { // 检查节点内是否包含帖子 const postsInNode = node.querySelectorAll('[id^="post_content_"]'); postsInNode.forEach(post => extractContentFromSkin(post)); } } }); }); }); // 监控整个文档的变化 observer.observe(document.body, { childList: true, subtree: true, attributes: false }); } // 初始化 function init() { // 先处理已有的帖子 processAllPosts(); // 监控新加载的内容 setupObserver(); } // 页面加载完成后初始化 if (document.readyState === 'complete') { init(); } else { window.addEventListener('load', init); } })();