]>
Softwares of Agnibho - sysrev.git/blob - script.js
3 var doi
="https://doi.org/";
4 var urlParams
=new URLSearchParams(window
.location
.search
);
5 if(urlParams
.has("doi")){
6 doi
="https://"+urlParams
.get("doi")+"/";
8 if(localStorage
.getItem("bibliographies")!=null){
9 bibgraph
=JSON
.parse(localStorage
.getItem("bibliographies"));
12 localStorage
.setItem("bibliographies", JSON
.stringify(bibgraph
));
14 function abstractFormat(text
){
17 text
=text
.replace(/\nobjectives?/i, "<strong>Objectives</strong>");
18 text
=text
.replace(/\nbackground/i, "<strong>Background</strong>");
19 text
=text
.replace(/\nmethods?/i, "\n<strong>Methods</strong>");
20 text
=text
.replace(/\ndesigns?/i, "\n<strong>Design</strong>");
21 text
=text
.replace(/\nmaterials? and methods?/i, "\n<strong>Materials and methods</strong>");
22 text
=text
.replace(/\nmethodology/i, "\n<strong>Methodology</strong>");
23 text
=text
.replace(/\ninterventions?/i, "\n<strong>Interventions</strong>");
24 text
=text
.replace(/\nstatistical analysis/i, "\n<strong>Statistical Analysis</strong>");
25 text
=text
.replace(/\nprincipal findings?/i, "\n<strong>Principal Findings</strong>");
26 text
=text
.replace(/\nfindings?/i, "\n<strong>Findings</strong>");
27 text
=text
.replace(/\noutcomes?/i, "\n<strong>Outcomes</strong>");
28 text
=text
.replace(/\nresults?/i, "\n<strong>Results</strong>");
29 text
=text
.replace(/\nconclusions?/i, "\n<strong>Conclusions</strong>");
30 text
=text
.replace(/\nsignificance/i, "\n<strong>Significance</strong>");
34 function showAllBibs(){
35 $("#all-bibs").html("");
36 Object
.values(bibgraph
).forEach(function(bib
){
38 $("#all-bibs").html($("#all-bibs").html()+"<li class='list-group-item'><a href='#' data-id='"+bib
.config
.id
+"' class='select-bib' >"+bib
.config
.label
+"</a> ["+bib
.config
.id
+"] <button data-id='"+bib
.config
.id
+"' class='btn btn-sm btn-outline-secondary delete-bib'>Delete</button></li>");
40 $("#all-bibs").on("click", ".select-bib", function(e
){
42 $("#loader").addClass("d-none");
43 $("#step-1-div").removeClass("d-none");
44 idx
=$(this).data("id");
45 $("#step-1").html("");
46 bibgraph
[idx
].items
.forEach(function(item
,i
){
47 bibgraph
[idx
].items
[i
].selected
=[false,false,false];
48 $("#step-1").html($("#step-1").html()+"<a href='#' class='list-group-item to-select' data-step='0' data-cite='"+item
.citationKey
+"'><input type='checkbox' class='step-1-select'> "+item
.title
+" ["+item
.creators
[0].lastName
+" et al]</a>");
51 $("#all-bibs").on("click", ".delete-bib", function(e
){
53 delete bibgraph
[$(this).data("id")];
58 $(document
).ready(function(){
60 $(".step-selector").on("click", ".to-select", function(e
){
62 $(this).children("input").prop("checked", !$(this).children("input").prop("checked"));
63 bibgraph
[idx
].items
.find(i
=>i
.citationKey
==$(this).data("cite")).selected
[$(this).data("step")]=$(this).children("input").prop("checked");
66 if(urlParams
.has("src")){
67 if(urlParams
.has("file")){
68 file
="&file="+urlParams
.get("file");
73 $.getJSON(urlParams
.get("src")+"?callback=?"+file
, function(data
){
74 if(typeof bibgraph
[data
.config
.id
]=="undefined"){
75 bibgraph
[data
.config
.id
]=data
;
78 if(confirm("Data with same ID already exists. Overwrite?")){
79 bibgraph
[data
.config
.id
]=data
;
86 $("#load-file").click(function(e
){
88 file
=document
.getElementById("file-selector").files
[0];
92 function fileLoaded(){
94 result
=JSON
.parse(fr
.result
);
95 bibgraph
[result
.config
.id
]=result
;
98 alert("Failed to parse data. \n"+e
);
104 $("#step-1to2").click(function(e
){
106 $("#step-1-div").addClass("d-none");
107 $("#step-2-div").removeClass("d-none");
108 $("#step-2").html("");
109 bibgraph
[idx
].items
.forEach(function(item
, idx
){
111 if(item
.selected
[1]==true) flag
="checked";
112 if(item
.selected
[0]){
113 $("#step-2").html($("#step-2").html()+"<div class='list-group-item'><a href='#' class='to-select' data-step='1' data-cite='"+item
.citationKey
+"'><input type='checkbox' "+flag
+" class='step-2-select'> "+item
.title
+" ["+item
.creators
[0].lastName
+" et al]</a><div class='abstract'>"+abstractFormat(item
.abstractNote
)+"</div></div>");
117 $("#step-2to3").click(function(e
){
119 $("#step-2-div").addClass("d-none");
120 $("#step-3-div").removeClass("d-none");
121 $("#step-3").html("");
122 bibgraph
[idx
].items
.forEach(function(item
, idx
){
124 if(item
.selected
[2]==true) flag
="checked";
125 if(item
.selected
[1]){
127 url
="<br>Link: <a href='"+item
.url
+"' target='_blank'>"+item
.url
+"</a>";
132 $("#step-3").html($("#step-3").html()+"<div class='list-group-item'><a href='#' class='to-select' data-step='2' data-cite='"+item
.citationKey
+"'><input type='checkbox' "+flag
+" class='step-3-select'> "+item
.title
+" ["+item
.creators
[0].lastName
+" et al]</a><div class='alert alert-info text-right'>Paper available at DOI: <a href='"+doi
+item
.DOI
+"' target='_blank'>"+item
.DOI
+"</a>"+url
+"</div></div>");
136 $("#finish").click(function(e
){
138 $("#step-3-div").addClass("d-none");
139 $("#download-div").removeClass("d-none");
140 finalBib
=$.extend(true, {}, bibgraph
[idx
]);
141 for(i
=(finalBib
.items
.length
-1); i
>=0; i
--){
142 if(!(finalBib
.items
[i
].selected
[0] && finalBib
.items
[i
].selected
[1] && finalBib
.items
[i
].selected
[2])){
143 finalBib
.items
.splice(i
,1);
146 $("#finished").html("");
147 finalBib
.items
.forEach(function(item
){
148 if(item
.selected
[2]){
149 $("#finished").html($("#finished").html()+"<li class='list-group-item'>"+item
.title
+" ["+item
.creators
[0].lastName
+" et al]</li>");
150 delete item
.selected
;
153 data
="data:text/json;charset=utf-8,"+encodeURIComponent(JSON
.stringify(finalBib
, null, 2));
154 $("#download").prop("href", data
);
155 $("#download").prop("download", finalBib
.config
.label
+".json");
157 $("#step-back").click(function(e
){
159 $("#step-1-div").addClass("d-none");
160 $("#loader").removeClass("d-none");
162 $("#step-2to1").click(function(e
){
164 $("#step-2-div").addClass("d-none");
165 $("#step-1-div").removeClass("d-none");
167 $("#step-3to2").click(function(e
){
169 $("#step-3-div").addClass("d-none");
170 $("#step-2-div").removeClass("d-none");
172 $("#step-backto3").click(function(e
){
174 $("#download-div").addClass("d-none");
175 $("#step-3-div").removeClass("d-none");