JavaScript - Hacer fork github users

 
Vista:

Hacer fork github users

Publicado por Sabat (1 intervención) el 28/10/2022 18:22:55
Quiero hacer un fork de todos los repositorios de un usuario de github.

He intentando con el siguiente codigo pero no funciono.

Fork all repositories from a user on GitHub
forkAllGitHubRepos.js

var totalForkCount;
var curForkCount=0;
var errorForkArray = new Array();

function initProcess(){
var user = window.location.pathname.split('/')[1];
var **pageNo** = 1;
var hrefArray = new Array();
while(hrefArray.length % 30 == 0){
var resp = sendSyncAjax("https://github.com/"+user+"?tab=repositories&page="+pageNo);
hrefArray = hrefArray.concat(getReposFromHtml(resp));
pageNo++;
}
totalForkCount = hrefArray.length;
forkAll(hrefArray);
}

function getReposFromHtml(response){
var text = response.responseText;
var parser = new DOMParser();
var html = parser.parseFromString(text, "text/html");
var repoCount = html.getElementsByClassName('d-inline-block mb-1').length;
var hrefArray = new Array();
for(var i=0; i<repoCount; i++){
hrefArray.push(html.getElementsByClassName('d-inline-block mb-1')[i].getElementsByTagName('a')[0].href);
}
return hrefArray;
}


function sendSyncAjax(url){
var xhr = new XMLHttpRequest();
xhr.open('GET', url, false);
xhr.send(null);
return xhr;
}

function forkAll(hrefArray){
var div = document.createElement('div');
div.style.display='none';
div.id='hdiv';
document.body.appendChild(div);
for (var i=0; i<hrefArray.length; i++){
loadPageAndFork(hrefArray[i]);
}
}

function loadPageAndFork(url){
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var parser = new DOMParser();
var html = parser.parseFromString(xhr.responseText, "text/html");
if(html.getElementsByClassName('btn-with-count').length == 5){
var actionUrl = html.getElementsByClassName('btn-with-count')[3].action;
var formData = html.getElementsByClassName('btn-with-count')[3].getElementsByTagName('input');
var postData = 'utf8=%E2%9C%93&authenticity_token='+encodeURIComponent(formData[1].value);
sendForkRequest(actionUrl, postData);
}else{
errorForkArray.push(url);
if(totalForkCount == curForkCount+errorForkArray.length){
window.alert("Done forking "+totalForkCount+" repositories. Error with these: "+errorForkArray);
}
}
}
};
xhr.send(null);
}

function sendForkRequest(actionUrl, postData){
var xhr = new XMLHttpRequest();
xhr.open('POST', actionUrl, false);
xhr.onreadystatechange = function() {
if(this.readyState == 4){
if (this.status == 200) {
curForkCount++;
}else{
errorForkArray.push(actionUrl);
}
if(totalForkCount == curForkCount+errorForkArray.length){
window.alert("Done forking "+totalForkCount+" repositories. Error with these: "+errorForkArray);
}
}

}
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send(postData);
}

initProcess();

Alguien sabe porque falla y no hace los fork. Lo intento pero al cargar el javascript en la consola de firefox se para y no hace los fork.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Gio
Val: 368
Bronce
Ha aumentado 1 puesto en JavaScript (en relación al último mes)
Gráfica de JavaScript

Hacer fork github users

Publicado por Gio (79 intervenciones) el 28/10/2022 20:13:35
Te recomiendo usar la siguiente opción para colocar códigos:

Borrar

Habrá gente que no se tomará la molestia de interpretar tu código si no usas esta opción.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar