-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
121 lines (107 loc) · 6.54 KB
/
popup.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2023 Maastricht University Library
// Use of this source code is governed by an Apache 2.0-style
// license that can be found in the LICENSE file or at
// https://github.com/MaastrichtU-Library/the-FAIR-extension/blob/main/LICENSE
//var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
function fair(id){
// posts evaluation using the doi and the FAIR api
var url = "https://api.fair-enough.semanticscience.org/evaluations";
var url2 = "https://doi.org/" + id ;
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
console.log(xhr.status, xhr.responseText);
//If response is successful
if (xhr.readyState === 4) {
var data=xhr.responseText;
var jsonResponse = JSON.parse(data);
console.log(jsonResponse);
//Add evaluation score
document.getElementById("evaluation").innerHTML = "<br>🎓️ Evaluation score: <br><br>"+jsonResponse["score"]+"/22";
//Add score percentage
document.getElementById("score").ariaValueNow = jsonResponse["score_percent"].toString()+"=";
//Turn into rounded percentage as style only takes integers
let percent = Math.round(jsonResponse["score_percent"]).toString();
document.getElementById("score").style = "--value:"+percent;
//Add successful results
var url = "https://w3id.org/fair-enough/metrics/tests/";
var testurl = "http://semanticscience.org/resource/SIO_000300";
var find = ["f1-data-identifier-persistent","f1-metadata-identifier-persistent","f1-metadata-identifier-unique","f2-grounded-metadata" ,"f2-structured-metadata" , "f3-data-identifier-in-metadata" ,"f3-metadata-identifier-in-metadata","f4-searchable" ]
var findStatement = ["F1 - Data identifier is persistent", "F1 - Resource identifier is persistent", "F1 - Resource metadata identifier is unique", "F2 - Metadata is grounded and machine-readable" , "F2 - Metadata is structured" , "F3 - Data identifier explicitly in metadata", "F3 - Metadata identifier explicitly in metadata", "F4 - The resource is indexed in a searchable resource"];
var access = ["a1-metadata-protocol","a1-data-protocol","a1-data-authorization","a1-metadata-authorization","a2-metadata-persistent"]
var accessState = ["A1.1 - Metadata uses an open free protocol for metadata retrieval", "A1.1 - Uses an open free protocol for data retrieval", "A1.2 - Data authentication and authorization" , "A1.2 - Metadata authentication and authorization", "A2 - Metadata is persistent"]
var inter = ["i1-data-knowledge-representation-semantic", "i1-data-knowledge-representation-structured" , "i1-metadata-knowledge-representation-semantic", "i1-metadata-knowledge-representation-structured","i2-fair-vocabularies-known","i2-fair-vocabularies-resolve","i3-metadata-contains-outward-links"]
var interState = ["I1 - Data uses a formal semantic knowledge representation language", "I1 - Data uses a formal structured knowledge representation language", "I1 - Metadata uses a formal semantic knowledge representation language", "I1 - Metadata uses a formal structured knowledge representation language", "I2 - Metadata uses FAIR Vocabularies registered in known repositories", "I2 - Metadata uses resolvable FAIR Vocabularies", "I3 - Metadata contains outward references"]
var reuse = ["r1-includes-license","r1-includes-standard-license"]
var reuseState = ["R2 - Metadata include a License","R1 - Metadata includes a standard License"]
//Findable
for(let i=0;i<find.length;i++){
if(jsonResponse["contains"][url+find[i]][0][testurl][0]["@value"]==1){
document.getElementById("find").innerHTML += "<div class=\"boxed3 center3\" style=\"background-color:white\">  ✅  " + findStatement[i]+"</div>"
}
}
//accessible
for(let i=0;i<access.length;i++){
if(jsonResponse["contains"][url+access[i]][0][testurl][0]["@value"]==1){
document.getElementById("access").innerHTML += "<div class=\"boxed3 center3\" style=\"background-color:white\">  ✅  " + accessState[i]+"</div>"
}
}
//inetroperable
for(let i=0;i<inter.length;i++){
if(jsonResponse["contains"][url+inter[i]][0][testurl][0]["@value"]==1){
document.getElementById("inter").innerHTML += "<div class=\"boxed3 center3\" style=\"background-color:white\">  ✅  " + interState[i]+"</div>"
}
}
//Reusable
for(let i=0;i<reuse.length;i++){
if(jsonResponse["contains"][url+reuse[i]][0][testurl][0]["@value"]==1){
document.getElementById("reuse").innerHTML += "<div class=\"boxed3 center3\" style=\"background-color:white\">  ✅  " + reuseState[i]+"</div>"
}
}
//Clear storage when done to avoid wrong results in different pages
chrome.storage.local.clear()
return [0,1];
}};
// data used to post request
var data = `{
"subject": "` + url2+`",
"collection": "fair-enough-data"
}`;
xhr.send(data);
}
// function getDoi() {
// // Retreive the DOI indicated by the user from chrome storage
// chrome.storage.local.get(['key'], async function(result) {
// //Check if there are any DOI's in the storage
// if(result.key != null){
// //Let the user know evaluation is under process
// document.getElementById("evaluation").innerText = "🎓️Evaluation under process";
// //Start the evaluation
// const results = await fair(result.key);
// }
// });
// }
function getDoi() {
// Retrieve the DOI indicated by the user from chrome storage
chrome.storage.local.get(['key'], async function(result) {
//Check if there are any DOI's in the storage
if(result.key != null){
//Let the user know evaluation is under process
document.getElementById("evaluation").innerText = "🎓️Evaluation under process";
// Show spinner
document.getElementById('spinner').style.display = 'block';
// Start the evaluation
await fair(result.key);
// Hide spinner
document.getElementById('spinner').style.display = 'none';
}
});
}
// initiates popup functions
//getDoi();
document.addEventListener('DOMContentLoaded', (event) => {
// The DOM is fully loaded. You can safely manipulate it here.
getDoi();
});