Copia codice Greasyfork figuccio

aggiunge pulsante copia codice

目前为 2023-01-14 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Copia codice Greasyfork figuccio
  3. // @namespace https://greasyfork.org/users/237458
  4. // @version 0.1
  5. // @description aggiunge pulsante copia codice
  6. // @author figuccio
  7. // @match https://greasyfork.org/*
  8. // @match https://sleazyfork.org/*
  9. // @require https://lib.baomitu.com/jquery/3.5.0/jquery.min.js
  10. // @run-at document-end
  11. // @grant GM_addStyle
  12. // @grant GM_setClipboard
  13. // @license MIT
  14. // ==/UserScript==
  15. function execCopy() {
  16. var code='';
  17. if($(".prettyprint li").length>0)
  18. {
  19. $(".prettyprint li").each(function(){
  20. code += $(this).text()+'\n';
  21. });
  22. }
  23. else
  24. {
  25. code = $(".prettyprint").text();
  26. }
  27.  
  28. code = encodeURI(code)
  29. code = code.replace(/%C2%A0/g,'%20');
  30. code = decodeURI(code);
  31.  
  32. GM_setClipboard(code, 'text');
  33. alert("copia con successo")
  34. return true;
  35. }
  36.  
  37. (function() {
  38. 'use strict';
  39. //Il collegamento al codice sorgente viene visualizzato dopo il collegamento allo script
  40. $(".script-list h2 a").each(function(){
  41. if(!$(this).next().hasClass("code-link"))
  42. {
  43. let short_link = $(this).attr("href");
  44. let $code_link = $('<a href=\"'+short_link+'/code\" class=\"code-link\">codice</a>');
  45. $(this).after($code_link);
  46. }
  47. })
  48.  
  49. //////////////////////////////////////////////////////////
  50. GM_addStyle('.source{'+
  51. 'transition: box-shadow 0.2s;'+
  52. 'display: inline-block;'+
  53. 'background-color:lime;'+
  54. 'padding: 0.5em 1em;'+
  55. 'color: white;'+
  56. 'text-decoration: none;'+
  57. 'cursor:pointer}'+
  58. '.source:hover{'+
  59. 'transition: box-shadow 0.2s;'+
  60. 'box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);'+
  61. '}'+
  62. '.code-link'+
  63. '{'+
  64. ' margin-left:10px; '+
  65. ' padding-left:2px;'+
  66. ' padding-right:2px; '+
  67. ' font-size:12px; '+
  68. ' background:red; '+
  69. ' color:white!important; '+
  70. ' text-decoration: none;'+
  71. '}'+
  72. '.rating-icon-none {'+
  73. ' border-color: #bbbbbb;'+
  74. ' background-color: #8590a612;'+
  75. ' color: gray;'+
  76. '}');
  77. //////////////////
  78. if(window.location.href.indexOf("/code")!= -1) //code
  79. {
  80. var source_btn = $("<a></a>")
  81. source_btn.addClass("source");
  82. source_btn.text("copiare il codice sorgente");
  83. source_btn.click(function(){
  84. execCopy();
  85. });
  86. $("#install-area").after(source_btn);
  87. }
  88. // else if(window.location.href.indexOf("/scripts/")!= -1) //scripts
  89. // {
  90.  
  91. // }
  92.  
  93. })();