Greasy Fork is available in English.

colori random con pulsante

pulsante per cambio colori

  1. // ==UserScript==
  2. // @name colori random con pulsante
  3. // @author figuccio
  4. // @namespace https://greasyfork.org/users/237458
  5. // @description pulsante per cambio colori
  6. // @version 1.4
  7. // @match *://*/*
  8. // @grant GM_registerMenuCommand
  9. // @noframes
  10. // @require http://code.jquery.com/jquery-latest.js
  11. // @require https://code.jquery.com/ui/1.12.1/jquery-ui.js
  12. // @grant GM_addStyle
  13. // @grant GM_setValue
  14. // @grant GM_getValue
  15. // @license MIT
  16. // ==/UserScript==
  17. (function() {
  18. 'use strict';
  19. let $ = window.jQuery;
  20. var j3 = $.noConflict();
  21. const body=document.body
  22. var Button = document.createElement('button');
  23. let btn_style = "position:absolute;text-align:center;border:3px solid green;font-size:19px;top:300px;right:;z-index:9999999999999999999999;background-color:aquamarine;color:red;padding:15px;border-radius:5px;";
  24. let box=document.createElement("div");
  25. /////////////////////////////////////
  26. box.title = 'cambiare colore';
  27. box.innerHTML=`
  28. </div>
  29. <button id="random" style="font-size:15px;color:black;background:red;border:2px solid green;">CAMBIA COLORI AL CLICK</button><br>
  30. </div>
  31. `;
  32. ////////////////////////////////////
  33.  
  34. box.style=btn_style;
  35. j3(box).draggable();
  36. body.append(box);
  37. //////////////////////////
  38. if(GM_getValue("bg")!==null){
  39. body.style.background=GM_getValue("bg");
  40. }
  41.  
  42. function randomColor() {
  43. var randomColor = '#' + Math.floor(Math.random()*16777215).toString(16);
  44. body.style.background = randomColor;
  45. box.innerHTML = "&nbsp;cambio colore <br/>&nbsp;"+ randomColor;
  46. //colore button dello stesso colore della pagina
  47. box.style.backgroundColor = randomColor;
  48. //colore testo button
  49. box.style.color = 'white';
  50.  
  51. }
  52. //cambio colore al click
  53. box.addEventListener("click",function(){
  54. body.style.background=`background:${randomColor("color")};color:${randomColor("color")};transition:.6s;`;
  55. GM_setValue("bg",body.style.background)
  56. })
  57.  
  58. //////////////////////////
  59.  
  60. })();