// ==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();