Skip to content

Commit

Permalink
Join the selectors and call querySelectorAll only once
Browse files Browse the repository at this point in the history
  • Loading branch information
mikokm authored and maxxcrawford committed Oct 25, 2019
1 parent 86dc645 commit fae4562
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,20 +473,20 @@ const facebookDetectedElementsArr = [];

function patternDetection(selectionArray, socialActionIntent){
// console.log("patternDetection");
for (let querySelector of selectionArray) {
for (let item of document.querySelectorAll(querySelector)) {
// overlay the FBC icon badge on the item
if (!item.classList.contains("fbc-has-badge") && !isPinterest(item) && !parentIsBadged(item)) {
// console.log([querySelector, item]);
const itemUIDClassName = "fbc-UID_" + (facebookDetectedElementsArr.length + 1);
const itemUIDClassTarget = "js-" + itemUIDClassName;
const socialAction = socialActionIntent;
facebookDetectedElementsArr.push(itemUIDClassName);
addFacebookBadge(item, itemUIDClassTarget, socialAction);
item.classList.add("fbc-has-badge");
item.classList.add(itemUIDClassName);
// console.log(itemUIDClassName);
}
let querySelector = selectionArray.join(",");

for (let item of document.querySelectorAll(querySelector)) {
// overlay the FBC icon badge on the item
if (!item.classList.contains("fbc-has-badge") && !isPinterest(item) && !parentIsBadged(item)) {
// console.log([querySelector, item]);
const itemUIDClassName = "fbc-UID_" + (facebookDetectedElementsArr.length + 1);
const itemUIDClassTarget = "js-" + itemUIDClassName;
const socialAction = socialActionIntent;
facebookDetectedElementsArr.push(itemUIDClassName);
addFacebookBadge(item, itemUIDClassTarget, socialAction);
item.classList.add("fbc-has-badge");
item.classList.add(itemUIDClassName);
// console.log(itemUIDClassName);
}
}
}
Expand Down

0 comments on commit fae4562

Please sign in to comment.