-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
75 lines (70 loc) · 2.21 KB
/
Copy pathcontent.js
File metadata and controls
75 lines (70 loc) · 2.21 KB
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
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.type === "origin-data")
var prefixes = request.prefixes;
prefixes = prefixes.match(/\d+/g);
let pos = getPosition();
let segmentationID = { "segID": getSegmentationID(prefixes)};
let data = Object.assign({}, pos, segmentationID);
console.log(data);
sendResponse(data);
});
function getPosition () {
var pos = {};
pos["x"] = getCoordinateValue("x");
pos["y"] = getCoordinateValue("y");
pos["z"] = getCoordinateValue("z");
return pos;
}
function getCoordinateValue (coordinate) {
let inputs = document.querySelectorAll("input.position-status-coord");
for(let input of inputs) {
if( input.previousSibling.textContent.trim() === coordinate) {
console.log(input.value);
return input.value;
}
}
console.log("Nothing found at input for " + coordinate);
return "";
}
function getSegmentationID (prefixes){
let url = window.location.href;
let re = /segmentation'_'segments':\[[^\]]*/i;
let text = url.match(re)? url.match(re)[0]: "";
console.log(text);
if (text === ""){
return "";
}
let arr = text.match(/\d+/g);
if (prefixes === null){
return arr[0];
}
if(arr.length === 0) {
return null;
} else if (arr.length === 1 && arr){
return arr[0];
} else {
for( var i = 0; i < arr.length; i++){
for( var j = 0; j < arr.length; j++ ){
if(i !== j) {
if(in_prefix_set(arr[i], arr[j], prefixes)){
return arr[j];
} else if (in_prefix_set(arr[j], arr[i], prefixes)){
return arr[i];
}
}
}
}
// Reaches this if no string is found as a substring of another
console.log("Returning first segmentation id as the default: " + arr[0]);
return arr[0];
}
}
function in_prefix_set(segId, root, prefixes){
for(prefix of prefixes){
if(segId === prefix + root){
return true
}
}
return false
}