/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ function imgCSS(ed) { var code = ed.getCss(), imags; local = document.location.host.replace(/[-\/\\^$*+?.()|[\]{}]/g,'\\$&'); regex = new RegExp('(http:|https:){0,1}\/\/'+local,'g'); code = code.replace(regex,''); //limpiar url locales code = code.replace(/(http:|https:){0,1}\/\//g,'#'); //marcar url no locales imags = code.match(/\("{0,1}[^#^\(]+?\.(gif|jpg|png|jpeg|tif|tiff|webp|svg|ico)"{0,1}\)/gi); if (imags !== null){ imags =imags.map(function(x){ return x.replace(/\("{0,1}(.*){0,1}"\)/,'$1');}); } else imags =[]; return imags; } /* get image src from HTML file just local urls */ function imgHTML(){ var imags = []; var src; var code = document.querySelector('.gjs-frame').contentDocument; code = code.getElementsByTagName('img'); for (i = 0; i < code.length; i++){ src = code[i].src; src = src.replace(location.origin,''); if (!src.includes('http')){ imags.push(src); } }; imags.push('img/pleca.webp'); //obtiene imagen de la pleca cartel/ en pruebas return imags; } /** Convierte a binario los datos devueltos en la lectura **/ function arrayBufferToBinary(buffer) { var binary = ''; var bytes = [].slice.call(new Uint8Array(buffer)); bytes.forEach((b) => binary += String.fromCharCode(b)); return binary; }; /* Leer los archivos de imagen param: ed el editor */ async function readImgs(ed){ var ImgData; var listaImgs, imagsSet; var peticion, archivo; var content=[]; listaImgs = imgHTML(ed).concat(imgCSS(ed)); imagsSet = new Set(listaImgs); listaImgs = [...imagsSet]; for (var i = 0; i