Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes MV3 and many Geneanet improves #130

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
08c9c8a
Fixes MV3 and many Geneanet improves
Sep 11, 2024
2aaf4b0
Restructuring of bakground.js for sending photos and some other details
Nov 27, 2024
36ccef5
Resumption of some general details - Improvements on Geneanet - Inter…
Dec 10, 2024
1923ae6
Malfunction reported by Dan Cornett - FS profile does not have a spou…
Dec 10, 2024
14cbec8
Update messages.json
pquenee Dec 16, 2024
1c5869f
FS with UNKNOWN parent
Dec 17, 2024
ad4587c
Update messages.json
pquenee Dec 17, 2024
a59421a
Merge remote-tracking branch 'refs/remotes/origin/master'
Dec 17, 2024
8c6e8ce
fusion pou coherence
Dec 17, 2024
7882daa
Merge branch 'master' of github.com:pquenee/SmartCopy
Dec 17, 2024
8745cd2
refresh
Dec 17, 2024
fa6dec5
Bug adding history to a GENI page and cosmetics spaces
Dec 19, 2024
8fbb33b
Child bug on Family Search and cosmetic changes
Dec 20, 2024
91c2475
downgrading in the indication of references - restriction for dates l…
Dec 22, 2024
7ab8ffe
Restriction for dates lower than 1600 except for curators: 1000
Dec 22, 2024
205ac03
Multiline on occupation import
Dec 23, 2024
ecbbcaa
marriage information FS - internatinalization - improvement status li…
Jan 11, 2025
4ae5124
Bug on live profile
Jan 16, 2025
d672fdd
location bug in WT
Jan 17, 2025
264fd0f
Significant improvement on FS n, Geneanet, and various details
Jan 24, 2025
45e2f1d
cosmetic space
Jan 25, 2025
a5bf0e1
first improvement on FAG
Feb 1, 2025
dfa45cd
new Family Search URL format
Feb 5, 2025
5d8bea9
Using GuyKh's version with marriage divorce added
Feb 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,535 changes: 850 additions & 685 deletions _locales/en/messages.json

Large diffs are not rendered by default.

850 changes: 850 additions & 0 deletions _locales/fr/messages.json

Large diffs are not rendered by default.

