random color menu comand

cambio colore dal pulsante e dal menu

当前为 2022-07-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name random color menu comand
  3. // @namespace https://greasyfork.org/users/237458
  4. // @version 0.2
  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. // @noframes
  14. // @license MIT
  15. // ==/UserScript==
  16. (function() {
  17. 'use strict';
  18. var Button = document.createElement('button');
  19. document.getElementsByTagName('body')[0].appendChild(Button);
  20. Button.setAttribute ('id', 'prova');
  21. Button.setAttribute ('title', 'cambio colore');
  22. Button.style = "position:absolute;top:370px;right:0px;z-index:9999999999999999999999;background-color:green;color:red;padding:3px;border-radius: 5px;border-color:black;";
  23. Button.innerHTML = "cambia colore random";
  24. Button .addEventListener("click",getRandomColor);
  25.  
  26. function getRandomColor() {
  27. var letters = "0123456789ABCDEF";
  28. var randomColor = "#";
  29. for (var i = 0; i < 6; i++) {
  30. randomColor += letters[Math.floor(Math.random() * letters.length)];
  31. }
  32.  
  33. document.body.style.backgroundColor = randomColor;
  34. }
  35.  
  36. GM_registerMenuCommand("genera color",getRandomColor);
  37. })();
  38. /*
  39. function myFunctionnasc() {
  40. if (prova.style.display === 'none') {prova.style.display = 'block';} else { prova.style.display = 'none';}}
  41. GM_registerMenuCommand("mostra pulsante/nascondi",myFunctionnasc);
  42. */
  43. function myFunctionnasc() {
  44. if(prova.style.display = (prova.style.display!='none') ? 'none' : 'block');}
  45.  
  46. GM_registerMenuCommand("mostra pulsante/nascondi",myFunctionnasc);