-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimages_fixer.js
63 lines (47 loc) · 2.06 KB
/
images_fixer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Paramètres à modifier :
dirName (laisser vide en cas d'accès via le nom de domaine, ou mettre "ojs2" en cas d'accès via l'IP)
journalName
*/
const dirName = "<your_ojs_directory_name>";
const journalName = "<your_journal_name>";
const DCIdentifier = document.querySelector('meta[name="DC.Identifier"]');
const imgs = document.querySelectorAll('#jatsParserFullText img');
const submissionId = Number(DCIdentifier.getAttribute('content'));
const stageId = 5;
let fileId;
if(dirName == "" || dirName == null || dirName == undefined){
fileId = syncFetch(`/public/journals/4/betterOJS/file_id_finder.php?submissionId=${submissionId}&expected=xml`);
} else {
fileId = syncFetch(`/${dirName}/public/journals/4/betterOJS/file_id_finder.php?submissionId=${submissionId}&expected=xml`);
}
imgs.forEach(img=>{
const src = img.getAttribute('src');
let imageId;
let newUrl;
if(dirName == "" || dirName == null || dirName == undefined){
imageId = syncFetch(`/public/journals/4/betterOJS/file_id_finder.php?submissionId=${submissionId}&expected=img&imageName=${src}`);
newUrl = `/index.php/${journalName}/article/downloadFullTextAssoc/${submissionId}/${fileId}/${imageId}`;
} else {
imageId = syncFetch(`/${dirName}/public/journals/4/betterOJS/file_id_finder.php?submissionId=${submissionId}&expected=img&imageName=${src}`);
newUrl = `/${dirName}/index.php/${journalName}/article/downloadFullTextAssoc/${submissionId}/${fileId}/${imageId}`;
}
img.src = newUrl;
});
function syncFetch(url){
const async = false;
let xhr = new XMLHttpRequest();
xhr.open('GET',url,async);
xhr.send();
let response = xhr.responseText;
if(response == "" || response == undefined || response == null){
let resStatus;
if(response == ""){
resStatus = "an empty string";
} else {
resStatus = response;
}
console.warn(`There is an error in your syncFetch request.\nThe response is ${resStatus}. Please check your URL, which is ${url}.`);
}
return response;
}