Copia codice Greasyfork figuccio

aggiunge pulsante copia codice

  1. // ==UserScript==
  2. // @name Copia codice Greasyfork figuccio
  3. // @namespace https://greasyfork.org/users/237458
  4. // @version 0.3
  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() {
  16. 'use strict';
  17.  
  18. function execCopy() {
  19. var code='';
  20. if($(".prettyprint li").length>0)
  21. {
  22. $(".prettyprint li").each(function(){
  23. code += $(this).text()+'\n';
  24. });
  25. }
  26. else {code = $(".prettyprint").text();}
  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. //Il collegamento al codice sorgente viene visualizzato dopo il collegamento allo script
  38. $(".script-list h2 a").each(function(){
  39. if(!$(this).next().hasClass("code-link"))
  40. {let short_link = $(this).attr("href");
  41. //let $code_link = $('<a href=\"'+short_link+'/code\" class=\"code-link\">codice</a>');//non apre in nuova scheda
  42. let $code_link = $('<a target="_blank" a href=\"'+short_link+'/code\" class=\"code-link\">codice</a>');//apre in nuova scheda
  43. $(this).after($code_link);
  44. }
  45. })
  46.  
  47. //////////////////////////////////////////////////////////
  48. GM_addStyle('.source{'+
  49. 'display: inline-block;'+
  50. 'background-color:lime;'+
  51. 'padding: 0.5em 1em;'+
  52. 'color: white;'+
  53. 'text-decoration: none;'+
  54. 'cursor:pointer}'+
  55. '.code-link'+
  56. '{'+
  57. ' margin-left:10px; '+
  58. ' padding-left:2px;'+
  59. ' padding-right:2px; '+
  60. ' font-size:12px; '+
  61. ' background:red; '+
  62. ' color:white!important; '+
  63. ' text-decoration: none;'+
  64. '}');
  65. //////////////////
  66. if(window.location.href.indexOf("/code")!= -1) //code
  67. {var source_btn = $("<a></a>")
  68. source_btn.addClass("source");
  69. source_btn.text("copiare il codice sorgente");
  70. source_btn.click(function(){
  71. execCopy();
  72. });
  73. $("#install-area").after(source_btn);
  74. }
  75.  
  76. })();