Fxp Useful Scripts

Spam those douchebags

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

  1. // ==UserScript==
  2. // @name Fxp Useful Scripts
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3.3
  5. // @description Spam those douchebags
  6. // @author MrTarnegol
  7. // @match https://www.fxp.co.il/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. const styles = `
  13. .tarnegol-buttons-container {
  14. box-shadow: 0 0 13px 5px rgba(0, 0, 0, 0.5);
  15. position: fixed;
  16. bottom: 0;
  17. left: 0;
  18. display: flex;
  19. flex-direction: column;
  20. }
  21. .tarnegol-buttons-btn {
  22. background-color: #4e4e4e;
  23. font-family: system-ui;
  24. color: white;
  25. padding: 15px 40px;
  26. font-size: 18px;
  27. width: 100%;
  28. }
  29. .tarnegol-buttons-btn-parent {
  30. background-color: #4e4e4e;
  31. width: 100%;
  32. }
  33. `
  34.  
  35. const styleSheet = document.createElement("style")
  36. styleSheet.type = "text/css"
  37. styleSheet.innerText = styles
  38. document.head.appendChild(styleSheet)
  39. })();
  40.  
  41. 'use strict';
  42.  
  43. const MIN_SIZE = window.MIN_SIZE = 3;
  44. const MAX_SIZE = window.MAX_SIZE = 5;
  45.  
  46. function componentToHex(c) {
  47. const hex = c.toString(16);
  48. return `0${hex}`.slice(-2);
  49. }
  50.  
  51. function rgbToHex(value) {
  52. const rHex = componentToHex(value.r);
  53. const gHex = componentToHex(value.g);
  54. const bHex = componentToHex(value.b);
  55. return `${rHex}${gHex}${bHex}`;
  56. }
  57.  
  58. function hexToRgb(hex) {
  59. const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  60. const r = parseInt(result[1], 16);
  61. const g = parseInt(result[2], 16);
  62. const b = parseInt(result[3], 16);
  63. return { r, g, b };
  64. }
  65.  
  66. function mulRGB(v, s) {
  67. const r = Math.floor(v.r * s);
  68. const g = Math.floor(v.g * s);
  69. const b = Math.floor(v.b * s);
  70. return { r, g, b };
  71. }
  72.  
  73. function addRGB(a, b) {
  74. return { r: a.r + b.r, g: a.g + b.g, b: a.b + b.b };
  75. }
  76.  
  77. function mixRGB(a, b, v) {
  78. const aMul = mulRGB(a, v);
  79. const bMul = mulRGB(b, 1 - v);
  80. return addRGB(aMul, bMul);
  81. }
  82.  
  83. function gradient(a, b, times = 5) {
  84. const colours = [];
  85. const delta = 1 / (times - 1);
  86. for (let i = 0; i < times; i++) {
  87. colours.push(mixRGB(a, b, delta * i));
  88. }
  89. return colours;
  90. }
  91.  
  92. const getText = window.getText = () => {
  93. const selector = '.cke_editor iframe'
  94. const element = $(selector)[0];
  95. if (element !== undefined) {
  96. const doc = element.contentWindow.document;
  97. return doc.getElementsByClassName("forum")[0].innerText;
  98. }
  99. return '';
  100. }
  101.  
  102. const setText = window.setText = (text) => {
  103. const selector = '.cke_editor iframe'
  104. const element = $(selector)[0];
  105. if (element !== undefined) {
  106. var doc = element.contentWindow.document;
  107. doc.getElementsByClassName("forum")[0].innerText = text;
  108. return true;
  109. }
  110. return false;
  111. }
  112.  
  113. const randomSize = window.randomSize = () => {
  114. const SIZES = MAX_SIZE - MIN_SIZE + 1;
  115. return Math.floor(Math.random() * SIZES) + MIN_SIZE;
  116. }
  117.  
  118. const isBlank = (letter) => {
  119. return letter == ' ' || letter == ' ';
  120. }
  121.  
  122. const letterWithSize = window.letterWithSize = (letter, size = randomSize()) => {
  123. return !isBlank(letter) ? `[SIZE=${size}]${letter}[/SIZE]` : ' ';
  124. }
  125.  
  126. const scribbleText = window.scribbleText = (text) => {
  127. let isText = true;
  128. return text.split('').reduce((a, b) => {
  129. if (b == ']') { isText = true; return a + b; };
  130. if (b == '[') { isText = false; return a + b; };
  131. return isText ? a + letterWithSize(b) : a + b;
  132. }, '');
  133. }
  134.  
  135. const doScribble = window.scribble = () => {
  136. console.log('MrTarnegol scribbling begin!');
  137.  
  138. const text = getText();
  139. const scribbled = scribbleText(text);
  140. setText(scribbled);
  141.  
  142. CKEDITOR.tools.callFunction(5, this);
  143. }
  144.  
  145. const addColourTag = window.addColourTag = (text, colour) => {
  146. return !isBlank(text) ? `[COLOR=#${colour}]${text}[/COLOR]` : ' ';
  147. }
  148.  
  149. const addColourTagRGB = window.addColourTagRGB = (text, colour) => {
  150. return addColourTag(text, rgbToHex(colour));
  151. }
  152.  
  153. const gradientColours = {
  154. start: hexToRgb(localStorage.getItem('tarnegol.gradient.start')),
  155. end: hexToRgb(localStorage.getItem('tarnegol.gradient.end')),
  156. }
  157. const gradientText = window.gradientText = (text) => {
  158. const colours = gradient(gradientColours.start, gradientColours.end, getText().length);
  159. let isText = true;
  160. return text.split('').reduce((a, b, i) => {
  161. if (b == ']') { isText = true; return a + b; };
  162. if (b == '[') { isText = false; return a + b; };
  163. const colour = colours[i % colours.length];
  164. return isText ? a + addColourTagRGB(b, colour) : a + b;
  165. }, '');
  166. }
  167.  
  168. const doGradient = window.gradient = () => {
  169. console.log('MrTarnegol gradient begin!');
  170.  
  171. const text = getText();
  172. const gradiented = gradientText(text);
  173. setText(gradiented);
  174.  
  175. CKEDITOR.tools.callFunction(5, this);
  176. }
  177.  
  178. const createButtonsDiv = () => {
  179. const div = document.createElement('div');
  180. div.className = 'tarnegol-buttons-container';
  181. return div;
  182. }
  183.  
  184. const button = (innerText, onclick) => {
  185. const button = document.createElement('button');
  186. button.className = 'tarnegol-buttons-btn';
  187. button.innerText = innerText;
  188. button.onclick = onclick;
  189. return button;
  190. }
  191.  
  192. const colourInput = (value) => {
  193. const input = document.createElement('input');
  194. input.type = 'color';
  195. input.value = value;
  196. return input;
  197. }
  198.  
  199. const scribbleButton = () => {
  200. const div = document.createElement('div');
  201. div.className = 'tarnegol-buttons-btn-parent';
  202. div.appendChild(button('ערבל טקסט', doScribble));
  203. return div;
  204. }
  205.  
  206. const gradientButton = () => {
  207. const div = document.createElement('div');
  208. div.className = 'tarnegol-buttons-btn-parent';
  209. div.appendChild(button('קשת בענן', doGradient));
  210. const start = colourInput(localStorage.getItem('tarnegol.gradient.start'));
  211. const end = colourInput(localStorage.getItem('tarnegol.gradient.end'));
  212. div.appendChild(start);
  213. div.appendChild(end);
  214. start.addEventListener('input', e => {
  215. gradientColours.start = hexToRgb(start.value);
  216. localStorage.setItem('tarnegol.gradient.start', start.value);
  217. })
  218. end.addEventListener('input', e => {
  219. gradientColours.end = hexToRgb(end.value);
  220. localStorage.setItem('tarnegol.gradient.end', end.value);
  221. })
  222. return div;
  223. }
  224.  
  225. const start = () => {
  226. if (window.top == window.self) {
  227. const div = createButtonsDiv();
  228. document.body.appendChild(div);
  229. const scribble = scribbleButton();
  230. div.appendChild(scribble);
  231. const gradient = gradientButton();
  232. div.appendChild(gradient);
  233. }
  234. }
  235.  
  236. start();
  237.