random color menu comand

cambio colore dal pulsante e dal menu

  1. // ==UserScript==
  2. // @name random color menu comand
  3. // @namespace https://greasyfork.org/users/237458
  4. // @version 0.8
  5. // @description cambio colore dal pulsante e dal menu
  6. // @author figuccio
  7. // @match *://*/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=stackoverflow.com
  9. // @grant GM_addStyle
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @grant GM_registerMenuCommand
  13. // @require http://code.jquery.com/jquery-latest.js
  14. // @require https://code.jquery.com/ui/1.13.2/jquery-ui.js
  15. // @noframes
  16. // @license MIT
  17. // ==/UserScript==
  18. (function() {
  19. 'use strict';
  20. let $ = window.jQuery.noConflict();
  21. const body=document.body;
  22. let btn_style="position:fixed;top:370px;left:0px;z-index:999999999999;text-align:center;width:130px;border:1px solid green;background-color:green;color:red;padding:3px;border-radius:5px;border-color:black;";
  23. let box=document.createElement("div");
  24. box.innerText="cambia colore random";
  25. box.title="random color";
  26. box.id="prova";
  27. box.style=btn_style;
  28. let box_state="btn";
  29. // Verifica se sono memorizzate le coordinate x e y del box
  30. if (GM_getValue('boxPosX') && GM_getValue('boxPosY')) {
  31. box.style.left = GM_getValue('boxPosX') + 'px';
  32. box.style.top = GM_getValue('boxPosY') + 'px';
  33. }
  34. $(box).draggable({
  35. containment: "window",
  36. stop: function(event, ui) {
  37. // Memorizza le coordinate x e y del box al termine del trascinamento
  38. GM_setValue('boxPosX', ui.position.left);
  39. GM_setValue('boxPosY', ui.position.top);
  40. }
  41. }); // Aggiunta della proprietà containment
  42. body.append(box);
  43.  
  44. /////////////////////////////////
  45. if(GM_getValue("bg")!==null){
  46. document.body.style.background=GM_getValue("bg");
  47. }
  48. ///////////////////////////////
  49. function changeColor(){
  50. var color = '#'+Math.floor(Math.random()*16777215).toString(16);
  51. document.body.style.background = color;
  52. box.innerHTML = "&nbsp;cambio colore <br/>&nbsp;"+ color;
  53. //colore button dello stesso colore della pagina
  54. box.style.backgroundColor = color;
  55. //colore testo button
  56. box.style.color = 'white';
  57. }
  58.  
  59. body.addEventListener("click",function(){
  60. document.body.style.background=`background:${changeColor("color")};color:${changeColor("color")};transition:.6s;`;
  61. GM_setValue("bg",document.body.style.background)
  62. })
  63.  
  64. ///////////////////////////////////
  65. GM_registerMenuCommand("genera color",function(){
  66. document.body.style.background=`background:${changeColor("color")};color:${changeColor("color")};transition:.6s;`;
  67. GM_setValue("bg",document.body.style.background)
  68. })
  69. ///////////////////////////////////////////////////////////////////////
  70. function myFunctionnasc() {
  71. if(box.style.display = (box.style.display!=='none') ? 'none' : 'block');}
  72. GM_registerMenuCommand("mostra pulsante/nascondi",myFunctionnasc);
  73. })();