random color menu comand

cambio colore dal pulsante e dal menu

当前为 2022-08-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name random color menu comand
  3. // @namespace https://greasyfork.org/users/237458
  4. // @version 0.4
  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 https://code.jquery.com/jquery-1.11.0.min.js
  14. // @noframes
  15. // @license MIT
  16. // ==/UserScript==
  17. (function() {
  18. 'use strict';
  19. var Button = document.createElement('button');
  20. document.getElementsByTagName('body')[0].appendChild(Button);
  21. Button.setAttribute ('id', 'prova');
  22. Button.setAttribute ('title', 'cambio colore');
  23. Button.style = "position:absolute;top:370px;right:0px;z-index:9999999999999999999999;background-color:green;color:red;padding:3px;border-radius: 5px;border-color:black;";
  24. Button.innerHTML = "cambia colore random";
  25.  
  26. /////////////////////////////////
  27. if(localStorage.getItem("bg")!==null){
  28. document.body.style.background=localStorage.getItem("bg");
  29. }
  30. ///////////////////////////////
  31. function changeColor(){
  32. var color = '#'+Math.floor(Math.random()*16777215).toString(16);
  33. document.body.style.background = color;
  34. Button.innerHTML = "&nbsp;cambio colore <br/>&nbsp;"+ color;
  35. //colore button dello stesso colore della pagina
  36. Button.style.backgroundColor = color;
  37. //colore testo button
  38. Button.style.color = 'white';
  39. }
  40.  
  41. Button.addEventListener("click",function(){
  42. document.body.style.background=`background:${changeColor("color")};color:${changeColor("color")};transition:.6s;`;
  43. localStorage.setItem("bg",document.body.style.background)
  44. })
  45.  
  46. //GM_registerMenuCommand("genera color",changeColor);
  47. ///////////////////////////////////
  48. GM_registerMenuCommand("genera color",function(){
  49. document.body.style.background=`background:${changeColor("color")};color:${changeColor("color")};transition:.6s;`;
  50. localStorage.setItem("bg",document.body.style.background)
  51. })
  52. })();
  53. /*
  54. function myFunctionnasc() {
  55. if (prova.style.display === 'none') {prova.style.display = 'block';} else { prova.style.display = 'none';}}
  56. GM_registerMenuCommand("mostra pulsante/nascondi",myFunctionnasc);
  57. */
  58. function myFunctionnasc() {
  59. if(prova.style.display = (prova.style.display!='none') ? 'none' : 'block');}
  60.  
  61. GM_registerMenuCommand("mostra pulsante/nascondi",myFunctionnasc);