Copia codice Greasyfork figuccio

aggiunge pulsante copia codice

目前為 2023-01-14 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name          Copia codice Greasyfork figuccio
// @namespace     https://greasyfork.org/users/237458
// @version       0.1
// @description   aggiunge pulsante copia codice
// @author        figuccio
// @match         https://greasyfork.org/*
// @match         https://sleazyfork.org/*
// @require       https://lib.baomitu.com/jquery/3.5.0/jquery.min.js
// @run-at        document-end
// @grant         GM_addStyle
// @grant         GM_setClipboard
// @license        MIT
// ==/UserScript==
function execCopy() {
    var code='';
    if($(".prettyprint li").length>0)
    {
        $(".prettyprint li").each(function(){
            code += $(this).text()+'\n';
        });
    }
    else
    {
        code = $(".prettyprint").text();
    }

    code = encodeURI(code)
    code = code.replace(/%C2%A0/g,'%20');
    code = decodeURI(code);

    GM_setClipboard(code, 'text');
    alert("copia con successo")
    return true;
}

(function() {
    'use strict';
    //Il collegamento al codice sorgente viene visualizzato dopo il collegamento allo script
    $(".script-list h2 a").each(function(){
        if(!$(this).next().hasClass("code-link"))
        {
            let short_link = $(this).attr("href");
            let $code_link = $('<a href=\"'+short_link+'/code\" class=\"code-link\">codice</a>');
            $(this).after($code_link);
        }
    })

    //////////////////////////////////////////////////////////
    GM_addStyle('.source{'+
                'transition: box-shadow 0.2s;'+
                'display: inline-block;'+
                'background-color:lime;'+
                'padding: 0.5em 1em;'+
                'color: white;'+
                'text-decoration: none;'+
                'cursor:pointer}'+
                '.source:hover{'+
                'transition: box-shadow 0.2s;'+
                'box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);'+
                '}'+
                '.code-link'+
                '{'+
                '	margin-left:10px; '+
                '	padding-left:2px;'+
                '	padding-right:2px; '+
                '	font-size:12px; '+
                '	background:red; '+
                '	color:white!important; '+
                '	text-decoration: none;'+
                '}'+
                '.rating-icon-none {'+
                '    border-color: #bbbbbb;'+
                '    background-color: #8590a612;'+
                '    color: gray;'+
                '}');
//////////////////
      if(window.location.href.indexOf("/code")!= -1) //code
    {
        var source_btn = $("<a></a>")
        source_btn.addClass("source");
        source_btn.text("copiare il codice sorgente");
        source_btn.click(function(){
            execCopy();
        });
        $("#install-area").after(source_btn);
    }
  //  else if(window.location.href.indexOf("/scripts/")!= -1) //scripts
  //  {

   // }

})();