Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #50 from rationalthinker1/feature-32
Browse files Browse the repository at this point in the history
feature(prefer-id-selector)
  • Loading branch information
tnolet authored May 31, 2019
2 parents cc87dd8 + 1cc71a7 commit 56f6ae4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/content-scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class EventRecorder {
this.isTopFrame = (window.location === window.parent.location)
}

start () {
boot () {
// We need to check the existence of chrome for testing purposes
if (chrome.storage && chrome.storage.local) {
chrome.storage.local.get(['options'], ({options}) => {
Expand Down Expand Up @@ -72,9 +72,10 @@ class EventRecorder {
// we explicitly catch any errors and swallow them, as none node-type events are also ingested.
// for these events we cannot generate selectors, which is OK
try {
const optimizedMinLength = (e.target.id) ? 2 : 10 // if the target has an id, use that instead of multiple other selectors
const selector = this.dataAttribute && e.target.hasAttribute && e.target.hasAttribute(this.dataAttribute)
? formatDataSelector(e.target, this.dataAttribute)
: finder(e.target, {seedMinLength: 5, optimizedMinLength: 10})
: finder(e.target, {seedMinLength: 5, optimizedMinLength: optimizedMinLength})

const msg = {
selector: selector,
Expand Down Expand Up @@ -113,4 +114,4 @@ function formatDataSelector (element, attribute) {
}

window.eventRecorder = new EventRecorder()
window.eventRecorder.start()
window.eventRecorder.boot()

0 comments on commit 56f6ae4

Please sign in to comment.