2014-10-01 74 views
7

有什麼辦法到明星按鈕添加到庫中的宣傳頁,就像有的Facebook就像谷歌Plus的+1按鈕,您只需添加一個片段和按鈕的作品?Github的STAR按鈕

+0

不容易。使用這個API你必須使這個調用成爲https:// developer.github.com/v3/activity/starring /#star-a-repository',但它需要認證,所以首先你必須得到一個宣誓令牌('https:// developer.github.com/v3/oauth_authorizations') – 2014-10-03 05:01:01

+1

看一看[this](http://ghbtns.com/) – 2014-11-14 08:06:02

+0

@KamranAhmed:太好了,發佈爲答案,以便其他人可以找到它很容易 – 2014-11-15 05:47:33

回答

9

我使用GitHub上的按鈕,你可以找到here

enter image description here

+7

ghbtns.com的問題在於,當您點擊星形按鈕時,它實際上並未對項目進行演示。它只是帶你到GitHub頁面。然後你必須再次點擊按鈕。這會讓很多用戶感到困惑。 – jcoffland 2015-04-23 20:12:19

0

我想這可能是可能的。以下片段可能會起作用。現在它缺少:owner:repo字段,但這是微不足道的添加。我不確定你是否可以解決這個問題,如果你嘗試一下,你會得到非常多的東西。這也不是很安全,因爲他們沒有直接將他們的信譽輸入到github中。但你不能這樣做,因爲它需要有回調交互

一個更容易的替代方案就是讓星星成爲github頁面的鏈接,並且它們可以在那裏出現。結帳這個網站添加相同的外觀到按鈕http://ghbtns.com/http://www.buildbuttons.com/GitHub/StarButton

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<img id="github-star" src="http://placehold.it/50/000000/ffffff"></img> 
 
<div id="github-overlay"> 
 
    <input id="github-username" type="username" name="username" placeholder="Username"> 
 
    <input id="github-password" type="password" name="password" placeholder="Password"> 
 
    <a id="github-submit" href="#">Star It</a> 
 
</div> 
 
<script> 
 
    $(document).ready(function() { 
 
    $("#github-star").click(function() { 
 
     $("#github-overlay").css("display", "block"); 
 
    }); 
 
    $("#github-submit").click(function(e) { 
 
     e.preventDefault(); 
 
     $.ajax({ 
 
     type: "PUT", 
 
     url: "user/starred/:owner/:repo", 
 
     username: $("#github-username").val(), 
 
     password: $("#github-password").val(), 
 
     success: function(data) { 
 
      $("#github-overlay").css("display", "none"); 
 
      $("#github-star").attr("src", "http://placehold.it/50/e8117f/ffffff"); 
 
     } 
 
     }); 
 
     return false; 
 
    }); 
 
    }); 
 
</script> 
 
<style> 
 
    #github-overlay { 
 
    display: none; 
 
    position: absolute; 
 
    top: 25%; 
 
    bottom: 25%; 
 
    left: 25%; 
 
    right: 25%; 
 
    } 
 
    #github-submit { 
 
    display: block; 
 
    } 
 
    #github-star:hover { 
 
    cursor: pointer; 
 
    } 
 
</style>

+3

但是誰會想要在您的網站上輸入他們的GitHub用戶名和密碼,並且相信您不會竊取它? – jcoffland 2015-04-23 20:10:05

+0

我同意,這不是很大 – 2015-04-23 21:03:48