|
112 | 112 | function tagName(el) {
|
113 | 113 | return el.tagName.toLowerCase();
|
114 | 114 | };
|
115 |
| -var getBestSelector = function(el) { |
116 |
| - if (!(el instanceof Element)) |
117 |
| - return; |
| 115 | +function turnIntoParentAsNeeded(el) { |
118 | 116 | if (tagName(el) == 'span') {
|
119 |
| - if (tagName(el.parentElement) == 'button') |
| 117 | + if (tagName(el.parentElement) == 'button') { |
120 | 118 | el = el.parentElement;
|
121 |
| - else if (tagName(el.parentElement.parentElement) == 'button') |
| 119 | + } |
| 120 | + else if (tagName(el.parentElement.parentElement) == 'button') { |
122 | 121 | el = el.parentElement.parentElement;
|
| 122 | + } |
123 | 123 | }
|
| 124 | + return el; |
| 125 | +} |
| 126 | +var getBestSelector = function(el) { |
| 127 | + if (!(el instanceof Element)) |
| 128 | + return; |
| 129 | + el = turnIntoParentAsNeeded(el); |
124 | 130 | child_sep = ' > ';
|
125 | 131 | selector_by_id = cssPathById(el);
|
126 | 132 | if (!selector_by_id.includes(child_sep))
|
|
214 | 220 | contains_tags.push('code');
|
215 | 221 | contains_tags.push('mark');
|
216 | 222 | contains_tags.push('label');
|
| 223 | + contains_tags.push('small'); |
217 | 224 | contains_tags.push('button');
|
218 | 225 | contains_tags.push('legend');
|
219 | 226 | contains_tags.push('strong');
|
220 | 227 | contains_tags.push('summary');
|
221 | 228 | all_by_tag = [];
|
222 |
| - inner_text = ''; |
223 |
| - if (el.innerText) |
224 |
| - inner_text = el.innerText.trim(); |
| 229 | + text_content = ''; |
| 230 | + if (el.textContent) |
| 231 | + text_content = el.textContent.trim(); |
225 | 232 | for (var i = 0; i < contains_tags.length; i++) {
|
226 | 233 | if (tag_name == contains_tags[i] &&
|
227 |
| - inner_text.length >= 2 && inner_text.length <= 64) |
| 234 | + text_content.length >= 2 && text_content.length <= 64) |
228 | 235 | {
|
229 | 236 | t_count = 0;
|
230 | 237 | all_by_tag[i] = document.querySelectorAll(contains_tags[i]);
|
231 | 238 | for (var j = 0; j < all_by_tag[i].length; j++) {
|
232 |
| - if (all_by_tag[i][j].innerText.includes(inner_text)) |
| 239 | + if (all_by_tag[i][j].textContent.includes(text_content)) |
233 | 240 | t_count += 1;
|
234 | 241 | }
|
235 |
| - if (t_count === 1 && !inner_text.includes('\n')) { |
236 |
| - inner_text = inner_text.replaceAll("'", "\\'"); |
237 |
| - inner_text = inner_text.replaceAll('"', '\\"'); |
238 |
| - return tag_name += ':contains("'+inner_text+'")'; |
| 242 | + if (t_count === 1 && !text_content.includes('\n')) { |
| 243 | + text_content = text_content.replaceAll("'", "\\'"); |
| 244 | + text_content = text_content.replaceAll('"', '\\"'); |
| 245 | + return tag_name += ':contains("'+text_content+'")'; |
239 | 246 | }
|
240 | 247 | }
|
241 | 248 | }
|
|
340 | 347 | document.body.addEventListener('mouseover', function (event) {
|
341 | 348 | reset_if_recorder_undefined();
|
342 | 349 | if (sessionStorage.getItem('pause_recorder') === 'yes') return;
|
343 |
| - const element = event.target; |
344 |
| - const selector = getBestSelector(element); |
| 350 | + const el = event.target; |
| 351 | + const selector = getBestSelector(el); |
345 | 352 | if (!selector.startsWith('body') && !selector.includes(' div')) {
|
346 | 353 | document.title = selector;
|
347 | 354 | }
|
|
392 | 399 | reset_if_recorder_undefined();
|
393 | 400 | if (sessionStorage.getItem('pause_recorder') === 'yes') return;
|
394 | 401 | const d_now = Date.now();
|
395 |
| - const element = event.target; |
396 |
| - const selector = getBestSelector(element); |
| 402 | + const el = event.target; |
| 403 | + const selector = getBestSelector(el); |
397 | 404 | ra_len = document.recorded_actions.length;
|
398 | 405 | if (ra_len > 0 &&
|
399 | 406 | document.recorded_actions[ra_len-1][0] === 'mo_dn' &&
|
400 | 407 | document.recorded_actions[ra_len-1][1] === selector)
|
401 | 408 | {
|
402 | 409 | document.recorded_actions.pop();
|
403 | 410 | }
|
404 |
| - if (element.draggable === true) { |
| 411 | + if (el.draggable === true) { |
405 | 412 | document.recorded_actions.push(['drags', selector, '', d_now]);
|
406 | 413 | }
|
407 | 414 | json_rec_act = JSON.stringify(document.recorded_actions);
|
|
422 | 429 | reset_if_recorder_undefined();
|
423 | 430 | if (sessionStorage.getItem('pause_recorder') === 'yes') return;
|
424 | 431 | const d_now = Date.now();
|
425 |
| - const element = event.target; |
426 |
| - const selector = getBestSelector(element); |
| 432 | + const el = event.target; |
| 433 | + const selector = getBestSelector(el); |
427 | 434 | ra_len = document.recorded_actions.length;
|
428 | 435 | if (ra_len > 0 && document.recorded_actions[ra_len-1][0] === 'drags')
|
429 | 436 | {
|
|
438 | 445 | reset_if_recorder_undefined();
|
439 | 446 | if (sessionStorage.getItem('pause_recorder') === 'yes') return;
|
440 | 447 | const d_now = Date.now();
|
441 |
| - const element = event.target; |
442 |
| - const selector = getBestSelector(element); |
| 448 | + const el = event.target; |
| 449 | + const selector = getBestSelector(el); |
443 | 450 | ra_len = document.recorded_actions.length;
|
444 |
| - tag_name = tagName(element); |
445 |
| - e_type = element.type; |
| 451 | + tag_name = tagName(el); |
| 452 | + e_type = el.type; |
446 | 453 | if (tag_name === 'select')
|
447 | 454 | {
|
448 | 455 | el_computed = document.querySelector(selector);
|
|
461 | 468 | document.recorded_actions.pop();
|
462 | 469 | ra_len = document.recorded_actions.length;
|
463 | 470 | }
|
464 |
| - value = element.value; |
| 471 | + value = el.value; |
465 | 472 | document.recorded_actions.push(['set_v', selector, value, d_now]);
|
466 | 473 | }
|
467 | 474 | else if (tag_name === 'input' && e_type === 'file') {
|
|
470 | 477 | document.recorded_actions.pop();
|
471 | 478 | ra_len = document.recorded_actions.length;
|
472 | 479 | }
|
473 |
| - value = element.value; |
| 480 | + value = el.value; |
474 | 481 | document.recorded_actions.push(['cho_f', selector, value, d_now]);
|
475 | 482 | }
|
476 | 483 | else if (ra_len > 0 &&
|
|
482 | 489 | if (ra_len > 0 && document.recorded_actions[ra_len-1][1] === selector)
|
483 | 490 | document.recorded_actions.pop();
|
484 | 491 | }
|
485 |
| - if (tag_name === 'input' && e_type === 'checkbox' && element.checked) |
| 492 | + if (tag_name === 'input' && e_type === 'checkbox' && el.checked) |
486 | 493 | document.recorded_actions.push(['c_box', selector, 'yes', d_now]);
|
487 |
| - else if (tag_name === 'input' && e_type === 'checkbox' && !element.checked) |
| 494 | + else if (tag_name === 'input' && e_type === 'checkbox' && !el.checked) |
488 | 495 | document.recorded_actions.push(['c_box', selector, 'no', d_now]);
|
489 | 496 | json_rec_act = JSON.stringify(document.recorded_actions);
|
490 | 497 | sessionStorage.setItem('recorded_actions', json_rec_act);
|
|
493 | 500 | reset_if_recorder_undefined();
|
494 | 501 | if (sessionStorage.getItem('pause_recorder') === 'yes') return;
|
495 | 502 | const d_now = Date.now();
|
496 |
| - const element = event.target; |
497 |
| - const selector = getBestSelector(element); |
| 503 | + el = event.target; |
| 504 | + const selector = getBestSelector(el); |
498 | 505 | ra_len = document.recorded_actions.length;
|
499 | 506 | rec_mode = sessionStorage.getItem('recorder_mode');
|
500 |
| - tag_name = tagName(element); |
| 507 | + tag_name = tagName(el); |
501 | 508 | text = '';
|
502 |
| - if (rec_mode === '3') |
503 |
| - text = element.innerText; |
| 509 | + if (rec_mode === '2' || rec_mode === '3') |
| 510 | + el = turnIntoParentAsNeeded(el); |
| 511 | + texts = [el.innerText, el.textContent]; |
504 | 512 | if (ra_len > 0 && document.recorded_actions[ra_len-1][0] === 'mo_dn')
|
505 | 513 | document.recorded_actions.pop();
|
506 | 514 | if (tag_name === 'select') {
|
507 | 515 | // Do Nothing. ('change' action.)
|
508 | 516 | }
|
509 | 517 | else
|
510 |
| - document.recorded_actions.push(['mo_dn', selector, text, d_now]); |
| 518 | + document.recorded_actions.push(['mo_dn', selector, texts, d_now]); |
511 | 519 | json_rec_act = JSON.stringify(document.recorded_actions);
|
512 | 520 | sessionStorage.setItem('recorded_actions', json_rec_act);
|
513 | 521 | });
|
514 | 522 | document.body.addEventListener('mouseup', function (event) {
|
515 | 523 | reset_if_recorder_undefined();
|
516 | 524 | if (sessionStorage.getItem('pause_recorder') === 'yes') return;
|
517 | 525 | const d_now = Date.now();
|
518 |
| - const element = event.target; |
519 |
| - selector = getBestSelector(element); |
| 526 | + const el = event.target; |
| 527 | + selector = getBestSelector(el); |
520 | 528 | ra_len = document.recorded_actions.length;
|
521 |
| - tag_name = tagName(element); |
522 |
| - parent_element = element.parentElement; |
523 |
| - parent_tag_name = tagName(parent_element); |
524 |
| - grand_element = ""; |
| 529 | + tag_name = tagName(el); |
| 530 | + parent_el = el.parentElement; |
| 531 | + parent_tag_name = tagName(parent_el); |
| 532 | + grand_el = ""; |
525 | 533 | grand_tag_name = "";
|
526 | 534 | origin = "";
|
527 | 535 | rec_mode = sessionStorage.getItem('recorder_mode');
|
528 |
| - if (ra_len > 0 && document.recorded_actions[ra_len-1][0] === 'mo_dn') { |
529 |
| - selector = document.recorded_actions[ra_len-1][1]; |
530 |
| - sel_has_contains = selector.includes(':contains('); |
531 |
| - if (rec_mode === '2' || (rec_mode === '3' && sel_has_contains)) { |
532 |
| - origin = window.location.origin; |
533 |
| - document.recorded_actions.push(['as_el', selector, origin, d_now]); |
| 536 | + if (ra_len > 0 && document.recorded_actions[ra_len-1][0] === 'mo_dn' && |
| 537 | + (rec_mode === '2' || rec_mode === '3')) |
| 538 | + { |
| 539 | + pre_sel = document.recorded_actions[ra_len-1][1]; |
| 540 | + sel_has_contains = pre_sel.includes(':contains('); |
| 541 | + texts = document.recorded_actions[ra_len-1][2]; |
| 542 | + text = texts[0]; |
| 543 | + t_con = texts[1]; |
| 544 | + origin = window.location.origin; |
| 545 | + if (!text) { text = ''; } |
| 546 | + if (rec_mode === '2' || ( |
| 547 | + rec_mode === '3' && sel_has_contains && text === t_con)) |
| 548 | + { |
| 549 | + document.recorded_actions.push(['as_el', pre_sel, origin, d_now]); |
534 | 550 | json_rec_act = JSON.stringify(document.recorded_actions);
|
535 | 551 | sessionStorage.setItem('recorded_actions', json_rec_act);
|
536 | 552 | return;
|
537 | 553 | }
|
538 | 554 | else if (rec_mode === '3') {
|
539 |
| - origin = window.location.origin; |
540 |
| - text = document.recorded_actions[ra_len-1][2]; |
541 | 555 | action = 'as_et';
|
542 |
| - if (!text) { text = ''; } |
543 |
| - else { |
544 |
| - text = text.trim(); |
545 |
| - var match = /\r|\n/.exec(text); |
546 |
| - if (match) { |
547 |
| - lines = text.split(/\r\n|\r|\n/g); |
548 |
| - text = ''; |
549 |
| - for (var i = 0; i < lines.length; i++) { |
550 |
| - if (lines[i].length > 0) { |
551 |
| - action = 'as_te'; text = lines[i]; break; |
552 |
| - } |
| 556 | + text = text.trim(); |
| 557 | + var match = /\r|\n/.exec(text); |
| 558 | + if (match) { |
| 559 | + lines = text.split(/\r\n|\r|\n/g); |
| 560 | + text = ''; |
| 561 | + for (var i = 0; i < lines.length; i++) { |
| 562 | + if (lines[i].length > 0) { |
| 563 | + action = 'as_te'; text = lines[i]; break; |
553 | 564 | }
|
554 | 565 | }
|
555 | 566 | }
|
556 |
| - tex_sel = [text, selector]; |
| 567 | + tex_sel = [text, pre_sel]; |
557 | 568 | document.recorded_actions.push([action, tex_sel, origin, d_now]);
|
558 | 569 | json_rec_act = JSON.stringify(document.recorded_actions);
|
559 | 570 | sessionStorage.setItem('recorded_actions', json_rec_act);
|
560 | 571 | return;
|
561 | 572 | }
|
562 | 573 | }
|
563 |
| - if (parent_element.parentElement != null) { |
564 |
| - grand_element = parent_element.parentElement; |
565 |
| - grand_tag_name = tagName(grand_element); |
| 574 | + if (parent_el.parentElement != null) { |
| 575 | + grand_el = parent_el.parentElement; |
| 576 | + grand_tag_name = tagName(grand_el); |
566 | 577 | }
|
567 | 578 | if (ra_len > 0 &&
|
568 | 579 | document.recorded_actions[ra_len-1][1] === selector &&
|
|
572 | 583 | {
|
573 | 584 | href = '';
|
574 | 585 | if (tag_name === 'a' &&
|
575 |
| - element.hasAttribute('href') && |
576 |
| - element.getAttribute('href').length > 0 && |
577 |
| - element.origin != 'null') |
| 586 | + el.hasAttribute('href') && |
| 587 | + el.getAttribute('href').length > 0 && |
| 588 | + el.origin != 'null') |
578 | 589 | {
|
579 |
| - href = element.href; |
580 |
| - origin = element.origin; |
| 590 | + href = el.href; |
| 591 | + origin = el.origin; |
581 | 592 | }
|
582 | 593 | else if (parent_tag_name === 'a' &&
|
583 |
| - parent_element.hasAttribute('href') && |
584 |
| - parent_element.getAttribute('href').length > 0 && |
585 |
| - parent_element.origin != 'null') |
| 594 | + parent_el.hasAttribute('href') && |
| 595 | + parent_el.getAttribute('href').length > 0 && |
| 596 | + parent_el.origin != 'null') |
586 | 597 | {
|
587 |
| - href = parent_element.href; |
588 |
| - origin = parent_element.origin; |
| 598 | + href = parent_el.href; |
| 599 | + origin = parent_el.origin; |
589 | 600 | }
|
590 | 601 | else if (grand_tag_name === 'a' &&
|
591 |
| - grand_element.hasAttribute('href') && |
592 |
| - grand_element.getAttribute('href').length > 0 && |
593 |
| - grand_element.origin != 'null') |
| 602 | + grand_el.hasAttribute('href') && |
| 603 | + grand_el.getAttribute('href').length > 0 && |
| 604 | + grand_el.origin != 'null') |
594 | 605 | {
|
595 |
| - href = grand_element.href; |
596 |
| - origin = grand_element.origin; |
| 606 | + href = grand_el.href; |
| 607 | + origin = grand_el.origin; |
597 | 608 | }
|
598 | 609 | document.recorded_actions.pop();
|
599 | 610 | child_sep = ' > ';
|
600 | 611 | child_count = ssOccurrences(selector, child_sep);
|
601 |
| - if ((tag_name === "a" && !element.hasAttribute('onclick') && |
| 612 | + if ((tag_name === "a" && !el.hasAttribute('onclick') && |
602 | 613 | child_count > 0 && href.length > 0) ||
|
603 | 614 | (parent_tag_name === "a" && href.length > 0 &&
|
604 |
| - child_count > 1 && !parent_element.hasAttribute('onclick')) || |
| 615 | + child_count > 1 && !parent_el.hasAttribute('onclick')) || |
605 | 616 | (grand_tag_name === "a" && href.length > 0 &&
|
606 |
| - child_count > 2 && !grand_element.hasAttribute('onclick'))) |
| 617 | + child_count > 2 && !grand_el.hasAttribute('onclick'))) |
607 | 618 | {
|
608 | 619 | w_orig = window.location.origin;
|
609 | 620 | if (origin === w_orig)
|
|
614 | 625 | else
|
615 | 626 | document.recorded_actions.push(['click', selector, href, d_now]);
|
616 | 627 | // hover_click() if dropdown.
|
617 |
| - if (element.parentElement.classList.contains('dropdown-content') && |
618 |
| - element.parentElement.parentElement.classList.contains('dropdown')) |
| 628 | + if (el.parentElement.classList.contains('dropdown-content') && |
| 629 | + el.parentElement.parentElement.classList.contains('dropdown')) |
619 | 630 | {
|
620 | 631 | ch_s = selector;
|
621 |
| - pa_el = element.parentElement.parentElement; |
| 632 | + pa_el = el.parentElement.parentElement; |
622 | 633 | pa_s = getBestSelector(pa_el);
|
623 | 634 | if (pa_el.childElementCount >= 2 &&
|
624 | 635 | !pa_el.firstElementChild.classList.contains('dropdown-content'))
|
|
649 | 660 | document.body.addEventListener('contextmenu', function (event) {
|
650 | 661 | reset_if_recorder_undefined();
|
651 | 662 | if (sessionStorage.getItem('pause_recorder') === 'yes') return;
|
652 |
| - const element = event.target; |
653 |
| - const selector = getBestSelector(element); |
| 663 | + const el = event.target; |
| 664 | + const selector = getBestSelector(el); |
654 | 665 | ra_len = document.recorded_actions.length;
|
655 | 666 | if (ra_len > 0 &&
|
656 | 667 | document.recorded_actions[ra_len-1][0] === 'mo_dn' &&
|
|
714 | 725 | // After controls for switching modes.
|
715 | 726 | if (sessionStorage.getItem('pause_recorder') === 'yes') return;
|
716 | 727 | const d_now = Date.now();
|
717 |
| - const element = event.target; |
718 |
| - const selector = getBestSelector(element); |
| 728 | + const el = event.target; |
| 729 | + const selector = getBestSelector(el); |
719 | 730 | skip_input = false;
|
720 |
| - if ((tagName(element) === 'input' && |
721 |
| - element.type !== 'checkbox' && element.type !== 'range') || |
722 |
| - tagName(element) === 'textarea') |
| 731 | + if ((tagName(el) === 'input' && |
| 732 | + el.type !== 'checkbox' && el.type !== 'range') || |
| 733 | + tagName(el) === 'textarea') |
723 | 734 | {
|
724 | 735 | ra_len = document.recorded_actions.length;
|
725 | 736 | if (ra_len > 0 && l_key === 'enter' &&
|
|
755 | 766 | }
|
756 | 767 | if (!skip_input) {
|
757 | 768 | document.recorded_actions.push(
|
758 |
| - ['input', selector, element.value, d_now]); |
| 769 | + ['input', selector, el.value, d_now]); |
759 | 770 | }
|
760 | 771 | }
|
761 | 772 | json_rec_act = JSON.stringify(document.recorded_actions);
|
|
0 commit comments