Colorful Paragraphs

Takes a 'p' tag. Fucks it up and spits out a fucking rainbow!! Making text practically un-readable.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Colorful Paragraphs
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Takes a 'p' tag. Fucks it up and spits out a fucking rainbow!! Making text practically un-readable. 
// @author       feedmegrizzly
// @match        https://*/*
// @match        http://*/*
// @grant        none
// ==/UserScript==

window.onload = function(){
    var colors = ["red", "green", "blue", "teal", "fuchsia", "purple", "orange"];
    var paragraphs = document.querySelectorAll('p');

    //-----------------------------------------------------

    function get_words(paragraphs){
        var result = []
        for(var paragraph of paragraphs){
            try{
                result.push(paragraph.innerText.split(""));
            }
            catch(err){console.log(err)}
        }
        return result
    };

    //-----------------------------------------------------

    function add_color_style(paragraphs, colors){
        var color_index = 0
        for(var i = 0; i < paragraphs.length; i++){
            for(var j = 0; j < paragraphs[i].length; j++){
                if(color_index >= colors.length){
                    color_index = 0
                }
                paragraphs[i][j] = "<span style='color:" + colors[color_index] + "'>" + paragraphs[i][j] + "</span>"
                color_index++
            }
            paragraphs[i] = paragraphs[i].join("")
        }
        set_text_to_dom(paragraphs)
    };

    //-----------------------------------------------------

    function set_text_to_dom(paragraphs){
        var old_p = document.querySelectorAll('p');
        for(var i = 0; i < old_p.length; i++){
            old_p[i].innerHTML = paragraphs[i]
        }
        return
    }


    add_color_style(get_words(paragraphs),colors);
}