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.2
  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>');
  42. $(this).after($code_link);
  43. }
  44. })
  45.  
  46. //////////////////////////////////////////////////////////
  47. GM_addStyle('.source{'+
  48. 'display: inline-block;'+
  49. 'background-color:lime;'+
  50. 'padding: 0.5em 1em;'+
  51. 'color: white;'+
  52. 'text-decoration: none;'+
  53. 'cursor:pointer}'+
  54. '.code-link'+
  55. '{'+
  56. ' margin-left:10px; '+
  57. ' padding-left:2px;'+
  58. ' padding-right:2px; '+
  59. ' font-size:12px; '+
  60. ' background:red; '+
  61. ' color:white!important; '+
  62. ' text-decoration: none;'+
  63. '}');
  64. //////////////////
  65. if(window.location.href.indexOf("/code")!= -1) //code
  66. {var source_btn = $("<a></a>")
  67. source_btn.addClass("source");
  68. source_btn.text("copiare il codice sorgente");
  69. source_btn.click(function(){
  70. execCopy();
  71. });
  72. $("#install-area").after(source_btn);
  73. }
  74.  
  75. })();