Нормальные короткие посты

Удаляет фон у коротких постов.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Нормальные короткие посты
// @namespace    PikabuNormal
// @version      0.1.3
// @description  Удаляет фон у коротких постов.
// @author       Gleb Liutsko
// @match        https://pikabu.ru/*
// @grant        none
// @license      MIT
// @icon         https://cs.pikabu.ru/assets/favicon.ico
// ==/UserScript==

(function() {
    'use strict';

    const classFeedPost = 'stories-feed__container'

    const classNormalStory = 'story story_tags-at-top'

    const classShortPost = 'story story_short'
    const classBackgroundShortPost = 'icon icon--ui__bg-story-short'

    function normalizePost(post) {
        console.log('Normalize post: ' + post.getElementsByClassName('story__title-link')[0].text)

        post.className = classNormalStory
        post.getElementsByClassName(classBackgroundShortPost)[0].remove()
    }

    function normalizeAllPostInFeed() {
        console.log('Normalize feed')

        let feed = document.getElementsByClassName(classFeedPost)[0]
        let shortPosts = Array.from(feed.getElementsByClassName(classShortPost))

        shortPosts.forEach(normalizePost)
    }


    if (location.href.match(/story/)) {
        let post = document.getElementsByTagName('article')[0]
        normalizePost(post)
    }
    else {
        document.getElementsByClassName(classFeedPost)[0].addEventListener('DOMNodeInserted', normalizeAllPostInFeed)
        normalizeAllPostInFeed()
    }
})();