Askfm only images

Only show images on askfm

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Askfm only images
// @version      1
// @description  Only show images on askfm
// @author       Benjababe
// @match        https://ask.fm/*
// @grant        none
// @namespace https://greasyfork.org/users/476679
// ==/UserScript==

(function() {
    'use strict';
    window.onload = () => {
        console.log("Askfm images running...");

        //gets latest loaded page on change
        let cb = (mutationList) => {
            let newTarget = document.querySelector(".item-pager"),
                newPages = newTarget.getElementsByClassName("item-page"),
                lastItemPage = newPages.item(newPages.length - 1);
            onlyShowImages(lastItemPage);
        }

        //looks for any changes in answers page
        let observer = new MutationObserver(cb);
        let target = document.querySelector(".item-pager");
        observer.observe(target, { attributes: true });

        let itemPages = Array.from(target.getElementsByClassName("item-page"));
        itemPages.forEach((itemPage) => onlyShowImages(itemPage));
    }
})();

let onlyShowImages = (itemPage) => {
    let answers = Array.from(itemPage.getElementsByClassName("item"));
    answers.forEach((answer) => {
        //image element in the answer
        let img = answer.querySelector(".streamItem_visual");
        //hide if doesn't exist
        if (img == null) {
            answer.style.display = "none";
        }
    });
}