Greasy Fork

Greasy Fork is available in English.

联合早报新闻强制一行一条

每条新闻独占一行

// ==UserScript==
// @name         联合早报新闻强制一行一条
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  每条新闻独占一行
// @match        https://www.zaobao.com/*
// @match        https://www.zaobao.com.sg/*
// @grant        none
// @license MIT
// ==/UserScript==


(function() {
    'use strict';

    function makeOneLine() {
        // 让所有新闻条目纵向排列,外观内容保持原样
        document.querySelectorAll('.list-block').forEach(item => {
            // 移除 Bootstrap 列相关 class
            item.classList.remove('col-lg-4', 'col-12', 'row', 'no-gutters');
            // 还原定位,防止错位
            item.style.position = 'static';
            item.style.left = '';
            item.style.top = '';
            // 独占一行
            item.style.display = 'block';
            item.style.width = '100%';
            item.style.boxSizing = 'border-box';
            item.style.margin = '0';
            item.style.padding = '0';
            // 新增:统一字体和高度样式
            item.style.fontSize = '18px';
            item.style.lineHeight = '27.54px';
        });
        document.querySelectorAll('.row.reset-row-margin').forEach(row => {
            row.style.display = 'block';
        });

        // 去除主新闻列表分隔线(包括伪元素)
        document.querySelectorAll('.list-container, .list-block').forEach(el => {
            el.style.border = 'none';
            el.style.borderBottom = 'none';
            el.style.background = 'none';
            el.style.boxShadow = 'none';
        });
        // 动态注入样式去除伪元素分隔线(加强版)
        if (!document.getElementById('remove-main-list-divider-style')) {
            const style = document.createElement('style');
            style.id = 'remove-main-list-divider-style';
            style.innerHTML = `
                .list-container:after,
                .list-container:before,
                .list-block:after,
                .list-container .row.reset-row-margin:after {
                    border: none !important;
                    background: none !important;
                    background-color: transparent !important;
                    box-shadow: none !important;
                    height: 0 !important;
                    width: 0 !important;
                    margin: 0 !important;
                    padding: 0 !important;
                    content: '' !important;
                    display: none !important;
                    position: static !important;
                    z-index: 0 !important;
                    top: auto !important;
                    bottom: auto !important;
                    left: auto !important;
                    right: auto !important;
                    clear: both !important;
                    float: none !important;
                    visibility: hidden !important;
                    opacity: 0 !important;
                }
            `;
            document.head.appendChild(style);
        }
        // 隐藏延伸阅读区块
        document.querySelectorAll('section.further-reading').forEach(el => {
            el.style.display = 'none';
        });
        // 隐藏相关热词区块
        document.querySelectorAll('.article-relative-word').forEach(el => {
            el.style.display = 'none';
        });


        // 针对 /news/china 页面主新闻列表一行化
        document.querySelectorAll('.list-block').forEach(item => {
            // 隐藏缩略图
            const pic = item.querySelector('.summary-pic');
            if (pic) pic.style.display = 'none';

            // 只显示标题
            item.querySelectorAll('.flex-1 > *').forEach(child => {
                if (!child.classList.contains('f18') && !child.classList.contains('m-eps')) {
                    child.style.display = 'none';
                }
            });

            // 标题一行显示
            const title = item.querySelector('.f18.m-eps');
            if (title) {
                title.style.display = 'inline';
                title.style.whiteSpace = 'nowrap';
                title.style.overflow = 'hidden';
                title.style.textOverflow = 'ellipsis';
                title.style.fontWeight = 'normal';
                title.style.fontSize = 'inherit';
                title.style.color = '';
            }

            // 每条新闻独占一行
            item.style.display = 'block';
            item.style.width = '100%';
            item.style.boxSizing = 'border-box';
            item.style.margin = '0';
            item.style.padding = '2px 0';
            item.style.whiteSpace = 'nowrap';
            item.style.overflow = 'hidden';
            item.style.textOverflow = 'ellipsis';
            // 还原定位
            item.style.position = 'static';
            item.style.left = '';
            item.style.top = '';
        });
    }

    // 页面加载后执行
    window.addEventListener('load', makeOneLine);
    // 监听DOM变化(防止异步加载)
    const observer = new MutationObserver(makeOneLine);
    observer.observe(document.body, { childList: true, subtree: true });
})();