Create mega repo

Create pirate repo

by Lissandro Dittmar

HTML

<div id="banner-message">
  <p>Create mega repo</p>
  <button>Do it!</button>  
</div>

<ol id="liste">

</ol>

<a id="downloadAnchorElem" style="display:none"></a>

CSS

i {
  color: #669FAB;
}

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#banner-message {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  font-size: 25px;
  text-align: center;
  transition: all 0.2s;
  margin: 0 auto;
  width: 300px;
}

button {
  background: #0084ff;
  border: none;
  border-radius: 5px;
  padding: 8px 14px;
  font-size: 15px;
  color: #fff;
}

#banner-message.alt {
  background: #0084ff;
  color: #fff;
  margin-top: 40px;
  width: 200px;
}

#banner-message.alt button {
  background: #fff;
  color: #000;
}

.loader {
  border: 16px solid #f3f3f3; /* Light grey */
  border-top: 16px solid #3498db; /* Blue */
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 2s linear infinite;
  margin-left: 410px;
  margin-top: 30px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

JavaScript

const adapterList = ["ioBroker/ioBroker.js-controller"];
const repo = [];
const times = 18;

const start = async function(){
	$('.loader').show();
	for(i=0;i<times;i++){    
    $.getJSON( "https://api.github.com/search/repositories?q=iobroker&page=" + i + "&per_page=100", function( data ) {
      $.each( data.items, function( key, val ) {
      	const full_name = val.full_name;
        const meta = "https://raw.githubusercontent.com/" + full_name + "/master/io-package.json";
        const published = val.created_at;
         
         $.ajax({ 
             url: meta, 
             dataType: 'json', 
             async: false, 
             success: function(res){ 
                if($.inArray(full_name, adapterList) == -1 && res && res.common){
                  adapterList.push(full_name);
                  test = {};
                  test.name = full_name;
                  test.published = published;
                  repo.push(test);
               }
             } 
         });
         
      });      
    }).always(function(){
    	ready();
    });
    await delay(18000);
  };
    
}

const delay = ms => new Promise(res => setTimeout(res, ms));


let count = 0;
const ready = function(){	
	count ++;
  console.log("time" + count + " " + Object.keys(repo).length);
  if(count === times){
  const sorted = repo.sort((a, b) => new Date(b.published) - new Date(a.published));
    sorted.forEach(function(a) {
      $("#liste").append("<li>" + a.name + " - " + a.published + "</li>");
    });   
  }
}

function encode( s ) {
    const out = [];
    for ( let i = 0; i < s.length; i++ ) {
        out[i] = s.charCodeAt(i);
    }
    return new Uint8Array( out );
}



$("button").on("click", function(){
  start();
});