Main.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import CacheUtils from "./CacheUtils.js";
  2. import GithubUtils from "./GithubUtils.js";
  3. import OpenCollectiveUtils from "./OpenCollectiveUtils.js";
  4. // import Christmas from "./Christmas.js";
  5. class OpenCollectiveService{
  6. static async init(){
  7. const collective="jmonkeyengine";
  8. this.backers=await OpenCollectiveUtils.getBackersFlat(collective,this.backers,(res)=>window.shuffleArray(res));
  9. console.assert(this.backers,"Backers can't be undefined");
  10. this.backersWithMessage = this.backers.filter(el=>el.message);
  11. this.cycleBackers();
  12. this.cycleMessage();
  13. setInterval(() =>{
  14. this.cycleBackers();
  15. }, 5000);
  16. }
  17. static async cycleBackers () {
  18. this.shownBacker=CacheUtils.cachedCycle("backers",0,this.backers.length-1,10000);
  19. const backer = this.backers[this.shownBacker];
  20. document.querySelectorAll("#backerName").forEach(el=>{
  21. el.setAttribute("href", backer.accountUrl);
  22. el.innerHTML = backer.name;
  23. });
  24. }
  25. static async cycleMessage () {
  26. this.shownBackerMessage=CacheUtils.cachedCycle("backersMex",0,this.backersWithMessage.length-1,10000);
  27. const backer = this.backersWithMessage[this.shownBackerMessage];
  28. document.querySelectorAll("#backerMessage").forEach(el=>{
  29. el.innerHTML = backer.message?backer.message:" ";
  30. });
  31. document.querySelectorAll("#backerMessageName").forEach(el=>{
  32. el.innerText = "- "+backer.name;
  33. el.setAttribute("href", backer.accountUrl);
  34. });
  35. }
  36. }
  37. class GithubService{
  38. static async init(){
  39. this.contributors=[];
  40. this.contributors.push(...await GithubUtils.getTop100Contributors("jMonkeyEngine/jmonkeyengine"),(res)=>window.shuffleArray(res));
  41. this.contributors.push(...await GithubUtils.getTop100Contributors("jMonkeyEngine/sdk"),(res)=>window.shuffleArray(res));
  42. this.contributors.push(...await GithubUtils.getTop100Contributors("jMonkeyEngine/wiki"),(res)=>window.shuffleArray(res));
  43. this.resolveUsers();
  44. this.cycleContributors();
  45. setInterval(() =>{
  46. this.cycleContributors();
  47. }, 5000);
  48. }
  49. static async cycleContributors () {
  50. this.shownContributor=CacheUtils.cachedCycle("contribs",0,this.contributors.length-1,20000);
  51. let contributor = this.contributors[this.shownContributor];
  52. contributor=await GithubUtils.resolveUser(contributor.login);
  53. document.querySelectorAll("#contributorName").forEach(contributorNameEl=>{
  54. contributorNameEl.innerText = contributor.name?contributor.name:contributor.login;
  55. contributorNameEl.setAttribute("href", contributor.html_url);
  56. });
  57. }
  58. static async resolveUsers(){
  59. console.log("Look for github users to resolve...")
  60. document.querySelectorAll("[github-user]").forEach(el=>{
  61. const user=el.getAttribute("github-user");
  62. console.log("Found user needing resolution",el,user)
  63. GithubUtils.resolveUser(user).then(user=>{
  64. // console.log(user,"read for resolution!");
  65. const properties={};
  66. properties.name=user.name;
  67. if(!properties.name)properties.name=user.login;
  68. properties.link=user.html_url;
  69. properties.bio=user.bio;
  70. properties.twitter_username=user.twitter_username;
  71. properties.twitter_link=user.twitter_username?"https://twitter.com/"+user.twitter_username:undefined;
  72. properties.public_repos=user.public_repos;
  73. properties.hireable=user.hireable;
  74. properties.email=user.email;
  75. properties.blog=user.blog;
  76. properties.avatar_url=user.avatar_url;
  77. for(let k in properties){
  78. const v=properties[k];
  79. if(!v)continue;
  80. const attr="ghresolve-"+k;
  81. el.querySelectorAll("["+attr+"]").forEach(eel=>{
  82. const realattr=eel.getAttribute(attr);
  83. eel.style.display="inline-block";
  84. if(realattr==="innerText"){
  85. eel.innerText=v;
  86. }else{
  87. eel.setAttribute(realattr,v);
  88. }
  89. })
  90. // el.querySelectorAll(".gh"+k).forEach(eel=>eel.style.display="inline-block");
  91. // el.querySelectorAll("a.gh"+k).forEach(eel=>eel.setAttribute("href",v));
  92. // el.querySelectorAll("span.gh"+k).forEach(eel=>eel.innerText=v);
  93. }
  94. });
  95. });
  96. }
  97. }
  98. window.addEventListener("DOMContentLoaded", function () {
  99. OpenCollectiveService.init();
  100. GithubService.init();
  101. // Christmas.init();
  102. });