GC - Neoboard Post Format Remover

Add buttons to neoboard posts to wipe out all formatting in a post.

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GC - Neoboard Post Format Remover
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Add buttons to neoboard posts to wipe out all formatting in a post.
// @author       Twiggies
// @match        *://www.grundos.cafe/neoboards/topic/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
// @grant        none
// @license      MIT
// ==/UserScript==



(function() {
    'use strict';

    //Get all the post timestamps to shove the buttons into.
    const postTimestampList = document.querySelectorAll('.post_timestamp')

    //Add button to each timestamp.
    for (let i = 0; i < postTimestampList.length; i++) {
        //Get the ID of the post.
        // console.log(Array.from(postTimestampList[i].classList).filter(function (str) { return str.includes('post_id'); })[0]);
        const postID = Array.from(postTimestampList[i].classList).filter(function (str) { return str.includes('post_id'); })[0];
        if (postID != undefined) {
            const formatButton = document.createElement('a');
            const buttonImage = document.createElement('img');
            buttonImage.src = "https://i.imgur.com/UT6QFio.png";
            buttonImage.title = "Remove Formatting";
            formatButton.appendChild(buttonImage);
            // formatButton.appendChild(document.createTextNode('[Remove Formatting]'));
            formatButton.addEventListener("click", function() {
                //Get the post_content with the same ID.
                const postContent = document.getElementsByClassName('post_content ' + postID)[0];
                if (postContent != undefined) {
                    //Remove the formatting of the textin that post.
                    for(var i = 0, elems = postContent.getElementsByTagName('*'), len = elems.length; i < len; i++) {
                        elems[i].removeAttribute('style');
                    }
                    console.log(postContent);
                }
            })
            postTimestampList[i].lastElementChild.insertAdjacentElement('afterbegin', formatButton);
        }
    }
    // const postList = document.querySelectorAll('.post_content')
})();