GithubHomePageStar

在 Github 首页显示最近的 30 个 star 项目,部分参考自 zhihaofans 的 https://greasyfork.org/zh-CN/scripts/25101

当前为 2018-06-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GithubHomePageStar
  3. // @description Show the latest 30 starred repos in Github home page.
  4. // @description:zh-CN 在 Github 首页显示最近的 30 个 star 项目,部分参考自 zhihaofans 的 https://greasyfork.org/zh-CN/scripts/25101
  5. // @description:zh-TW 在 Github 首頁顯示最近的 30 個 star 項目,部分參考自 zhihaofans 的 https://greasyfork.org/zh-CN/scripts/25101
  6. // @author ladit
  7. // @version 1.0.3
  8. // @namespace https://greasyfork.org/zh-CN/scripts/33511
  9. // @homepageURL https://github.com/ladit/Userscripts
  10. // @supportURL https://github.com/ladit/Userscripts
  11. // @grant none
  12.  
  13. // @require https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js
  14. // @match https://github.com/
  15. // ==/UserScript==
  16.  
  17. function getStarredList(userName) {
  18. var itemsList = '';
  19. var item = '';
  20. $.getJSON('https://api.github.com/users/' + userName + '/starred', function (starredRepos) {
  21. var isPublic = '';
  22. $.each(starredRepos, function (key, starredRepo) {
  23. if (starredRepo.private === true) {
  24. isPublic = 'private';
  25. } else {
  26. isPublic = 'public';
  27. }
  28. item = '<li class="' + isPublic + ' source "><a class="d-flex flex-items-baseline flex-items-center f5 mb-2" href="' + starredRepo.full_name + '"><div class="text-gray-light mr-2"><svg aria-label="Repository" class="octicon octicon-repo" viewBox="0 0 12 16" version="1.1" width="12" height="16" role="img"><path fill-rule="evenodd" d="M4 9H3V8h1v1zm0-3H3v1h1V6zm0-2H3v1h1V4zm0-2H3v1h1V2zm8-1v12c0 .55-.45 1-1 1H6v2l-1.5-1.5L3 16v-2H1c-.55 0-1-.45-1-1V1c0-.55.45-1 1-1h10c.55 0 1 .45 1 1zm-1 10H1v2h2v-1h3v1h5v-2zm0-10H2v9h9V1z"></path></svg></div><div class="width-full text-bold"><span class="css-truncate css-truncate-target" style="max-width: 100%" title="' + starredRepo.owner.login + '">' + starredRepo.owner.login + '</span>/<span class="css-truncate css-truncate-target" style="max-width: 100%" title="' + starredRepo.name + '">' + starredRepo.name + '</span></div></a></li>';
  29. itemsList += item;
  30. });
  31. });
  32. return '<div id="your_stars" class="Box Box--condensed mb-3 Details js-repos-container" data-pjax-container="" role="navigation"><div class="Box-header"><h3 class="Box-title d-flex flex-justify-between flex-items-center">Recent starred repos<a class="btn btn-sm btn-primary text-white" href="/' + userName + '?tab=stars">All stars</a></h3></div><div class="Box-body"><ul class="list-style-none pr-3" data-filterable-for="dashboard-repos-filter" data-filterable-type="substring">' + itemsList + '</ul></div></div>';
  33. }
  34.  
  35. $(document).ready(function () {
  36. $.ajaxSettings.async = false;
  37. if ($('meta.js-ga-set').attr('content') == 'Logged In') {
  38. var userName = $('meta[name="user-login"]').attr('content');
  39. if (window.localStorage) {
  40. if (!localStorage.getItem('lastStoreStarredReposTime') || Number(localStorage.getItem('lastStoreStarredReposTime')) + 86400000 < $.now()) {
  41. var starredReposBlock = getStarredList(userName);
  42. localStorage.setItem('starredReposBlock', starredReposBlock);
  43. $('.dashboard-sidebar.column.one-third.pr-5.pt-3').append(starredReposBlock);
  44. localStorage.setItem('lastStoreStarredReposTime', $.now());
  45. } else {
  46. $('.dashboard-sidebar.column.one-third.pr-5.pt-3').append(localStorage.getItem('starredReposBlock'));
  47. }
  48. } else {
  49. $('.dashboard-sidebar.column.one-third.pr-5.pt-3').append(getStarredList(userName));
  50. }
  51. }
  52. $.ajaxSettings.async = true;
  53. });