159 changes: 118 additions & 41 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,49 +39,30 @@ function getJsonFromUrl(query) {
// listen for messages - if they include photo URLs, intercept and get them
chrome.runtime.onMessage.addListener( function(request, sender, callback) {
if (request.action == "xhttp") {
delay(190);// see https://www.nginx.com/blog/rate-limiting-nginx/
const method = request.method ? request.method.toUpperCase() : 'GET';
if (method == 'POST') {
fetch(request.url, {
method : method,
body: request.data,
headers: {
"Content-Type" : "application/x-www-form-urlencoded"
}
}).then((response) => {
if (!response.ok) {
console.error("Unable to get XMLHttpRequest: " + request.url);
var valrtn = {error: response.error, variable: request.variable, responseURL: response.responseURL};
callback(valrtn);
} else {
const responseText = response.text();
var valrtn = {source: responseText, variable: request.variable, responseURL: response.responseURL};
callback(valrtn);
const jsData = getJsonFromUrl(request);
if (jsData.photo !== undefined) {
// load the photo from the given URL
fetch(jsData.photo, {
method: 'GET',
headers: {
"Content-Type" : "text/plain; charset=UTF-8"
}
}).then((photoResponse) => {
if (!photoResponse.ok) {
var valrtn = {error: photoResponse.error, responseURL: photoResponse.responseURL};
callback(valrtn);
} else {
const photo = photoResponse.text()
let binary = ""
for(i=0;i<photo.length;i++){
binary += String.fromCharCode(photo.charCodeAt(i) & 0xff);
}
delete jsData.photo;
jsData.file = btoa(binary);
return fetch(getUrlFromJson(jsData));
}
});
}
}
const jsData = getJsonFromUrl(request.data);
//console.log("jsDATA :",jsData.photo,jsData.file);
if (jsData.photo !== undefined) {
const photoOk = GetPhoto(jsData);
/*Chargement de la Photo par appel Url et mise en place d'un appel POST pour la transférer dans Geni - Loading the Photo by Url call and setting up a POST call for transfer into Geni.
Les parametres de l'appel sont transmis dans l'Objet "request", request.url contient l'url, request.data contient 3 clés à l'origine title, attribution, et photo l'url de l'image à charger -data.title, data.attribution et data.photo. Pendant le traitement, on crée la clé "data.file" qu'on remplit avec une chaine codée en base64. On efface data.photo.
The parameters of the call are transmitted in the "request" Object, request.url contains the url, request.data contains 3 keys at the origin title, attribution, and photo the url of the image to load - data.title, data.attribution and data.photo. During processing, we create the “data.file” key which we fill with a base64 encoded string. We delete data.photo.
https://www.geni.com/api/profile-34835287013/add-photo?fields=id,unions,name&access_token=AEWNhgu5Mdz7kGa4pXPXMohl45ZLVeoo1kFUH4p6
*/
photoOk.then((jsData) => {
request.data = jsData
//console.log("RQ_DAT1 url :",request.url,jsData.photo,jsData.file);
const header = "application/x-www-form-urlencoded";
GeniPostReq(request,header,callback);
});
return true
}
//console.log("RQ_DAT2 url :",request.url,jsData.photo,jsData.file);
const header = "application/x-www-form-urlencoded";
GeniPostReq(request,header,callback);

} else {
// pass this request through - note that all receivers need to change for fetch response
var vartn = {variable: request.variable};
Expand Down Expand Up @@ -110,8 +91,93 @@ chrome.runtime.onMessage.addListener( function(request, sender, callback) {
return true;
}
return false;
});
});
//Création et Mis à jour des donnes Geni - Creation and Update of Geni data
function GeniPostReq(request,header,callback) {
fetch(request.url, {
method : "POST",
body: request.data,
headers: {
"Content-Type" : header
}
})
.then((response) => {
if (!response.ok) {
return response.text()
.then((responseText)=> {
console.error("Unable to get Fetch Request: " + request.url);
var valrtn = {error: responseText, variable: request.variable, responseURL: request.url};
console.log("valrtn_FL ",valrtn,request.data);
callback(valrtn);
});

} else {
return response.text()
.then((responseText)=> {
var valrtn = {source: responseText, variable: request.variable, responseURL: request.url};
//console.log("valrtn_OK ",valrtn);
callback(valrtn);
});
}
})
}
// load the photo from the given URL
async function GetPhoto (jsData){

/*
Réécriture du 23 nov 2024.
Utilisation des API JS "ReadableStream: getReader() method" avec la method "read" qui récupère morceaux par morceaux (chunks) les éléments de l'image dans le contexte asynchrone.
Rewritten from Nov 23, 2024.
Using the JS API "ReadableStream: getReader() method" with the "read" method which retrieves the image elements piece by piece (chunks) in the asynchronous context
https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/getReader
La propriete "text()" de fetch ne se comporte pas comme xhr.responseText.
The "text()" property of fetch does not behave like xhr.responseText
*/
try {
const photoResponse = await fetch(jsData.photo, {
method: 'GET',
mode: "cors",
headers: {
"Content-Type" : "application/xml",
// "Access-Control-Allow-Origin": "*",
// "Access-Control-Allow-Methods": "GET",
// "Access-Control-Max-Age": "86400",
},
//credentials: "include",
// superflu jusqu'à preuve du contraire - superfluous until proven otherwise
});
if (!photoResponse.ok) {
throw new Error(`Erreur Photo : ${photoResponse.status}`);
}
const photoreader = photoResponse.body.getReader();
let binary = "";
while (true){
const {done,value} = await photoreader.read();
if (done){
// L'image est entièrement récupéré, on prépare les parametres du POST
// The image is fully recovered, we prepare the POST parameters
delete jsData.photo;
jsData.file = btoa(binary);
jsData = getUrlFromJson(jsData);
return jsData;
}
// Traitement de chaque chunk récupéré - Processing each retrieved chunk
// et construction progressive de la chaine binaire. - and progressive construction of the binary chain.
charsReceived = value.length;
for(i=0;i<charsReceived;i++){
binary += String.fromCharCode(value[i]);
}
}
/* Code obsolete et abandon du & 0xff - Obsolete code and abandonment of & 0xff
for(i=0;i<photoblob.size;i++){
// binary += String.fromCharCode(photoimg.charCodeAt(i) & 0xff);
binary += photoarray[i];
} */
}
catch({name, stat}) {
console.error(name, stat);
}
}
async function evalObject(expression, callback) {
await setupOffscreenDocument("offscreen.html");
await chrome.runtime.sendMessage({
Expand Down Expand Up @@ -184,3 +250,14 @@ async function setupOffscreenDocument(path) {
creating = null;
}
}
/*
En raison des restrictions générés par nginx, il est nécessaire de temporiser les appels pour ne pas saturer les serveurs et se faire jeter. Due to the restrictions generated by nginx, it is necessary to delay calls so as not to saturate the servers and get thrown out.
La programmation n'est pas optimum, mais à défaut de mieux ... The programming is not optimal, but for lack of anything better...
*/
function delay(ms){
let currDate = new Date().getTime();
let dateNow = currDate;
while(dateNow<currDate+ms){
dateNow = new Date().getTime();
}
}
Loading