random color menu comand

cambio colore dal pulsante e dal menu

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

  1. // ==UserScript==
  2. // @name random color menu comand
  3. // @namespace https://greasyfork.org/users/237458
  4. // @version 0.3
  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. }
  36.  
  37. Button.addEventListener("click",function(){
  38. document. body.style.background=`background:${changeColor("color")};color:${changeColor("color")};transition:.6s;`;
  39. localStorage.setItem("bg",document.body.style.background)
  40. })
  41.  
  42. //GM_registerMenuCommand("genera color",changeColor);
  43. ///////////////////////////////////
  44. GM_registerMenuCommand("genera color",function(){
  45. document. body.style.background=`background:${changeColor("color")};color:${changeColor("color")};transition:.6s;`;
  46. localStorage.setItem("bg",document.body.style.background)
  47. })
  48. })();
  49. /*
  50. function myFunctionnasc() {
  51. if (prova.style.display === 'none') {prova.style.display = 'block';} else { prova.style.display = 'none';}}
  52. GM_registerMenuCommand("mostra pulsante/nascondi",myFunctionnasc);
  53. */
  54. function myFunctionnasc() {
  55. if(prova.style.display = (prova.style.display!='none') ? 'none' : 'block');}
  56.  
  57. GM_registerMenuCommand("mostra pulsante/nascondi",myFunctionnasc);