Fxp Useful Scripts

Spam those douchebags

当前为 2020-10-30 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Fxp Useful Scripts
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Spam those douchebags
// @author       MrTarnegol
// @match        https://www.fxp.co.il/*
// @grant        none
// ==/UserScript==

'use strict';

const MIN_SIZE = window.MIN_SIZE = 3;
const MAX_SIZE = window.MAX_SIZE = 5;

function componentToHex(c) {
    const hex = c.toString(16);
    return `0${hex}`.slice(-2);
}

function rgbToHex(r, g, b) {
    const rHex = componentToHex(r);
    const gHex = componentToHex(g);
    const bHex = componentToHex(b);
    return `${rHex}${gHex}${bHex}`;
}

const getText = window.getText = () => {
    const selector = '.cke_editor iframe'
    const element = $(selector)[0];
    if (element !== undefined) {
        const doc = element.contentWindow.document;
        return doc.getElementsByClassName("forum")[0].innerText;
    }
    return '';
}

const setText = window.setText = (text) => {
    const selector = '.cke_editor iframe'
    const element = $(selector)[0];
    if (element !== undefined) {
        var doc = element.contentWindow.document;
        doc.getElementsByClassName("forum")[0].innerText = text;
        return true;
    }
    return false;
}

const randomSize = window.randomSize  = () => {
    const SIZES = MAX_SIZE - MIN_SIZE + 1;
    return Math.floor(Math.random() * SIZES) + MIN_SIZE;
}

const letterWithSize = window.letterWithSize = (letter, size = randomSize()) => {
    return letter != ' ' ? `[SIZE=${size}]${letter}[/SIZE]` : ' ';
}

const scribbleText = window.scribbleText = (text) => {
    let isText = true;
    return text.split('').reduce((a, b) => {
        if (b == ']') { isText = true; return a + b; };
        if (b == '[') { isText = false; return a + b; };
        return isText ? a + letterWithSize(b) : a + b;
    }, '');
}

const scribble = window.scribble = () => {
    console.log('MrTarnegol scribbling begin!');

    const text = getText();
    const scribbled = scribbleText(text);
    setText(scribbled);

    CKEDITOR.tools.callFunction(5, this);
}

const addColourTag = window.addColourTag = (text, colour) => {
    return text != ' ' ? `[COLOR=#${colour}]${text}[/COLOR]` : ' ';
}

const addColourTagRGB = window.addColourTagRGB = (text, colour) => {
    return addColourTag(text, rgbToHex(colour.r, colour.g, colour.b));
}

const colours = [
    {r: 255, g: 0, b: 0},
    {r: 255, g: 127, b: 0},
    {r: 255, g: 255, b: 0},
    {r: 127, g: 255, b: 0},
    {r: 0, g: 255, b: 0},
    {r: 0, g: 255, b: 127},
    {r: 0, g: 255, b: 255},
    {r: 0, g: 127, b: 255},
    {r: 0, g: 0, b: 255},
    {r: 127, g: 0, b: 255},
    {r: 255, g: 0, b: 255},
    {r: 255, g: 0, b: 127},
];
const rainbowText = window.rainbowText = (text) => {
    let isText = true;
    return text.split('').reduce((a, b, i) => {
        if (b == ']') { isText = true; return a + b; };
        if (b == '[') { isText = false; return a + b; };
        const colour = colours[i % colours.length];
        return isText ? a + addColourTagRGB(b, colour) : a + b;
    }, '');
}

const rainbow = window.rainbow = () => {
    console.log('MrTarnegol rainbow begin!');

    const text = getText();
    const rainbowed = rainbowText(text);
    setText(rainbowed);

    CKEDITOR.tools.callFunction(5, this);
}

const createButtonsDiv = () => {
    const div = document.createElement('div');
    div.style.position = 'fixed';
    div.style.bottom = '0';
    div.style.left = 0;
    div.style.display = 'flex';
    div.style.flexDirection = 'column';
    return div;
}

const button = (innerText, onclick) => {
    const button = document.createElement('button');
    button.style.backgroundColor = '#73AD21';
    button.style.padding = '15px 40px';
    button.style.fontSize = '18px';
    button.innerText = innerText;
    button.onclick = onclick;
    return button;
}

const scribbleButton = () => button('ערבל טקסט', scribble);

const rainbowButton = () => button('קשת בענן', rainbow);

const start = () => {
    if (window.top == window.self) {
        const div = createButtonsDiv();
        document.body.appendChild(div);
        const scribble = scribbleButton();
        div.appendChild(scribble);
        const rainbow = rainbowButton();
        div.appendChild(rainbow);
    }
}

start();