-
Notifications
You must be signed in to change notification settings - Fork 0
/
java_pre.user.js
154 lines (130 loc) · 5.26 KB
/
java_pre.user.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// ==UserScript==
// @name java_pre
// @namespace chdg61
// @author chdg61
// @description Сворачивался pre
// @include *
// @version 1.0.1
// @grant none
// ==/UserScript==
(function(window){
var options = {
"time_reload" : 100,
"class_div_toogle": "array_pre",
"class_show_array": "show_array",
"class_hide_array": "hide_array",
"class_span_plus": "button_plus",
"class_span_minus": "button_minus",
"content_plus": "+",
"content_minus": "-",
"style_span": "color: blue;cursor:pointer;font-weight:bold;",
"style_span_string_block": "color:green;cursor:pointer;font-weight:bold;",
"style_pre": "background:white;z-index:1000px;position:relative;border: 2px dotted red;padding 5px;"
};
function action_pre(){
var all_pre = window.document.getElementsByTagName("PRE");
var div_visual_editor = null;
for(var i =0; i < all_pre.length; i++){
if(!all_pre[i].action_pre){
if(div_visual_editor === null){
div_visual_editor = window.document.querySelector("div.bxce") || false;
if(div_visual_editor && all_pre[i].compareDocumentPosition(div_visual_editor) & 8){
continue;
}
}else if(div_visual_editor !== false && div_visual_editor !== null){
if(all_pre[i].compareDocumentPosition(div_visual_editor) & 8){
continue;
}
}
all_pre[i].innerHTML = all_pre[i].innerHTML.replace(/^(.*)$/img,action_line);
all_pre[i].style.background = "white";
all_pre[i].style.zIndex = 1000;
all_pre[i].style.position = "relative";
all_pre[i].style.border = "2px dotted red";
all_pre[i].style.padding = "5px";
}
all_pre[i].action_pre = true;
}
setTimeout(action_pre,options.time_reload);
}
function action_line(str, line, offset, s){
var _regExArrayBlockReplace = /^(\s*?)([\(\)])(\s*?)$/i,
_regExArrayBlockTest = /^\s*?[\(\)]\s*?$/i,
_regExStringBlockReplace = /^(\s*?)\[(.*?)\]\s=>(.*?)$/i,
_regExStringBlockTest = /^\s*?\[.*?\]\s=>.*?$/i;
if(_regExArrayBlockTest.test(line)){
return line.replace(_regExArrayBlockReplace,function(str, p1, p2, p3, offset, s){
var _new_str = "";
if(p1){
_new_str+= p1;
}
if(p2 === "("){
_new_str+= "(";
_new_str+= "<span data-offset='" + offset + "' class='" + options.class_span_minus + "' onclick='_preSpanToogle(this);' style='" + options.style_span + "'>" + options.content_minus + "</span>";
_new_str+= "<span data-offset='" + offset + "' class='" + options.class_show_array + "'>";
}else if(p2 === ")"){
_new_str+= "</span>";
_new_str+= ")";
}
if(p3){
_new_str+= p3;
}
return _new_str;
});
}else if(_regExStringBlockTest.test(line)){
return line.replace(_regExStringBlockReplace,function(str, p1, p2, p3, offset, s){
var _new_str = "";
if(p1){
_new_str+= p1;
}
_new_str+= "[";
_new_str+= "<span onclick='' style='" + options.style_span_string_block + "'>" + p2 + "</span>";
_new_str+= "] => ";
if(p3){
_new_str+= _htmlspecialchars(p3);
}
return _new_str;
});
}else{
return _htmlspecialchars(line);
}
}
function _toggleDivArray(element){
if(element.className === options.class_show_array){
element.style.display = "none";
element.className = options.class_hide_array;
}else{
element.style.display = "";
element.className = options.class_show_array;
}
}
function _toggleSpan(element){
if(element.className === options.class_span_minus){
element.className = options.class_span_plus;
element.innerHTML = options.content_plus;
}else{
element.className = options.class_span_minus;
element.innerHTML = options.content_minus;
}
}
function _htmlspecialchars(str){
if(!str.replace){
return str;
}
return str.replace(/</g, '<').replace(/>/g, '>');
}
function _htmlspecialcharsback(str){
if(!str.replace){
return str;
}
return str.replace(/\</g, '<').replace(/\>/g, '>');
}
window._preSpanToogle = function(element){
var offset = element.getAttribute("data-offset");
if(offset && element.nextElementSibling && element.nextElementSibling.getAttribute("data-offset") === offset){
_toggleDivArray(element.nextElementSibling);
_toggleSpan(element);
}
}
setTimeout(action_pre,options.time_reload);
})(unsafeWindow);