-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.js
137 lines (115 loc) · 4.13 KB
/
gui.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
function mfgListeners() {
//// General
// make GUI almost transparent when out of focus
$('body > ._li')
.mouseenter( ()=> $('#mfgPanel').css('opacity', '0.3') )
.mouseleave( ()=> $('#mfgPanel').css('opacity', '1') );
//// Menu
// button which starts the crawler
$('.mfgButton.start').click( ()=> {
GM_setValue('_isTest',0);
startCrawler();
});
$('.mfgButton.test').click( ()=> mfgShow('#mfgTest') );
$('.mfgLink.return').click( ()=> mfgShow('#mfgStart') );
$('.mfgLink.close').click( ()=> $('#mfgWrapper').hide() );
// start button on the test page
$('.mfgButton.startTest').click( ()=> {
var toTest = parseInt($('#mfgTest textarea').val(),10);
if(toTest > 0) startCrawler(toTest);
else alert('You must enter value larger than 0');
});
// "last results" active or not
let btnRes = $('.mfgButton.results');
if(GM_getValue('_friendsCount',0) > 0) {
btnRes.click(showResults);
} else {
btnRes.css('background','#7a7a7a');
}
//// Crawler
// abort crawling
$('.mfgLink.abort').click( ()=> {
GM_setValue('mfgCrawlerRunning',0);
location.reload();
});
//// Text results
// select all text when clicking on the textarea
$('#mfgPanel textarea').focus( ()=> $('#mfgPanel textarea').select() );
// copy output to clipboard
$('.mfgLink.copy').click( ()=> {
$('#mfgPanel textarea').select();
document.execCommand('copy');
});
//// Graph
// graph fullscreen
$('.mfgGraph svg').click( ()=> {
$('.mfgGraph').toggleClass('fullscreen');
$('.mfgGraph svg').toggle();
hideEverythingElse();
cy.resize();
});
$('.mfgGraph button.center').click( ()=> cy.fit(15) );
$('.mfgGraph button.settings').click( ()=> $('#graphDialog').show() );
// graph layout, one time event listener
$('.mfgGraph button.layout-start').one('click', runLayout);
$('#save-layout').click( ()=> {
graphLayout.current.nodeRepulsion = Number($('#node-repulsion').val());
graphLayout.current.nodeOverlap = Number($('#node-overlap').val());
graphLayout.current.idealEdgeLength = Number($('#ideal-edge-length').val());
graphLayout.current.edgeElasticity = Number($('#edge-elasticity').val());
graphLayout.current.nestingFactor = Number($('#nesting-factor').val());
graphLayout.current.gravity = Number($('#gravity').val());
graphLayout.current.numIter = Number($('#num-iter').val());
graphLayout.current.animate = $('#animate').prop('checked');
graphLayout.current.refresh = Number($('#refresh').val());
graphLayout.current.fit = $('#fit').prop('checked');
graphLayout.current.padding = Number($('#padding').val());
graphLayout.current.randomize = $('#randomize').prop('checked');
graphLayout.current.debug = $('#debug').prop('checked');
graphLayout.current.initialTemp = Number($('#initialTemp').val());
graphLayout.current.minTemp = Number($('#minTemp').val());
$('#graphDialog').hide();
});
$("#default-layout").click( ()=> {
graphLayout.current = Object.assign({}, graphLayout.cose);
$('#graphDialog form')[0].reset(); // [0] cuz .reset() isn't jQ function
$('#graphDialog').hide();
});
}
function runLayout() {
let btn = $('.mfgGraph button.layout-start')
btn.css('color', 'lightgrey');
setTimeout( ()=> {
graphLayout.current.stop = ()=> { // run when layout stops running
btn.css('color', 'black');
btn.one('click', runLayout); // add one-time event listener again
}
cy.layout(graphLayout.current).run();
},100); // timeout to allow greying out to appear
}
function hideEverythingElse() {
var ele = $('head style#mfgHide');
if(ele.length) ele.remove();
else $('head').append('<style id="mfgHide">body > *:not(.mfg) {display: none !important;}</style>')
}
function progressBar(position,string,fraction) {
var percent = (fraction*100).toFixed()+'%';
if(string!=0) {
$('.mfgProgress.' + position + ' p.left').text(string);
}
if(position=='bottom') {
let bott = $('.mfgProgress.bottom .bar div');
if(fraction==0) {
bott.css('transition', 'none');
} else {
bott.css('transition', 'width 0.2s');
}
} else {
$('.mfgProgress.' + position + ' p.right').text(percent);
}
$('.mfgProgress.' + position + ' .bar div').css('width', percent);
}
function mfgShow(str) {
$('#mfgBody > div').hide();
$(str).show();
}