Airflow log hightlight lib

Enhanced keywords highlight for Airflow pages

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/460362/1151949/Airflow%20log%20hightlight%20lib.js

  1. console.log('Airflow log hightlight lib start')
  2. try {
  3.  
  4. function l(message) {if (typeof console == 'object') {console.log(message)} else {GM_log(message)}}
  5. (function word_hightlight(loaded){
  6. //if (window.top != window.self) return; //don't run on frames or iframes
  7. // check browser
  8. if (!loaded && window.opera && document.readyState == 'interactive') {
  9. document.addEventListener('DOMContentLoaded', function(){
  10. loaded = true;
  11. word_hightlight(true);
  12. }, false);
  13. window.addEventListener('load', function(){
  14. if (!loaded)
  15. word_hightlight(true);
  16. }, false);
  17. return;
  18. }
  19. if (document.contentType && !/html/i.test(document.contentType))
  20. return;
  21. // check api
  22. if (typeof GM_getValue == "function") {
  23. var getv = GM_getValue;
  24. var setv = GM_setValue;
  25. } else { // workaround functions, creadit to ww_start_t
  26. var setv = function(cookieName, cookieValue, lifeTime){
  27. if (!cookieName) {return;}
  28. if (lifeTime == "delete") {lifeTime = -10;} else {lifeTime = 31536000;}
  29. document.cookie = escape(cookieName)+ "=" + escape(getRecoverableString(cookieValue))+
  30. ";expires=" + (new Date((new Date()).getTime() + (1000 * lifeTime))).toGMTString() + ";path=/";
  31. };
  32. var getv = function(cookieName, oDefault){
  33. var cookieJar = document.cookie.split("; ");
  34. for (var x = 0; x < cookieJar.length; x++ ) {
  35. var oneCookie = cookieJar[x].split("=");
  36. if (oneCookie[0] == escape(cookieName)) {
  37. try {
  38. eval('var footm = '+unescape(oneCookie[1]));
  39. } catch (e) {return oDefault;}
  40. return footm;
  41. }
  42. }
  43. return oDefault;
  44. };
  45. }
  46. //{ values >
  47. var isOpera = !!this.opera,
  48. isFirefox = !!this.Components,
  49. isChromium = !!this.chromium,
  50. isSafari = this.getMatchedCSSRules && !isChromium;
  51. var STYLE_COLOR = ['#FFFF80','#99ccff','#ff99cc','#66cc66','#cc99ff','#ffcc66','#66aaaa','#dd9966','#aaaaaa','#dd6699'];
  52. var BORDER_COLOR = ['#aaaa20','#4477aa','#aa4477','#117711','#7744aa','#aa7711','#115555','#884411','#555555','#881144'];
  53. var STYLE_COLOR_2 = ['#FFFFa0','#bbeeff','#ffbbcc','#88ee88','#ccbbff','#ffee88','#88cccc','#ffbb88','#cccccc','#ffaabb'];
  54. var BORDER_COLOR_2 = ['#aaaa40','#6699aa','#aa6699','#339933','#9966aa','#aa9933','#337777','#aa6633','#777777','#aa3366'];
  55. var but_c = '#99cc99', but_ca = '#FFD000', but_cd = '#999999', but_cb = '#669966'; // button normal/active/disable background color/border color.
  56. // Initialize value
  57. var PRE = 'wordhighlight', ID_PRE = PRE + '_id', ST_PRE = PRE + '_store', PO_PRE = PRE + '_position', CO_PRE = PRE + '_config';
  58. var STYLE_CLASS = '0123456789'.split('').map(function(a,i){return PRE + '_word'+i;});
  59. var setuped = false;
  60. var highlight_off = false;
  61. var addKeyword = true;
  62. var keyword = "AnalysisException|ValueError|TypeError|ProgrammingError|JSONDecodeError|AnalysisException|NameError|IndentationError|KeyError|IndexError|AttributeError|FileNotFoundError|\
  63. ConnectionError|HTTPError|Received SIGTERM|SyntaxError|OutOfMemory|Container killed by YARN for exceeding memory limits|Failed to get minimum memory|\
  64. Permission denied|Memory limit exceeded|Could not resolve table reference|Could not resolve column/field reference|File does not exist|RemoteException|\
  65. TExecuteStatementResp|object has no attribute|InternalError|NullPointerException|ConnectionError|Failed to close HDFS|cannot be null|IntegrityError|\
  66. ArrayIndexOutOfBoundsException|has more columns|Unknown column|No such file or directory|Out Of Memory|RuntimeError|Traceback|AirflowTaskTimeout|\
  67. Check 'stl_load_errors' system table for details|OperationalError|Lost connection to MySQL server during query|AirflowTaskTimeout|files cols number not match target file cols number, check it|\
  68. Data too long for column|DataError|Initial job has not accepted any resources|/tmp/oneflow_|http://oneflow.yimian.com.cn/dag|num_dumped_rows|com.yimian.etl"
  69. var words = [], word_lists = [], word_inputs_list=[], layers, positions = [];
  70. var words_off = [];
  71. var xp_all = new $XE('descendant::span[starts-with(@name,"' + PRE + '_word")]', document.body);
  72. var keyCodeStr = {
  73. 8: 'BAC',
  74. 9: 'TAB',
  75. 10: 'RET',
  76. 13: 'RET',
  77. 27: 'ESC',
  78. 33: 'PageUp',
  79. 34: 'PageDown',
  80. 35: 'End',
  81. 36: 'Home',
  82. 37: 'Left',
  83. 38: 'Up',
  84. 39: 'Right',
  85. 40: 'Down',
  86. 45: 'Insert',
  87. 46: 'Delete',
  88. 112: 'F1',
  89. 113: 'F2',
  90. 114: 'F3',
  91. 115: 'F4',
  92. 116: 'F5',
  93. 117: 'F6',
  94. 118: 'F7',
  95. 119: 'F8',
  96. 120: 'F9',
  97. 121: 'F10',
  98. 122: 'F11',
  99. 123: 'F12'
  100. };
  101. var whichStr = {
  102. 32: 'SPC'
  103. };
  104. var htmlDoc = isChromium ? document.implementation.createHTMLDocument('hogehoge') : document;
  105. var highlight_reset = function(){};
  106. var canvas, cw, c2context, nav;
  107. var root = /BackCompat/i.test(document.compatMode) ? document.body : document.documentElement;
  108. var CanvasWidth = 150;
  109. var ratio = 1;
  110. var aside, section, td0, lock, edit, off, text_input, posi_tip, posi_tip_timer, inputBOX; // panel elements
  111. var sheet, main_sheet, move_sheet, inst_sheet; // style sheets
  112. //language detection
  113. var _L = 1;
  114. //var _L = (!!(navigator.userAgent.toLowerCase().indexOf('zh-') == -1))? 0:1;
  115. //if(navigator.userAgent.toLowerCase().indexOf('firefox') != -1)
  116. //{_L = (!!(navigator.language.indexOf('zh-') == -1))? 0:1;} // Thanks to SoIN(http://userscripts.org/users/302257)
  117. var _ti = { // en/zh locale string for tooltip.
  118. edit: ['Edit current keywords','编辑现有关键词'],
  119. edit_a: ['Confirm editing keywords','确认编辑关键词'],
  120. off: ['Toggle all keywords\' highlight','切换全部关键词的高亮'],
  121. td0: ['Double-click to minimize the panel','双击最小化面板'],
  122. td0_a: ['Double-click to restore EWH panel','双击恢复 EWH 面板'],
  123. lock: ['Lock current set of keywords','锁定当前的关键词组'],
  124. lock_a: ['Current locked keyword(s):','当前锁定的关键词组:'],
  125. lock_u: ['Function not supported by this browser','此浏览器不支持该功能'],
  126. close: ['Close Enhanced word highlight','关闭关键词高亮'],
  127. kwL: ['Left click to the next; Right click to the previous','左击跳到下一个;右击跳到上一个'],
  128. check: [['Toggle highlight of "','"'],['切换“','”的高亮']],
  129. mapl:['Toggle highlight map locking status','切换高亮分布图的锁定状态'],
  130. ad_nw: ['Toggle add/new keywords for highlight','切换添加/取代关键词的高亮'],
  131. subm: ['Submit keywords','提交关键词'],
  132. clos: ['Close input box','关闭输入框']
  133. };
  134. var _di = { // en/zh locale string for dialog.
  135. update: [['There is an update available for the Greasemonkey script "','."\nWould you like to go to the install page now?','No update is available for "','."','An error occurred while checking for updates:\n',' - Manual Update Check'],
  136. ['发现 GM 脚本“','”有更新,\n是否现在打开脚本发布页?','没找到“','”脚本的更新。','检查更新时出现了一个错误:\n',' - 手动检查更新']],
  137. confT: ['Enhanced word highlight Advanced Config','Enhanced word highlight 高级设置'],
  138. conf: [['What auto-pager tool do you mostly use?',
  139. 'Turn off highlight of short keywords by default?',
  140. 'Disable auto-highlight (auto-capture keywords for highlight) ?',
  141. 'Sort keyword for more accurate highlight (Recommended, except for regular expression users)',
  142. 'Save panel position',
  143. 'Show indicator bar when navigating'],
  144. ['你主要用那种自动翻页工具?',
  145. '是否默认停用短关键词的高亮?',
  146. '是否禁用自动高亮(自动抓取关键词来高亮)?',
  147. '排列关键词以更准确高亮(推荐;需要高亮正则表达式的用户除外)',
  148. '保存面板位置',
  149. '查找关键词时显示指示条']],
  150. confR: [[['Autopagerize GM script','Autopager extension','Other (can handle all auto-pager tools but works slow)'],
  151. ['Don\'t turn off','One-letter/digit word','One- and two-letter/digit word'],
  152. ['Enable','Completely disable','Disable on pages opened from supported search results','Disable on supported search result pages']],
  153. [['Autopagerize GM 脚本','Autopager 扩展','其他(能应付任何自动翻页工具但运作较慢)'],
  154. ['否','是;针对单个字母/数字','是,针对单/两个字母/数字'],
  155. ['不禁用','完全禁用','仅在从支持的搜索结果中打开的页面上禁用','仅在支持的搜索结果页面上禁用']]]
  156. };
  157. //}
  158. var urlArr = [], queryArr = [];
  159. //{ Config I >
  160. // #### Config I #### --------------------------{{
  161. // keybinds
  162. var KEY_NEXT = 'n'; // "n" Next occurrence
  163. var KEY_PREV = 'b'; // "Shift-n" Previous occurrence
  164. var KEY_SEARCH = 'M-/'; // "Alt-/" Add keywords
  165. var KEY_OFF = 'M-,'; // "Alt-," Suspend highlight
  166. var KEY_CLOSE = 'C-M-/'; // "Ctrl-Alt-/" Disable highlight
  167. var KEY_EDIT = 'M-.'; // "Alt-." Edit highlight
  168. var KEY_REFRESH = 'r'; // "r" Refresh highlight
  169. // delay of highlighting (ms)
  170. var delay = 500;
  171. // instant highlight selected keywords
  172. var instant = true;
  173. // restore focus and scroll position after closing keyword input box with shortcut key?
  174. // mainly useful for keyboard navigation, not recommend for mouse navigation.
  175. var refocus = false;
  176. // minimize the panel initially?
  177. var panel_hide = true;
  178. // #### Config I #### --------------------------}}
  179. //}
  180. if (window.top != window.self) panel_hide = true; //hide panel in iframes
  181. //{ Config II >
  182. // #### Config II #### --------------------------{{
  183. // What's your main auto-pager tool?
  184. // 0 - Autopagerize (GM script)
  185. // 1 - AuroPager (Firefox Extension)
  186. // 2 - Other (Other auto-pager scripts, site-specific scripts, bookmarklets, etc.)
  187. //<!> From top option to botom one, the compatibility of the script
  188. // will be strengthened while the performance of highlight will be lower.
  189. var ap_option = 2;
  190. // turn off short keywords (one or two letters or number) by default?
  191. // 0-no, 1-one letter, 2-one or two letters
  192. var off_short_words = 1;
  193. // Stop auto-highlight on supported pages?
  194. // 0-no, 1-yes, 2-only those from search results, 3-only search results
  195. var no_auto_hili = 0;
  196. // sort keywords? 0-no, 1-yes
  197. //<!> Setting this to "yes" will produce better highlight result,
  198. // while "no" will perform faster and support ReExp input better.
  199. var sort_keywords = 0;
  200. // save panel position?
  201. var save_panel_pos = false;
  202. // show indicator bar when navigating?
  203. var show_indc_bar = false;
  204. // GM APIs available?
  205. if (typeof GM_getValue == "function") var gm_ok = true;
  206. // Configs
  207. if (!gm_ok) {
  208. //
  209. var Ewh_configs = [ap_option, off_short_words, no_auto_hili, sort_keywords, save_panel_pos, show_indc_bar];
  210. } else {
  211. var Ewh_configs = GM_getValue(CO_PRE, '2|1|0|1|0|0').split('|');
  212. }
  213. for (i in Ewh_configs) {Ewh_configs[i] = Number(Ewh_configs[i]);}
  214. // Locked keywords
  215. if (gm_ok) var keyword_store = GM_getValue(ST_PRE);
  216. // Saved position
  217. var panel_pos_arr = ['right:-1px;','bottom:-1px;'];
  218. if (Ewh_configs[4] && gm_ok) panel_pos_arr = GM_getValue(PO_PRE, panel_pos_arr.join('|')).split('|');
  219. // Configs menuConnectionError
  220. if (gm_ok) window.addEventListener('load', function(){GM_registerMenuCommand(_di.confT[_L], config_box);}, false);
  221. if (gm_ok) {
  222. unsafeWindow.EWH_iSearch = function() {instant_search(false, null);};
  223. unsafeWindow.EWH_cClose = function() {command_close();};
  224. }
  225. // main process
  226. init_keyboard();
  227. if (load_keyword() !== false || init_keyword() !== false) {
  228. //window.addEventListener('load', go, false);
  229. setTimeout(go, delay);
  230. }
  231. // var oldurl = window.location.href;
  232. // window.addEventListener('DOMNodeInserted', function(e){ l(window.location.href);
  233. // if (window.location.href !== oldurl) {
  234. // if (load_keyword() !== false || init_keyword() !== false) {
  235. // setTimeout(go, delay*2);
  236. // }
  237. // }
  238. // }, false);
  239. function go(){
  240. setup();
  241. }
  242. // Functions
  243. function highlight(doc, ext_word) {
  244. var _words = words.filter(function(w,i){return !words_off[i];});
  245. if (_words.length <= 0)
  246. return;
  247. var _index;
  248. if (ext_word && ext_word.words) {
  249. _words = ext_word.words;
  250. _index = ext_word.index;
  251. }
  252. var exd_words, xw;
  253. if (_words.length === 1 && _words[0].exp) {
  254. exd_words = _words.map(function(e){return e.exp;});
  255. xw = '';
  256. } else {
  257. exd_words = _words.map(function(w){return w.test ? w : new RegExp('(' + w.replace(/\W/g,'\\$&') + ')(?!##)', 'ig');});
  258. xw = ' and (' + _words.map(function(w){return ' contains(translate(self::text(),"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ"),'+escapeXPathExpr(w.toUpperCase())+') ';}).join(' or ') + ') ';
  259. }
  260. $X('descendant::text()[string-length(normalize-space(self::text())) > 0 ' + xw +' and not(ancestor::textarea or ancestor::script or ancestor::style or ancestor::aside)]', doc).forEach(function(text_node) {
  261. var df, text = text_node.nodeValue, id_index = 0,
  262. parent = text_node.parentNode, range = document.createRange(), replace_strings = [],
  263. new_text = reduce(exd_words, function(text,ew,i) {
  264. var _i = _index || i;
  265. return text.replace(ew,function($0,$1) {
  266. replace_strings[id_index] = '<span id="' + ID_PRE + id_index + '" class="' + STYLE_CLASS[_i%10] + '" name="'+PRE+'_word'+_i+'">' + $1 + '</span>';
  267. return '##'+(id_index++)+'##';
  268. });
  269. }, text).
  270. replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').
  271. replace(/##(\d+)##/g, function($0,$1) {
  272. return replace_strings[$1] || '';
  273. });
  274. if (replace_strings.length) {
  275. try {
  276. if (isChromium) {
  277. range.selectNodeContents(htmlDoc.documentElement);
  278. } else {
  279. range.selectNode(text_node);
  280. }
  281. df = range.createContextualFragment(new_text);
  282. if (df.firstChild) parent.replaceChild(df, text_node);
  283. range.detach();
  284. } catch (e) {
  285. error(e);
  286. }
  287. }
  288. });
  289. }
  290. function addsheet() {
  291. if (!main_sheet) {
  292. var hilistyles = STYLE_COLOR.map(function(rgb,i){
  293. return 'span.' + PRE + '_word'+i+',.' + PRE + '_item'+i+'{background:'+rgb+'!important;}';
  294. });
  295. var borderstyles = BORDER_COLOR.map(function(rgb,i){
  296. return 'li.' + PRE + '_item'+i+'{outline:1px solid '+rgb+'!important;}';
  297. });
  298. sheet = addCSS([
  299. //Additional Style
  300. 'span[class^="' + PRE + '_word"]{color:black!important;font:inherit!important;display:inline!important;margin:0!important;padding:0!important;text-align:inherit!important;float:none!important;position:static!important;}', //vertical-align:inherit !important;
  301. '#' + PRE + '_words, #' + PRE + '_words *{font-family: Arial ;}',
  302. '#' + PRE + '_words{line-height:1;position:fixed;z-index:60000;opacity:0.8;list-style-type:none;margin:0;padding:0;width:auto;max-width:100%;' + panel_pos_arr[0] + panel_pos_arr[1] +'}',
  303. '#' + PRE + '_words > section{clear:right;line-height:1;border:1px solid #666;/*border-left-width:10px;*/background:#fff;display:block;position:relative;}',
  304. '#' + PRE + '_words * {margin:0;padding:0;width:auto;height:auto;}',
  305. '#' + PRE + '_words:hover{opacity:1;}',
  306. '#' + PRE + '_words:hover > section{opacity:1;border-color:#333;}',
  307. '#' + PRE + '_words #_ewh_handle{background:#666;width:10px;cursor:move;}',
  308. '#' + PRE + '_words:hover #_ewh_handle{background:#333;}',
  309. '#' + PRE + '_words.ewh_hide #_ewh_handle{cursor:pointer;}',
  310. // '#' + PRE + '_words.ewh_hide:hover #_ewh_handle{width:10px;}',
  311. // '#' + PRE + '_words.ewh_hide > section form.' + PRE + '_ctrl > input.c_b{display:none;}',
  312. '#' + PRE + '_words > nav{display:none;width:100%;padding:3px;position:relative;}',
  313. '#' + PRE + '_words > nav > canvas.backport{background:rgba(0,0,0,0.5);cursor:pointer;position:absolute;right:6px;z-index:3;}',
  314. '#' + PRE + '_words > nav > canvas.viewport{background:rgba(79,168,255,0.7);cursor:default;position:absolute;bottom:0px;right:6px;}',//outline:6px solid rgba(79,168,255,0.7);
  315. // '#' + PRE + '_words > nav:hover > canvas.backport{background:rgba(0,0,0,0.5);}',
  316. '#' + PRE + '_words:hover > nav{display:block;}',
  317. '#' + PRE + '_words > nav._locked{display:block;}',
  318. '#' + PRE + '_words:hover > nav > canvas.backport{bottom:0px;}',
  319. '#' + PRE + '_words > nav._locked > canvas.backport{bottom:0px;}',
  320. '#' + PRE + '_words.ewh_edit{opacity:1;}',
  321. '#' + PRE + '_words.ewh_edit #' + PRE + '_word_inputs_list{display:none;}',
  322. '#' + PRE + '_words form.' + PRE + '_editor{display:none;}',
  323. '#' + PRE + '_words.ewh_edit form.' + PRE + '_editor{display:inline-block;}',
  324. '#' + PRE + '_words.ewh_edit form.' + PRE + '_editor input{min-width:80px;}',
  325. '#' + PRE + '_words li{display:inline-block;margin:0.1em 0.2em;line-height:1.3em;font-size:medium;}',
  326. '#' + PRE + '_words > section > * {vertical-align:middle;}',
  327. '#' + PRE + '_words > section td {border:none;}',
  328. '#' + PRE + '_words > section > h3.' + PRE + '_title{display:inline-block;background:#333;color:#fff;padding:0.1em 0.3em;border:none;margin:0 0.2em;}',
  329. '#' + PRE + '_words > section form.' + PRE + '_ctrl{display:inline-block;}',
  330. '#' + PRE + '_words > section form.' + PRE + '_ctrl > input{display:inline;width:1.3em;margin:0.1em 0.1em;background:'+ but_c +';border:1px solid '+ but_cb +';cursor:pointer;font-size:10pt;color:black;}',
  331. '#' + PRE + '_words > section form.' + PRE + '_ctrl > input._active{background:'+ but_ca +';}',
  332. '#' + PRE + '_words > section form.' + PRE + '_ctrl > input._disable{background:'+ but_cd +' !important;cursor:default;}',
  333. '#' + PRE + '_words > section form.' + PRE + '_ctrl > input:hover{outline:1px solid '+ but_cb +'!important;}',
  334. '#' + PRE + '_word_inputs_list {padding:0!important;margin:0.2em!important;display:inline-block;border:none!important;}',
  335. '#' + PRE + '_word_inputs_list > li{position:relative;padding:0 4px;}',
  336. '#' + PRE + '_word_inputs_list > li.ewh_disable{background:white!important;outline:1px solid #999!important;}',
  337. '#' + PRE + '_word_inputs_list > li > label{cursor:pointer;color:black!important;}',
  338. '#' + PRE + '_word_inputs_list > li > input{cursor:pointer;}',
  339. // '#' + PRE + '_word_inputs_list > li > label > input[type=image]{vertical-align:top;padding:0;height:12px;}',
  340. '#' + PRE + '_word_inputs_list > li > input[type=checkbox]{display:none;position:absolute;right:0px;top:0px;opacity:0.7;}',
  341. '#' + PRE + '_word_inputs_list > li:hover{outline-width:2px!important;}',
  342. '#' + PRE + '_word_inputs_list > li:hover > input[type=checkbox]{display:block;}',
  343. '#' + PRE + '_word_inputs_list > li > input[type=checkbox]:hover{opacity:1;}',
  344. '#' + PRE + '_words > section td+td+td > input {display:inline;width:1.3em;margin:0.1em 0.1em;background:#FAFAFA;border:1px solid #aaaaaa;cursor:pointer;font-size:10pt;color:black;}',
  345. ].concat(hilistyles, borderstyles).join('\n'));
  346. main_sheet = true;
  347. }
  348. if (!move_sheet) addmovesheet()
  349. }
  350. function addmovesheet() {
  351. addCSS('.wordhighlight_em{outline:4px solid #FF7B00;-webkit-outline:4px solid #FF7B00;text-decoration:blink;}');
  352. move_sheet = true;
  353. }
  354. function setup(init) {
  355. setuped = true;
  356. addsheet();
  357. // build ui
  358. aside = creaElemIn('aside', document.body);
  359. aside.id = PRE + '_words';
  360. section = creaElemIn('section', aside);
  361. var table_COL = creaElemIn('table', section);
  362. table_COL.setAttribute('style', 'border:0;margin:0;padding:0;border-spacing:2px;border-collapse:separate!important;');
  363. table_COL.setAttribute('cellspacing', '0');
  364. table_COL.setAttribute('cellpadding', '0');
  365. var tbdy_COL = creaElemIn('tbody', table_COL);
  366. var tr_COL = creaElemIn('tr', tbdy_COL);
  367. td0 = creaElemIn('td', tr_COL);
  368. td0.id = '_ewh_handle';
  369. td0.title = _ti.td0[_L];
  370. var td1 = creaElemIn('td', tr_COL);
  371. td1.setAttribute('style', 'border-right: 1px solid black; padding:0.2em 0.3em 0 0;vertical-align:top;');//width:7.2em;
  372. var td2 = creaElemIn('td', tr_COL);
  373. var td3 = creaElemIn('td', tr_COL);
  374. var editor = creaElemIn('form', td2);
  375. editor.className = PRE + '_editor';
  376. text_input = creaElemIn('input', editor);
  377. text_input.type = 'text';
  378. var ctrl = creaElemIn('form', td1);
  379. ctrl.className = PRE + '_ctrl';
  380. var close_button = creaElemIn('input', ctrl);
  381. close_button.type = 'button';
  382. close_button.className = 'c_b';
  383. close_button.value = 'X';
  384. close_button.title = _ti.close[_L];
  385. off = creaElemIn('input', ctrl);
  386. off.type = 'button';
  387. off.value = 'O';
  388. off.title = _ti.off[_L];
  389. lock = creaElemIn('input', ctrl);
  390. lock.type = 'button';
  391. lock.value = 'L';
  392. edit = creaElemIn('input', ctrl);
  393. edit.type = 'button';
  394. edit.value = 'E';
  395. edit.title = _ti.edit[_L];
  396. word_inputs_list = creaElemIn('ul', td2);
  397. word_inputs_list.id = PRE + '_word_inputs_list';
  398. word_inputs_list.className = PRE + '_inputs';
  399. var maplock = creaElemIn('input', td3);
  400. maplock.type = 'button';
  401. maplock.value = '<';
  402. maplock.title = _ti.mapl[_L];
  403. // add interactivity
  404. edit.addEventListener('click',command_edit,false);
  405. off.addEventListener('click',command_off,false);
  406. close_button.addEventListener('click',command_close,false);
  407. editor.addEventListener('submit',function(e){
  408. command_edit();
  409. e.preventDefault();
  410. },false);
  411. if (gm_ok) {
  412. lock.title = _ti.lock[_L];
  413. lock.className = (keyword_store)? '_active' : '';
  414. lock.addEventListener('click',function(){
  415. if (aside.className == 'ewh_edit') return;
  416. if (keyword_store) {
  417. lock.className = '';
  418. lock.title = _ti.lock[_L];
  419. GM_setValue(ST_PRE, '');
  420. keyword_store = '';
  421. // lock.value = 'Lock: Off';
  422. } else {
  423. lock.className = '_active';
  424. lock.title = _ti.lock_a[_L] + ' ' + keyword;
  425. GM_setValue(ST_PRE, keyword);
  426. keyword_store = keyword;
  427. // lock.value = 'Lock: On';
  428. }
  429. },false);
  430. } else {
  431. lock.title = _ti.lock_u[_L];
  432. lock.className = '_disable';
  433. }
  434. /* 展开右下角的画布
  435. td0.addEventListener('dblclick',function(evt){//l(panel_hide,window.innerWidth - aside.offsetLeft,1);
  436. if (panel_hide) {//l('O');
  437. aside.style.right = '0px';
  438. aside.className = '';
  439. panel_hide = false; //默认隐藏
  440. this.title = _ti.td0[_L];
  441. }else{//l(panel_hide);
  442. aside.style.right = (14 - aside.offsetWidth) +'px';
  443. aside.className = 'ewh_hide';
  444. panel_hide = true;//l(panel_hide,3);
  445. this.title = _ti.td0_a[_L];
  446. }
  447. }, false);*/
  448. maplock.addEventListener('click',function(){
  449. if(!nav.className) {nav.className = '_locked'; this.value = '>';}
  450. else {nav.className = ''; this.value = '<';}
  451. },false);
  452. // build map
  453. nav = document.createElement('nav');
  454. aside.insertBefore(nav,aside.firstChild);
  455. canvas = creaElemIn('canvas', nav);
  456. canvas.className='backport';
  457. cw = creaElemIn('canvas', nav);
  458. cw.className='viewport';
  459. var c2 = c2context = canvas.getContext('2d');
  460. // /+drag codes by grea
  461. // scrolling per events
  462. this.perf = 2, this.perfic = 0;
  463. this.moveTo = function(evt){
  464. if (perfic++ % perf || !window.drgg) return;
  465. var x = (evt.offsetX || evt.layerX)/ratio - root.clientWidth/2;
  466. var y = (evt.offsetY || evt.layerY)/ratio - root.clientHeight/2;
  467. window.scrollTo(x, y);
  468. }
  469. with(canvas){
  470. addEventListener('mousedown', function(e){ window.drgg = true; moveTo(e); },false);
  471. addEventListener('mousemove', function(e){ moveTo(e); },false);
  472. addEventListener('mouseup', function(e){ window.drgg = false; moveTo(e); },false);
  473. addEventListener('mouseout', function(e){ window.drgg = false; moveTo(e); },false);
  474. }
  475. // +/codes end
  476. // add AutoPager page change detector
  477. if (Ewh_configs[0]) {
  478. this.pagef = 5, this.pagefic = 0;
  479. var docHeight = document.body.scrollHeight, pageChanged;
  480. this.checkpage = function(){
  481. if ((pagefic++ % pagef == 0) && (document.body.scrollHeight > docHeight)) {
  482. switch (Ewh_configs[0]) {
  483. case 1:
  484. after_load();
  485. break;
  486. case 2:
  487. resetup();
  488. break;
  489. }
  490. docHeight = document.body.scrollHeight;
  491. }
  492. }
  493. }
  494. // sync with map & check page
  495. window.addEventListener('scroll',function(){
  496. var x = window.pageXOffset * ratio;
  497. var y = window.pageYOffset * ratio;
  498. cw.style.bottom = (canvas.height - cw.height - y) + 'px';
  499. cw.style.right = (-x + 6) + 'px';
  500. if (Ewh_configs[0]) checkpage();
  501. },false);
  502. // go to highlight
  503. highlight(document.body);
  504. word_lists = create_inputlist(words);
  505. layers = xp_all.get();
  506. draw_wordmap();
  507. if (!Ewh_configs[0]) init_autopager();
  508. if (panel_hide && !init){
  509. aside.style.right = (14 - aside.offsetWidth) +'px';
  510. aside.className = 'ewh_hide';
  511. td0.title = _ti.td0_a[_L];
  512. }
  513. }
  514. function restore_words(words) {
  515. (words||xp_all.get()).forEach(function(layer,i){
  516. var parent = layer.parentNode;
  517. while (layer.firstChild){
  518. parent.insertBefore(layer.firstChild, layer);
  519. }
  520. parent.removeChild(layer);
  521. });
  522. }
  523. function draw_wordmap() {
  524. var c2 = c2context;
  525. var _height = root.clientHeight * 0.7;
  526. if (_height > CanvasWidth * (root.scrollHeight/root.scrollWidth)) {
  527. canvas.width = CanvasWidth;
  528. canvas.height = CanvasWidth * (root.scrollHeight/root.scrollWidth);
  529. ratio = CanvasWidth / root.scrollWidth;
  530. } else {
  531. canvas.height = _height;
  532. canvas.width = _height * (root.scrollWidth/root.scrollHeight);
  533. ratio = _height / root.scrollHeight;
  534. }
  535. cw.width = root.clientWidth * ratio;
  536. cw.height = root.clientHeight * ratio;
  537. cw.style.bottom = (canvas.height - cw.height - window.pageYOffset * ratio)+'px';
  538. c2.clearRect(0,0,window.innerWidth,window.innerHeight);
  539. c2.beginPath();
  540. word_lists.forEach(function(item,i){
  541. if(!words_off[i]) {
  542. c2.fillStyle = STYLE_COLOR[i%10];
  543. item.get_w().forEach(function(ly,j){
  544. var recs = ly.getClientRects();
  545. for (var i = 0, l = recs.length;i < l;++i){
  546. var rec = recs[i];
  547. var x = Math.max(ratio*(root.scrollLeft + rec.left), 2);
  548. var y = Math.max(ratio*(root.scrollTop + rec.top), 2);
  549. var width = Math.max(ratio*(rec.width ||(rec.right-rec.left)), 2);
  550. var height = Math.max(ratio*(rec.height||(rec.bottom-rec.top)), 2);
  551. c2.fillRect(x, y, width, height);
  552. }
  553. });
  554. }
  555. });
  556. c2.fill();
  557. }
  558. function add_word(word) {
  559. word_tmp = init_words(word);
  560. var word_tmp_len = word_tmp.length, words_len = words.length;
  561. for (var m=0;m<word_tmp_len;m++) {
  562. var word_m = word_tmp[m];
  563. highlight(document.body,{words:[word_m],index:(words_len - word_tmp_len + m)});
  564. word_lists.push.apply(word_lists,create_inputlist([word_m], words_len - word_tmp_len + m));
  565. }
  566. layers = xp_all.get();
  567. draw_wordmap();
  568. }
  569. function resetup() {
  570. //if (!setuped) {go(); return;}
  571. restore_words();
  572. word_lists.forEach(function(item){item.item.parentNode.removeChild(item.item);});
  573. highlight(document.body);
  574. layers = xp_all.get();
  575. word_lists = create_inputlist(words);
  576. draw_wordmap();
  577. }
  578. function move(node) {
  579. if (!node) return;
  580. if (Ewh_configs[5]) var _em_bar;
  581. if (node.className.indexOf(' wordhighlight_em') == -1) node.className += ' wordhighlight_em';
  582. if (node.getBoundingClientRect) {
  583. var pos = node.getBoundingClientRect();
  584. var pos_h = node.offsetHeight;
  585. document.documentElement.scrollTop = document.body.scrollTop =
  586. pos.top + window.pageYOffset - window.innerHeight/2 + pos_h;
  587. if (Ewh_configs[5]) {
  588. var pos_t = getY(node);
  589. _em_bar = creaElemIn('div', document.body);
  590. _em_bar.setAttribute('style', 'background:rgba(29,163,63,.3);position:absolute;width:100%;height:' + pos_h + 'px;top:' + pos_t + 'px;');
  591. }
  592. } else {
  593. node.scrollIntoView();
  594. }
  595. var move_timer = setTimeout(function(){
  596. node.className = node.className.replace(' wordhighlight_em','');
  597. if (_em_bar) document.body.removeChild(_em_bar);
  598. },3000);
  599. }
  600. function create_inputlist(words, start) {
  601. positions[0] = -1;
  602. return words.map(function(w, i){
  603. var _i = i + (start||0);
  604. var li = creaElemIn('li', word_inputs_list);
  605. li.className = PRE + '_item' + _i%10;
  606. var label = creaElemIn('label', li);
  607. (!Ewh_configs[3] && positions[_i+1]) || (positions[_i+1] = -1);
  608. var xp = new $XE('descendant::span[@name="' + PRE + '_word' + _i +'"]', document.body);
  609. var xp_count = new $XE('count(descendant::span[@name="' + PRE + '_word' + _i +'"])', document.body);
  610. label.addEventListener('click',function(){
  611. if (words_off[_i]) return;
  612. var layers = xp.get();
  613. next(_i+1,layers);
  614. },false);
  615. label.addEventListener('contextmenu',function(evt){
  616. evt.preventDefault(); //prevent activating context menu
  617. evt.stopPropagation();
  618. if (words_off[_i]) return;
  619. var layers = xp.get();
  620. prev(_i+1,layers);
  621. },false);
  622. label.addEventListener('DOMMouseScroll', function(evt){
  623. evt.preventDefault();
  624. if (words_off[_i]) return;
  625. var layers = xp.get();
  626. ct = (-evt.detail);
  627. ct < 0 ? next(_i+1,layers) : prev(_i+1,layers);
  628. return false; //?
  629. }, false);
  630. label.className = PRE + '_label' + _i % 10;
  631. label.title = _ti.kwL[_L];
  632. label.textContent = w + ' (' + xp_count.get({result_type:XPathResult.NUMBER_TYPE}).numberValue + ')';
  633. var check = creaElemIn('input', li);
  634. check.type = 'checkbox';
  635. if (words_off[_i]) {
  636. check.checked = false;
  637. li.className += ' ewh_disable';
  638. }
  639. else check.checked = true;
  640. check.title = _ti.check[_L][0] + w + _ti.check[_L][1];
  641. var _id = check.id = ID_PRE + '_check' + _i;
  642. var list = {item:li,word:w,label:label,check:check,get_count:xp_count.get,get_w:xp.get};
  643. check.addEventListener('change', function(){
  644. if (check.checked) {
  645. words_off[_i] = false;
  646. highlight(document.body,{words:[w],index:_i});
  647. after_load(null, _i);
  648. this.parentNode.className = this.parentNode.className.replace(' ewh_disable', '');
  649. } else {
  650. words_off[_i] = true;
  651. restore_words(xp.get());
  652. draw_wordmap();
  653. this.parentNode.className += ' ewh_disable';
  654. }
  655. },false);
  656. return list;
  657. });
  658. }
  659. function endrag(element,opt) {
  660. var p_x, p_y, isDragging;
  661. endrag = function(element,opt){
  662. return new endrag.proto(element,opt||{});
  663. }
  664. endrag.proto = function(elem,opt){
  665. var self = this;
  666. this.element = elem;
  667. this.style = elem.style;
  668. var _x = opt.x !== 'right';
  669. var _y = opt.y !== 'bottom';
  670. this.x = _x ? 'left' : 'right';
  671. this.y = _y ? 'top' : 'bottom';
  672. p_x = this.x;
  673. p_y = this.y;
  674. this.xd = _x ? -1 : 1;
  675. this.yd = _y ? -1 : 1;
  676. this.computed_style = document.defaultView.getComputedStyle(elem, '');
  677. this.drag_begin = function(e){self.__drag_begin(e);};
  678. td0.addEventListener('mousedown', this.drag_begin, false); //only drag on handler
  679. this.dragging = function(e){self.__dragging(e);};
  680. document.addEventListener('mousemove', this.dragging, false);
  681. this.drag_end = function(e){
  682. if (Ewh_configs[4] && isDragging && elem.style[p_x] && gm_ok) {
  683. var h_pos = p_x + ':' + elem.style[p_x] + ';';
  684. var v_pos = p_y + ':' + elem.style[p_y] + ';';
  685. GM_setValue(PO_PRE, h_pos + '|' + v_pos);
  686. }
  687. // if (panel_hide && isDragging && ((window.innerWidth - aside.offsetLeft) > 14)){
  688. // section.className = '';
  689. // panel_hide = false;
  690. // }
  691. self.__drag_end(e);
  692. };
  693. document.addEventListener('mouseup', this.drag_end, false);
  694. };
  695. endrag.proto.prototype = {
  696. __drag_begin:function(e){
  697. if (e.button == 0) {
  698. var _c = this.computed_style;
  699. this.isDragging = isDragging = true;
  700. this.position = {
  701. _x:parseFloat(_c[this.x]),
  702. _y:parseFloat(_c[this.y]),
  703. x:e.pageX,
  704. y:e.pageY
  705. };
  706. e.preventDefault();
  707. }
  708. },
  709. __dragging:function(e){
  710. if (!this.isDragging) return;
  711. var x = Math.floor(e.pageX), y = Math.floor(e.pageY), p = this.position;
  712. // prevent moving out of window
  713. var x_border = window.innerWidth - 40, y_border = window.innerHeight - 20;
  714. if (x - window.pageXOffset > x_border) x = window.pageXOffset + x_border;
  715. if (y - window.pageYOffset > y_border) y = window.pageYOffset + y_border;
  716. p._x = p._x + (p.x - x) * this.xd;
  717. p._y = p._y + (p.y - y) * this.yd;
  718. this.style[this.x] = p._x + 'px';
  719. this.style[this.y] = p._y + 'px';
  720. p.x = x;
  721. p.y = y;
  722. },
  723. __drag_end:function(e){
  724. if (e.button == 0) {
  725. if (this.isDragging)
  726. this.isDragging = isDragging = false;
  727. }
  728. },
  729. hook:function(method,func){
  730. if (typeof this[method] === 'function') {
  731. var o = this[method];
  732. this[method] = function(){
  733. if (func.apply(this,arguments) === false)
  734. return;
  735. o.apply(this,arguments);
  736. };
  737. }
  738. }
  739. };
  740. return endrag(element,opt);
  741. }
  742. function load_keyword() {
  743. if (keyword_store) {
  744. keyword = keyword_store;
  745. prep_keyword();
  746. return true;
  747. }else {
  748. return false;
  749. }
  750. }
  751. function init_keyword() {
  752. if (Ewh_configs[2] == 1) return false;
  753. var name = window.name;
  754. var host = location.host, q = document.location.search.slice(1), e = -1;
  755. if (Ewh_configs[2] == 2 || name == (PRE + '::CLOSED::')) var _no_refer = true;
  756. if (Ewh_configs[2] != 3) init_KW_SR(); //l(101,keyword);
  757. if (!keyword) init_KW_IH(); //l(102,keyword);
  758. if (!_no_refer && !keyword) init_KW_RF(); //l(103,keyword);
  759. if (Ewh_configs[2] != 3 && !keyword) init_KW_SRo(); //l(104,keyword);
  760. keyword = trim(keyword);
  761. if (keyword) {
  762. window.name = PRE + '::' + encodeURIComponent(keyword);
  763. prep_keyword();//l(104,keyword);
  764. return true;
  765. } else {
  766. return false;
  767. }
  768. }
  769. function init_KW_SR() { //for Search Results
  770. var host = location.host, q = document.location.search.slice(1), e = -1;
  771. for (i = 0; i < urlArr.length; i++) {
  772. if (host.indexOf(urlArr[i][2]) != -1 && q.indexOf(urlArr[i][1]) != -1) e = i;//l(e);
  773. }
  774. if (e >= 0) {
  775. keyword = get_KW_from_URL(q, e);//l(keyword);
  776. }
  777. }
  778. function init_KW_SRo() { //for other search result pages
  779. var locationhref = escape(document.location.href);
  780. for (var z = 0; z < queryArr.length; z++) {
  781. var input_query = document.getElementById(queryArr[z][0]);
  782. if (!input_query || locationhref.indexOf(queryArr[z][1]) == -1) continue;
  783. if (input_query.tagName.toLowerCase() == "input") keyword = clean(input_query.value);
  784. if (keyword) break;
  785. }
  786. }
  787. function init_KW_RF() { //for Pages from Results
  788. var host = location.host, ref = document.referrer, e = -1;
  789. for (i = 0; i < urlArr.length; i++) {
  790. if (Ewh_configs[2] == 3 && host.indexOf(urlArr[i][2]) != -1) return;
  791. if (ref.indexOf(urlArr[i][2]) != -1 && ref.indexOf(urlArr[i][1]) != -1) e = i;//l(e);
  792. }
  793. if (e >= 0) {
  794. var _a = document.createElement('a');
  795. _a.href = ref;
  796. var q = _a.search.slice(1);
  797. keyword = get_KW_from_URL(q, e);//l(keyword);
  798. }
  799. }
  800. function init_KW_IH() { //look for keywords in name
  801. if (name.indexOf(PRE) == 0 && name != (PRE + '::CLOSED::')) {
  802. keyword = (new RegExp(PRE + '\\d*::(.+)').exec(decodeURIComponent(window.name))[1]) || '';
  803. }
  804. }
  805. function get_KW_from_URL(urlsearch, _e) {
  806. if (urlArr[_e][0] =='Google' && urlsearch.indexOf('&url=') != -1) urlsearch = urlsearch.replace(/%25/g,'%'); // if it is from Google's redirect link
  807. var qspairs = urlsearch.split('&'), kwtmp;
  808. for (k = 0; k < qspairs.length; k++) {
  809. if (qspairs[k].indexOf(urlArr[_e][1]) == 0) {KW = qspairs[k].substring(urlArr[_e][1].length).replace(/\+/g,' '); break;}
  810. }//l(KW);
  811. /*else*/ kwtmp = decodeURIComponent(KW);
  812. return clean(kwtmp);
  813. }
  814. function prep_keyword() {
  815. words = init_words(keyword);
  816. }
  817. function trim(str) {
  818. return str.replace(/[\n\r]+/g,' ').replace(/^\s+|\s+$/g,'').replace(/\.+\s|\.+$/g,'');
  819. }
  820. function clean(str) {
  821. return str.replace(/(?:(?:\s?(?:site|(?:all)?in(?:url|title|anchor|text)):|(?:\s|^)-)\S*|(\s)(?:OR|AND)\s|[()])/g,'$1');
  822. }
  823. function uniq(arr) {
  824. var a = [], o = {}, i, v, len = arr.length;
  825. if (len < 2) {return arr;}
  826. for (i = 0; i < len; i++) {
  827. v = arr[i];
  828. if (o[v] !== 1) {
  829. a.push(v);
  830. o[v] = 1;
  831. }
  832. }
  833. return a;
  834. };
  835. function word_length_Comp(a,b) {
  836. return (b.length - a.length);
  837. };
  838. function init_words(word) {
  839. var erg = word.match(new RegExp("^ ?/(.+)/([gim]+)?$"));
  840. if (erg) {
  841. var ew = erg[1], flag = erg[2] || '';
  842. var word_s = [{exp:new RegExp('(' + ew + ')(?!##)', flag), text:ew, toString:function(){return ew;}}];
  843. } else if (word) {
  844. var ret=[], eword = word.replace(/"([^"]+)"/g,function($0,$1){$1 && ret.push($1);return '';});
  845. var word_s = eword.split(/[\+\|#]/).filter(function(w){return !!w;}).concat(ret);
  846. word_s = (Ewh_configs[3])? uniq(word_s).sort(word_length_Comp) : uniq(word_s);
  847. if (Ewh_configs[1]) {
  848. for (var i in word_s) {
  849. if (/^[a-z0-9]$/i.test(word_s[i]) || (Ewh_configs[1] == 2 && /^[a-z0-9]{2}$/i.test(word_s[i])))
  850. words_off[i] = true;
  851. else words_off[i] = false;
  852. }
  853. }
  854. }//l(word_s[0].exp);
  855. return word_s;
  856. }
  857. function init_minibuffer() {
  858. if (window.Minibuffer)
  859. document.removeEventListener('keypress', keyhandler, false);
  860. var mini = window.Minibuffer;
  861. mini.addCommand({
  862. name: 'keyword-search',
  863. command: function(stdin){
  864. keyword += ' ' + this.args.join(' ');
  865. keyword = trim(keyword);
  866. prep_keyword();
  867. if (setuped) resetup();
  868. else setup();
  869. return stdin;
  870. }
  871. });
  872. mini.addShortcutkey({
  873. key:KEY_NEXT,
  874. command:next,
  875. description: 'emphasis next keyword'
  876. });
  877. mini.addShortcutkey({
  878. key:KEY_PREV,
  879. command:prev,
  880. description: 'emphasis prev keyword'
  881. });
  882. mini.addShortcutkey({
  883. key:KEY_SEARCH,
  884. command:function(e){
  885. instant_search();
  886. },
  887. description: 'emphasis prev keyword'
  888. });
  889. }
  890. function next(index,_layers) {
  891. _layers || (_layers = (layers || (layers = xp_all.get()) ));
  892. index || (index = 0);
  893. move(_layers[++positions[index]] || (positions[index] = 0, _layers[positions[index]]));
  894. position_box(index);
  895. }
  896. function prev(index,_layers) {
  897. _layers || (_layers = (layers || (layers = xp_all.get()) ));
  898. index || (index = 0);
  899. move(_layers[--positions[index]] || (positions[index] = _layers.length - 1, _layers[positions[index]]));
  900. position_box(index);
  901. }
  902. function position_box(index) {
  903. if (!posi_tip) {
  904. posi_tip = creaElemIn('div', section);
  905. posi_tip.setAttribute('style', 'background:white;color:black;border:1px solid black;text-align:center;position:absolute;left:30px;z-index:1025;font-size:16px;height:20px;top:-20px;width:40px;-moz-box-shadow:0 2px 4px #444444;-Webkit-box-shadow:0 2px 4px #444444;');
  906. }
  907. clearTimeout(posi_tip_timer);
  908. posi_tip.style.display = 'block';
  909. posi_tip.innerHTML = positions[index]+1;
  910. if (index == 0) posi_tip.style.left = '30px';
  911. else posi_tip.style.left = (word_lists[index-1].item.offsetLeft + (word_lists[index-1].item.clientWidth - 40)/2) + 'px';
  912. posi_tip_timer = setTimeout(function(){posi_tip.style.display = 'none';},3000);
  913. }
  914. function init_keyboard() {
  915. if (isOpera) {
  916. } else if (window.Minibuffer) {
  917. init_minibuffer();
  918. return;
  919. } else {
  920. window.addEventListener('GM_MinibufferLoaded', init_minibuffer, false);
  921. }
  922. if (!window.chromium) {
  923. document.addEventListener('keypress', keyhandler, false);
  924. } else {
  925. document.addEventListener('keydown', keyhandler, false);
  926. }
  927. }
  928. function get_key(evt) {
  929. var key = String.fromCharCode(evt.which),
  930. ctrl = evt.ctrlKey ? 'C-' : '',
  931. meta = (evt.metaKey || evt.altKey) ? 'M-' : '';
  932. if (!evt.shiftKey){
  933. key = key.toLowerCase();
  934. }
  935. if (evt.ctrlKey && evt.which >= 186 && evt.which < 192) {
  936. key = String.fromCharCode(evt.which - 144);
  937. }
  938. if (evt.keyIdentifier && evt.keyIdentifier !== 'Enter' && !/^U\+/.test(evt.keyIdentifier) ) {
  939. key = evt.keyIdentifier;
  940. } else if ( evt.which !== evt.keyCode ) {
  941. key = keyCodeStr[evt.keyCode] || whichStr[evt.which] || key;
  942. } else if (evt.which <= 32) {
  943. key = keyCodeStr[evt.keyCode] || whichStr[evt.which];
  944. }
  945. return ctrl+meta+key;
  946. }
  947. function keyhandler(evt) {
  948. if (evt.target.id == PRE + '_textinput') var _r = true;
  949. else if (/^(?:input|textarea)$/i.test(evt.target.localName)) return;
  950. var fullkey = get_key(evt);
  951. if (setuped){
  952. switch (fullkey) {
  953. case KEY_NEXT:
  954. next();
  955. break;
  956. case KEY_PREV:
  957. prev();
  958. break;
  959. case KEY_OFF:
  960. command_off();
  961. break;
  962. case KEY_CLOSE:
  963. command_close();
  964. break;
  965. case KEY_EDIT:
  966. command_edit();
  967. break;
  968. case KEY_REFRESH:
  969. resetup();
  970. break;
  971. }
  972. }
  973. switch (fullkey) {
  974. case KEY_SEARCH:
  975. evt.preventDefault();
  976. evt.stopPropagation();
  977. instant_search(_r, evt.target);
  978. break;
  979. }
  980. }
  981. function command_close() {
  982. document.body.removeChild(aside);
  983. if (document.getElementById(PRE + '_textinputbox')) document.body.removeChild(inputBOX);
  984. instant_search.input = null;
  985. restore_words();
  986. // sheet.disable = true;
  987. if (addCSS.__style.parentNode) addCSS.__root.removeChild(addCSS.__style);
  988. window.name = PRE + '::CLOSED::';
  989. word_lists = [];
  990. // _words = [];
  991. setuped = false;
  992. highlight_reset();
  993. }
  994. function command_off() {
  995. if (aside.className == 'ewh_edit') return;
  996. if (!highlight_off) {
  997. restore_words();
  998. for (i in word_lists) {
  999. word_lists[i].check.checked = false;
  1000. word_lists[i].item.className += ' ewh_disable'
  1001. }
  1002. off.className = '_active'
  1003. highlight_off = true;
  1004. } else {
  1005. word_lists = [];
  1006. word_inputs_list.innerHTML = '';
  1007. resetup();
  1008. for (i in word_lists) {
  1009. word_lists[i].check.checked = true;
  1010. word_lists[i].item.className = word_lists[i].item.className.replace(' ewh_disable', '');
  1011. }
  1012. off.className = '';
  1013. highlight_off = false;
  1014. }
  1015. draw_wordmap();
  1016. }
  1017. function command_edit() {
  1018. if (aside.className == 'ewh_edit') {
  1019. // aside.style.width = 'auto';
  1020. // edit.value = 'Edit';
  1021. edit.className = '';
  1022. edit.title = _ti.edit[_L];
  1023. if (gm_ok) lock.className = lock.className.replace(' _disable','');
  1024. off.className = '';
  1025. highlight_off = false;
  1026. aside.className = '';
  1027. keyword = trim(text_input.value);
  1028. prep_keyword();
  1029. window.name = PRE + '::' + encodeURIComponent(keyword);
  1030. resetup();
  1031. } else {
  1032. var _aside_w = aside.offsetWidth;
  1033. // edit.value = 'Set';
  1034. edit.className = '_active';
  1035. edit.title = _ti.edit_a[_L];
  1036. if (gm_ok) lock.className += ' _disable';
  1037. off.className += ' _disable';
  1038. aside.className = 'ewh_edit';
  1039. text_input.value = keyword;
  1040. text_input.focus();
  1041. var t_width = (Math.max(320,_aside_w) - 135) +'px';
  1042. text_input.style = 'width:'+t_width+';height:22px;margin:2px 0;font-size:15px;';
  1043. // aside.style.width = Math.max(320,_aside_w) +'px';
  1044. }
  1045. }
  1046. function instant_search(_r, e_target) {
  1047. var input_cancel = function(){
  1048. if (refocus) {
  1049. var top = document.body.scrollTop || document.documentElement.scrollTop;
  1050. var left = document.body.scrollLeft || document.documentElement.scrollLeft;
  1051. }
  1052. document.body.removeChild(inputBOX);
  1053. instant_search.input = null;
  1054. if (refocus && e_target) {
  1055. e_target.focus();
  1056. document.body.scrollTop = document.documentElement.scrollTop = top;
  1057. document.body.scrollLeft = document.documentElement.scrollLeft = left;
  1058. }
  1059. };
  1060. var input_position = function(){
  1061. inputBOX.style.bottom = '30px' ;//window.innerHeight - aside.offsetTop + 4 + 'px';
  1062. }
  1063. var input_comfirm = function(text, bAdd){
  1064. if (!text && setuped) return;
  1065. if (bAdd) {
  1066. keyword = trim(((setuped)?keyword:'') + ' ' + text);
  1067. prep_keyword();
  1068. if (setuped) {
  1069. if (Ewh_configs[3]) resetup();
  1070. else add_word(text);
  1071. }
  1072. else setup(true);
  1073. } else {
  1074. keyword = trim(text);
  1075. prep_keyword();
  1076. if (setuped) {
  1077. resetup();
  1078. }
  1079. else setup(true);
  1080. }
  1081. window.name = PRE + '::' + encodeURIComponent(keyword);
  1082. if (instant_search.input) {input_position(); instant_search.input.select();}
  1083. };
  1084. if (_r) {input_cancel(); return;}
  1085. var selectedText = getSelection();
  1086. if (instant && selectedText.toString()) {
  1087. input_comfirm(selectedText.toString(), true);
  1088. return;
  1089. }
  1090. if (instant_search.input) {
  1091. (instant_search.input.value = selectedText) && instant_search.input.select();
  1092. // instant_search.input.focus();
  1093. return;
  1094. }
  1095. if (!inst_sheet) {
  1096. addCSS([
  1097. '#' + PRE + '_textinputbox input[type=button]{padding:0;display:inline;margin:0.1em 0.2em;background:'+ but_c +';border:1px solid #996666;cursor:pointer;font-size:12pt;color:black;}',
  1098. '#' + PRE + '_textinputbox label{padding:0;display:inline;}',
  1099. '#' + PRE + '_textinputbox{border:1px solid #333;margin:0px;padding:0px;position:fixed;bottom:34px;left:5%;z-index:1023;background:#fff;-moz-box-shadow: #333 3px 3px 2px;color:#000;-Webkit-box-shadow: #333 3px 3px 2px;color:#000;font-weight:bold;max-width:70%;font-size:16pt;height:auto;opacity:0.95;}',
  1100. '#' + PRE + '_textinputbox,#' + PRE + '_textinputbox *{font-family: Arial;}',
  1101. '#' + PRE + '_textinput{border:none;margin:0 0 0 5px;padding:0px;max-width:80%;height:100%;background:#fff;color:#000;font-weight:bold;font-size:inherit;}'
  1102. ].join('\n'));
  1103. inst_sheet = true;
  1104. }
  1105. if (!move_sheet) addmovesheet();
  1106. inputBOX = creaElemIn('div', document.body);
  1107. inputBOX.id = PRE + '_textinputbox';
  1108. inputBOX.setAttribute('class', PRE + '_inbox');
  1109. if (setuped) {
  1110. input_position();
  1111. }
  1112. var inputCHECK = creaElemIn('input', inputBOX);
  1113. inputCHECK.type = 'checkbox';
  1114. inputCHECK.checked = addKeyword;
  1115. inputCHECK.title = _ti.ad_nw[_L];
  1116. var inputCHECKlabel = creaElemIn('label', inputBOX);
  1117. inputCHECKlabel.textContent = (addKeyword) ? 'Add':'New';
  1118. inputCHECKlabel.title = inputCHECK.title;
  1119. var i_C_id = inputCHECK.id = 'Add_Check';
  1120. inputCHECKlabel.htmlFor = i_C_id;
  1121. var input = instant_search.input = creaElemIn('input', inputBOX);
  1122. input.id = PRE + '_textinput';
  1123. var go_button = creaElemIn('input', inputBOX);
  1124. go_button.type = 'button';
  1125. go_button.value = '\u2192';
  1126. go_button.title = _ti.subm[_L];
  1127. var close_button = creaElemIn('input', inputBOX);
  1128. close_button.type = 'button';
  1129. close_button.value = 'X';
  1130. close_button.title = _ti.clos[_L];
  1131. inputCHECK.addEventListener('change', function(){
  1132. inputCHECKlabel.textContent = (this.checked) ? 'Add':'New';
  1133. addKeyword = this.checked;
  1134. input.focus();
  1135. },false);
  1136. go_button.addEventListener('click', function(){input_comfirm(input.value, addKeyword);}, false);
  1137. close_button.addEventListener('click', input_cancel, false);
  1138. input.addEventListener('keypress',function(evt){
  1139. var fullkey = get_key(evt);
  1140. switch (fullkey) {
  1141. case 'RET':
  1142. evt.preventDefault();
  1143. evt.stopPropagation();
  1144. input_comfirm(this.value, addKeyword);
  1145. break;
  1146. case 'ESC':
  1147. input_cancel();
  1148. }
  1149. },false);
  1150. input.addEventListener('input',function(e) {
  1151. var text = input.value.toUpperCase();
  1152. if (!/\S/.test(text) || text.length <2) return;
  1153. var x = 'descendant::text()[contains(translate(self::text(),"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ"),'+escapeXPathExpr(text)+') and not(ancestor::textarea) and not(ancestor::script) and not(ancestor::style)]/parent::*';
  1154. var node = document.evaluate(x, document.body, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  1155. if (node) move(node);
  1156. },false);
  1157. if (selectedText.toString()) {
  1158. input.value = selectedText.toString();
  1159. input.select();
  1160. } else if (keyword && !setuped) {
  1161. input.value = keyword;
  1162. input.select();
  1163. } else input.focus();
  1164. }
  1165. function config_box() {
  1166. var confBOXBack = creaElemIn('div', document.body);
  1167. confBOXBack.setAttribute('style', 'background:white;position:fixed;top:0;left:0;width:100%;height:100%;text-align:center;z-index:30000;');
  1168. var confBOX = creaElemIn('div', confBOXBack);
  1169. confBOX.setAttribute('style', 'line-height:1;border:1px solid #333;border-left-width:10px;width:600px;margin:130px auto auto auto;padding:5px;');
  1170. var confTitle = creaElemIn('h3', confBOX);
  1171. confTitle.setAttribute('style', 'font-weight:800;border-bottom:1px solid black;width:80%;margin:15px auto 10px auto;');
  1172. confTitle.innerHTML = _di.confT[_L];
  1173. var confP = creaElemIn('p', confBOX);
  1174. confP.setAttribute('style', 'text-align:left;');
  1175. var conf = [], confR = [], confL = [], opt;
  1176. for (n=0;n<3;n++) {
  1177. conf[n] = document.createTextNode(_di.conf[_L][n]);
  1178. confP.appendChild(conf[n]);
  1179. creaElemIn('br', confP);
  1180. confR[n] = [], confL[n] = [];
  1181. opt = 3;
  1182. if (n == 2) opt = 4;
  1183. for (r=0;r<opt;r++) {
  1184. confR[n][r] = creaElemIn('input', confP);
  1185. confR[n][r].type = 'radio';
  1186. confR[n][r].name = 'confR' + n;
  1187. // confR[n][r].value = r;
  1188. confR[n][r].id = PRE + 'confR' + n + '' + r;
  1189. if (r == Ewh_configs[n]) confR[n][r].checked = true;
  1190. confL[n][r] = creaElemIn('label', confP);
  1191. confL[n][r].textContent = _di.confR[_L][n][r];
  1192. confL[n][r].htmlFor = confR[n][r].id;
  1193. confL[n][r].setAttribute('style', 'display: inline;');
  1194. creaElemIn('br', confP);
  1195. }
  1196. creaElemIn('br', confP);
  1197. }
  1198. var confC = [], confCL = [];
  1199. for (n=3;n<6;n++) {
  1200. r = n-3;
  1201. confC[r] = creaElemIn('input', confP);
  1202. confC[r].type = 'checkbox';
  1203. confC[r].id = PRE + 'confC' + r;
  1204. confC[r].checked = !!(Ewh_configs[n] == 1);
  1205. confCL[r] = creaElemIn('label',confP );
  1206. confCL[r].textContent = _di.conf[_L][n];
  1207. confCL[r].htmlFor = confC[r].id;
  1208. confCL[r].setAttribute('style', 'display: inline;');
  1209. creaElemIn('br', confP);
  1210. creaElemIn('br', confP);
  1211. }
  1212. var cancconfig = function(){document.body.removeChild(confBOXBack);};
  1213. var saveconfig = function(){
  1214. var tmp_config = Ewh_configs.join('|');
  1215. for (n=0;n<3;n++) {
  1216. opt = 3;
  1217. if (n == 2) opt = 4;
  1218. for (r=0;r<opt;r++) {
  1219. if (confR[n][r].checked == true) {
  1220. Ewh_configs[n] = Number(r);
  1221. break;
  1222. }
  1223. }
  1224. }
  1225. for (n=3;n<6;n++) {
  1226. r = n-3;
  1227. if (confC[r].checked == true) Ewh_configs[n] = 1;
  1228. else Ewh_configs[n] = 0;
  1229. }
  1230. if (tmp_config != Ewh_configs.join('|')) {
  1231. GM_setValue(CO_PRE, Ewh_configs.join('|'));
  1232. location.reload();
  1233. }
  1234. else cancconfig();
  1235. };
  1236. var confBa = creaElemIn('input', confBOX);
  1237. confBa.type = 'button';
  1238. confBa.value = 'OK';
  1239. confBa.addEventListener('click',saveconfig,false);
  1240. var confBb = creaElemIn('input', confBOX);
  1241. confBb.type = 'button';
  1242. confBb.value = 'Cancel';
  1243. confBb.addEventListener('click',cancconfig,false);
  1244. }
  1245. function after_load(e, _ind) {
  1246. var cmd = function(_ind){
  1247. if (!_ind) {
  1248. word_lists.forEach(function(item){
  1249. item.label.textContent = item.word + ' (' + item.get_count({result_type:XPathResult.NUMBER_TYPE}).numberValue + ')';
  1250. });
  1251. } else {
  1252. word_lists[_ind].label.textContent = word_lists[_ind].word + ' (' + word_lists[_ind].get_count({result_type:XPathResult.NUMBER_TYPE}).numberValue + ')';
  1253. }
  1254. layers = xp_all.get();
  1255. draw_wordmap();
  1256. if (panel_hide){aside.style.right = (14 - aside.offsetWidth) +'px';}
  1257. }
  1258. setTimeout(cmd, delay+100, _ind);
  1259. }
  1260. function init_autopager(e) {
  1261. var page = 0, disabled = false;
  1262. var inserted_highlight = function(e){
  1263. setTimeout(highlight, delay, e.target);
  1264. };
  1265. window.addEventListener('AutoPatchWork.DOMNodeInserted', inserted_highlight,false);
  1266. window.addEventListener('AutoPatchWork.pageloaded', after_load,false);
  1267. window.addEventListener('AutoPagerize_DOMNodeInserted', inserted_highlight,false);
  1268. window.addEventListener('GM_AutoPagerizeNextPageLoaded', after_load,false);
  1269. window.addEventListener('Super_preloaderPageLoaded', resetup ,false);
  1270. highlight_reset = function(){
  1271. window.removeEventListener('AutoPatchWork.DOMNodeInserted', inserted_highlight,false);
  1272. window.removeEventListener('AutoPatchWork.pageloaded', after_load,false);
  1273. window.removeEventListener('AutoPagerize_DOMNodeInserted', inserted_highlight,false);
  1274. window.removeEventListener('GM_AutoPagerizeNextPageLoaded', after_load,false);
  1275. window.removeEventListener('Super_preloaderPageLoaded', resetup ,false);
  1276. }
  1277. }
  1278. function $XE(exp, context) {
  1279. var xe = new XPathEvaluator();
  1280. var resolver = xe.createNSResolver(document.documentElement);
  1281. //var defaultNS = document.lookupNamespaceURI(window.opera ? '' : null);
  1282. var defaultNS = (document.documentElement.nodeName !== 'HTML') ? context.namespaceURI : null;
  1283. if (defaultNS) {
  1284. var defaultPrefix = '__default__';
  1285. if (!isChromium)
  1286. exp = addDefaultPrefix(exp, defaultPrefix);
  1287. var defaultResolver = resolver;
  1288. resolver = function (prefix) {
  1289. return (prefix == defaultPrefix) ? defaultNS : defaultResolver.lookupNamespaceURI(prefix);
  1290. };
  1291. }
  1292. var ex = xe.createExpression(exp, resolver);
  1293. this.get = function(param) {
  1294. param || (param={});
  1295. var result = this.result =
  1296. ex.evaluate(param.context||context, param.result_type||XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,this.result);
  1297. if (param.result_type) return result;
  1298. for (var i = 0, len = result.snapshotLength, res = new Array(len); i < len; i++) {
  1299. res[i] = result.snapshotItem(i);
  1300. }
  1301. return res;
  1302. };
  1303. }
  1304. // via AutoPagerize Thx! nanto_vi
  1305. function addDefaultPrefix(xpath, prefix) {
  1306. var tokenPattern = /([A-Za-z_\u00c0-\ufffd][\w\-.\u00b7-\ufffd]*|\*)\s*(::?|\()?|(".*?"|'.*?'|\d+(?:\.\d*)?|\.(?:\.|\d+)?|[\)\]])|(\/\/?|!=|[<>]=?|[\(\[|,=+-])|([@$])/g;
  1307. var TERM = 1, OPERATOR = 2, MODIFIER = 3;
  1308. var tokenType = OPERATOR;
  1309. prefix += ':';
  1310. function replacer(token, identifier, suffix, term, operator, modifier) {
  1311. if (suffix) {
  1312. tokenType =
  1313. (suffix == ':' || (suffix == '::' && (identifier == 'attribute' || identifier == 'namespace')))
  1314. ? MODIFIER : OPERATOR;
  1315. } else if (identifier) {
  1316. if (tokenType == OPERATOR && identifier != '*') {
  1317. token = prefix + token;
  1318. }
  1319. tokenType = (tokenType == TERM) ? OPERATOR : TERM;
  1320. } else {
  1321. tokenType = term ? TERM : operator ? OPERATOR : MODIFIER;
  1322. }
  1323. return token;
  1324. }
  1325. return xpath.replace(tokenPattern, replacer);
  1326. }
  1327. // http://d.hatena.ne.jp/amachang/20090917/1253179486
  1328. function escapeXPathExpr(text) {
  1329. var matches = text.match(/[^"]+|"/g);
  1330. function esc(t) {
  1331. return t == '"' ? ('\'' + t + '\'') : ('"' + t + '"');
  1332. }
  1333. if (matches) {
  1334. if (matches.length == 1) {
  1335. return esc(matches[0]);
  1336. } else {
  1337. var results = [];
  1338. for (var i = 0, len = matches.length; i < len; i ++) {
  1339. results.push(esc(matches[i]));
  1340. }
  1341. return 'concat(' + results.join(', ') + ')';
  1342. }
  1343. } else {
  1344. return '""';
  1345. }
  1346. }
  1347. function $X(exp, context, resolver, result_type) {
  1348. context || (context = document);
  1349. var Doc = context.ownerDocument || context;
  1350. var result = Doc.evaluate(exp, context, resolver, result_type || XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  1351. if (result_type) return result;
  1352. for (var i = 0, len = result.snapshotLength, res = new Array(len); i < len; i++) {
  1353. res[i] = result.snapshotItem(i);
  1354. }
  1355. return res;
  1356. }
  1357. // reduce https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce#Compatibility
  1358. function reduce(arr, fun) {
  1359. var len = arr.length, i = 0, rv;
  1360. if (arguments.length >= 3) rv = arguments[2];
  1361. else {do {
  1362. if (i in arr) {
  1363. rv = arr[i++];break;
  1364. }
  1365. if (++i >= len) throw new TypeError();
  1366. } while (true)};
  1367. for (; i < len; i++) if (i in arr) rv = fun.call(null, rv, arr[i], i, arr);
  1368. return rv;
  1369. }
  1370. function error(e) {
  1371. if (isOpera) {
  1372. opera.postError(e);
  1373. } else if (window.console) {
  1374. console.error(e);
  1375. }
  1376. }
  1377. function addCSS(css) {
  1378. var sheet, self = arguments.callee;
  1379. if (document.createStyleSheet) { // for IE
  1380. sheet = document.createStyleSheet();
  1381. sheet.cssText = css;
  1382. return sheet;
  1383. } else if (!self.__style || !self.__root) {
  1384. sheet = document.createElement('style');
  1385. sheet.type = 'text/css';
  1386. self.__style = sheet;
  1387. self.__root = document.getElementsByTagName('head')[0] || document.documentElement;
  1388. }
  1389. sheet = self.__style.cloneNode(false);
  1390. sheet.textContent = css;
  1391. return self.__root.appendChild(sheet).sheet;
  1392. }
  1393. function getY(oElement) {
  1394. var iReturnValue = 0;
  1395. while (oElement != null) {
  1396. iReturnValue += oElement.offsetTop;
  1397. oElement = oElement.offsetParent;
  1398. }
  1399. return iReturnValue;
  1400. }
  1401. function creaElemIn(tagname, destin) {
  1402. var theElem = destin.appendChild(document.createElement(tagname));
  1403. return theElem;
  1404. }
  1405. /** Get elements by className
  1406. * @function getElementsByClassName
  1407. * @param string className
  1408. * @param optional string tag restrict to specified tag
  1409. * @param optional node restrict to childNodes of specified node
  1410. * @return Array of nodes
  1411. * @author Jonathan Snook, http://www.snook.ca/jonathan
  1412. * @author Robert Nyman, http://www.robertnyman.com
  1413. */
  1414. function getElementsByClassName(className, tag, elm) {
  1415. var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
  1416. var tag = tag || "*";
  1417. var elm = elm || document;
  1418. var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
  1419. var returnElements = [];
  1420. var current;
  1421. var length = elements.length;
  1422. for(var i=0; i<length; i++){
  1423. current = elements[i];
  1424. if(testClass.test(current.className)){
  1425. returnElements.push(current);
  1426. }
  1427. }
  1428. return returnElements;
  1429. }
  1430. // GM api to cookie function
  1431. function getRecoverableString(oVar,notFirst){
  1432. var oType = typeof(oVar);
  1433. if((oType == 'null' )|| (oType == 'object' && !oVar )){
  1434. return 'null';
  1435. }
  1436. if(oType == 'undefined' ){ return 'window.uDfXZ0_d'; }
  1437. if(oType == 'object' ){
  1438. //Safari throws errors when comparing non-objects with window/document/etc
  1439. if(oVar == window ){ return 'window'; }
  1440. if(oVar == document ){ return 'document'; }
  1441. if(oVar == document.body ){ return 'document.body'; }
  1442. if(oVar == document.documentElement ){ return 'document.documentElement'; }
  1443. }
  1444. if(oVar.nodeType && (oVar.childNodes || oVar.ownerElement )){ return '{error:\'DOM node\'}'; }
  1445. if(!notFirst ){
  1446. Object.prototype.toRecoverableString = function (oBn){
  1447. if(this.tempLockIgnoreMe ){ return '{\'LoopBack\'}'; }
  1448. this.tempLockIgnoreMe = true;
  1449. var retVal = '{', sepChar = '', j;
  1450. for(var i in this ){
  1451. if(i == 'toRecoverableString' || i == 'tempLockIgnoreMe' || i == 'prototype' || i == 'constructor' ){ continue; }
  1452. if(oBn && (i == 'index' || i == 'input' || i == 'length' || i == 'toRecoverableObString' )){ continue; }
  1453. j = this[i];
  1454. if(!i.match(basicObPropNameValStr)){
  1455. //for some reason, you cannot use unescape when defining peoperty names inline
  1456. for(var x = 0; x < cleanStrFromAr.length; x++ ){
  1457. i = i.replace(cleanStrFromAr[x],cleanStrToAr[x]);
  1458. }
  1459. i = '\''+i+'\'';
  1460. } else if(window.ActiveXObject && navigator.userAgent.indexOf('Mac')+ 1 && !navigator.__ice_version && window.ScriptEngine && ScriptEngine()== 'JScript' && i.match(/^\d+$/)){
  1461. //IE mac does not allow numerical property names to be used unless they are quoted
  1462. i = '\''+i+'\'';
  1463. }
  1464. retVal += sepChar+i+':'+getRecoverableString(j,true);
  1465. sepChar = ',';
  1466. }
  1467. retVal += '}';
  1468. this.tempLockIgnoreMe = false;
  1469. return retVal;
  1470. };
  1471. Array.prototype.toRecoverableObString = Object.prototype.toRecoverableString;
  1472. Array.prototype.toRecoverableString = function (){
  1473. if(this.tempLock ){ return '[\'LoopBack\']'; }
  1474. if(!this.length ){
  1475. var oCountProp = 0;
  1476. for(var i in this ){ if(i != 'toRecoverableString' && i != 'toRecoverableObString' && i != 'tempLockIgnoreMe' && i != 'prototype' && i != 'constructor' && i != 'index' && i != 'input' && i != 'length' ){ oCountProp++; } }
  1477. if(oCountProp ){ return this.toRecoverableObString(true); }
  1478. }
  1479. this.tempLock = true;
  1480. var retVal = '[';
  1481. for(var i = 0; i < this.length; i++ ){
  1482. retVal += (i?',':'')+getRecoverableString(this[i],true);
  1483. }
  1484. retVal += ']';
  1485. delete this.tempLock;
  1486. return retVal;
  1487. };
  1488. Boolean.prototype.toRecoverableString = function (){
  1489. return ''+this+'';
  1490. };
  1491. Date.prototype.toRecoverableString = function (){
  1492. return 'new Date('+this.getTime()+')';
  1493. };
  1494. Function.prototype.toRecoverableString = function (){
  1495. return this.toString().replace(/^\s+|\s+$/g,'').replace(/^function\s*\w*\([^\)]*\)\s*\{\s*\[native\s+code\]\s*\}$/i,'function (){[\'native code\'];}');
  1496. };
  1497. Number.prototype.toRecoverableString = function (){
  1498. if(isNaN(this)){ return 'Number.NaN'; }
  1499. if(this == Number.POSITIVE_INFINITY ){ return 'Number.POSITIVE_INFINITY'; }
  1500. if(this == Number.NEGATIVE_INFINITY ){ return 'Number.NEGATIVE_INFINITY'; }
  1501. return ''+this+'';
  1502. };
  1503. RegExp.prototype.toRecoverableString = function (){
  1504. return '\/'+this.source+'\/'+(this.global?'g':'')+(this.ignoreCase?'i':'');
  1505. };
  1506. String.prototype.toRecoverableString = function (){
  1507. var oTmp = escape(this);
  1508. if(oTmp == this ){ return '\''+this+'\''; }
  1509. return 'unescape(\''+oTmp+'\')';
  1510. };
  1511. }
  1512. if(!oVar.toRecoverableString ){ return '{error:\'internal object\'}'; }
  1513. var oTmp = oVar.toRecoverableString();
  1514. if(!notFirst ){
  1515. //prevent it from changing for...in loops that the page may be using
  1516. delete Object.prototype.toRecoverableString;
  1517. delete Array.prototype.toRecoverableObString;
  1518. delete Array.prototype.toRecoverableString;
  1519. delete Boolean.prototype.toRecoverableString;
  1520. delete Date.prototype.toRecoverableString;
  1521. delete Function.prototype.toRecoverableString;
  1522. delete Number.prototype.toRecoverableString;
  1523. delete RegExp.prototype.toRecoverableString;
  1524. delete String.prototype.toRecoverableString;
  1525. }
  1526. return oTmp;
  1527. }
  1528. })();
  1529.  
  1530. } catch (e) {
  1531. console.error('Airflow log hightlight error', e)
  1532. }
  1533. console.log('Airflow log hightlight lib end')

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址