|
|
|
如题,只显示帖子的主楼
应标注群友的要求做的 按理说discuz论坛都能适用吧?
- // ==UserScript==
- // @name 论坛只显示主楼
- // @version 0.1
- // @description 在Discuz论坛中只显示主楼内容,隐藏回复楼层
- // @author MKM
- // @match https://www.gamemale.com/thread*
- // @grant GM_addStyle
- // ==/UserScript==
- (function() {
- 'use strict';
- GM_addStyle(`
- .floor-hidden {
- display: none !important;
- }
- .floor-visible {
- display: block !important;
- }
- `);
- function hideReplies() {
- let mainFloorFound = false;
- const floorSelectors = [
- '.floor',
- '.plhin',
- '.psth',
- '.authi',
- '.t_f',
- 'td.plc'
- ];
- for (const selector of floorSelectors) {
- const floors = document.querySelectorAll(selector);
- if (floors.length > 0) {
- floors.forEach((floor, index) => {
- if (index === 0) {
- floor.classList.remove('floor-hidden');
- floor.classList.add('floor-visible');
- mainFloorFound = true;
- } else {
- floor.classList.add('floor-hidden');
- }
- });
- if (mainFloorFound) break;
- }
- }
- if (!mainFloorFound) {
- const floorElements = document.querySelectorAll('*');
- floorElements.forEach(element => {
- if (element.textContent && element.textContent.includes('楼主') ||
- element.textContent && element.textContent.includes('沙发') ||
- element.textContent && element.textContent.includes('#1')) {
- const parent = element.closest('tr, div, li');
- if (parent) {
- if (element.textContent.includes('楼主') || element.textContent.includes('#1')) {
- parent.classList.remove('floor-hidden');
- parent.classList.add('floor-visible');
- mainFloorFound = true;
- } else {
- parent.classList.add('floor-hidden');
- }
- }
- }
- });
- }
- return mainFloorFound;
- }
- function init() {
- if (document.readyState === 'loading') {
- document.addEventListener('DOMContentLoaded', function() {
- setTimeout(hideReplies, 1000);
- });
- } else {
- setTimeout(hideReplies, 1000);
- }
- }
- init();
- const observer = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- if (mutation.addedNodes && mutation.addedNodes.length > 0) {
- const newFloors = document.querySelectorAll('.floor, .plhin, .psth');
- if (newFloors.length > 0) {
- setTimeout(hideReplies, 500);
- }
- }
- });
- });
- observer.observe(document.body, {
- childList: true,
- subtree: true
- });
- })();
复制代码
|
评分
-
查看全部评分
|