F-List Profile Stripper

Adds a button to strip most formatting information from an F-List profile description.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         F-List Profile Stripper
// @namespace    tag:[email protected],2018-02-25:F-ListProfileStripper
// @version      1.0
// @description  Adds a button to strip most formatting information from an F-List profile description.
// @author       Cummy
// @match        https://www.f-list.net/c/*
// @grant        none
// ==/UserScript==
(function () {
    'use strict';

    var profileDescription = document.getElementsByClassName("FormattedBlock")[0];
    var savedInnerHTML = profileDescription.innerHTML;

    var button = document.createElement('button');
    button.innerHTML = 'Strip formatting';
    button.onclick = function() {
        var images = document.getElementsByClassName("FormattedBlock")[0].getElementsByTagName("img");
        while (images.length > 0) { images[0].parentNode.removeChild(images[0]); }

        var childElements = document.getElementsByClassName("FormattedBlock")[0].getElementsByTagName("*");
        for (var i = 0; i < childElements.length; i++) { childElements[i].className = ''; childElements[i].style = ''; }

        button.replaceWith(restoreButton);
    };

    var restoreButton = document.createElement('button');
    restoreButton.innerHTML = 'Restore formatting';
    restoreButton.onclick = function() {
        profileDescription.innerHTML = savedInnerHTML;
        restoreButton.replaceWith(button);
    };

    profileDescription.parentNode.insertBefore(button, profileDescription);
})();