-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
executable file
·83 lines (73 loc) · 2.42 KB
/
content.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
function injectNewButtons() {
console.info('DOM loaded');
initOn();
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', injectNewButtons);
} else {
injectNewButtons();
}
document.addEventListener("click", function(msg){
initOn();
});
function initOn() {
var query_selector = document.querySelector("div#query");
if(document.querySelector("button#solr_up")) {
return;
}
if(query_selector == undefined) {
return;
}
var ahref = document.createElement('button');
ahref.type = 'submit';
ahref.id = 'solr_up';
ahref.textContent = 'UP';
ahref.style.cssText = "position: fixed;bottom: 95px;right: 63px;";
query_selector.parentNode.insertBefore(ahref, query_selector.nextSibling);
ahref.onclick = function () {
window.scrollTo({ top: 0, behavior: 'smooth' });
};
if (document.querySelector("button#buton_solr")) {
return;
}
var index = document.createElement('button');
index.type = 'submit';
index.id = 'buton_solr';
index.textContent = 'Row Numbers';
index.style.cssText = "margin-top: 10px;";
index.addEventListener("click", insertRowNumbers, false);
var query = document.querySelector("form.ng-pristine");
query.parentNode.insertBefore(index, query.nextSibling);
}
function httpGet(theUrl, sendResponse) {
fetch(theUrl)
.then(response => response.json())
.then(body => body.response)
.then(solrResponse => solrResponse.docs)
.then(json => sendResponse(json))
return true;
}
function insertRowNumbers(){
href_url = document.querySelector('#url').href;
if (href_url) {
httpGet(href_url, function(json) {
var columns = new Map();
for (const entry of json.entries()) {
columns.set(entry[0], Object.keys(entry[1]).length);
}
row_numbers = 1;
nOfkeys = 0;
console.log(columns)
document.querySelectorAll('#response > pre > code > span:nth-child(4) > span:nth-child(6) span.value').forEach(function (box, i) {
if (i == 0) {
nOfkeys = columns.get(0);
}
box.setAttribute("title", row_numbers);
if ((i+1) % nOfkeys == 0) {
row_numbers += 1;
nOfkeys += columns.get(row_numbers - 1);
}
});
});
}
}