Skip to content

Commit

Permalink
update yarn.lock, imporve namings, fix observe helper
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Jun 1, 2023
1 parent 8f42de7 commit f0f69d9
Show file tree
Hide file tree
Showing 6 changed files with 1,591 additions and 1,884 deletions.
2 changes: 1 addition & 1 deletion src/helpers/node-text-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { toRegExp } from './string-utils';
* @param {string} selector CSS selector to find nodes by
* @param {Function} handler handler to pass nodes to
*/
export const handleEarlyNodes = (selector, handler) => {
export const handleExistingNodes = (selector, handler) => {
const nodeList = document.querySelectorAll(selector);
const nodes = nodeListToArray(nodeList);
handler(nodes);
Expand Down
8 changes: 6 additions & 2 deletions src/helpers/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ export const getAddedNodes = (mutations) => {
* @param {Object} options MutationObserver options
* @param {number|null} timeout Disconnect timeout in ms
*/
export const observeDocument = (callback, options, timeout = 10000) => {
const observer = new MutationObserver(callback);
export const observeDocumentWithTimeout = (callback, options, timeout = 10000) => {
const observer = new MutationObserver((mutations, observer) => {
observer.disconnect();
callback(mutations);
observer.observe(document.documentElement, options);
});
observer.observe(document.documentElement, options);

if (typeof timeout === 'number') {
Expand Down
10 changes: 5 additions & 5 deletions src/redirects/redirects-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export * from './fingerprintjs2';
export * from './fingerprintjs3';
export * from './gemius';
export * from './ati-smarttag';
export * from './prevent-bab2.js';
export * from './prevent-bab2';
export * from './google-ima3';
export * from './didomi-loader.js';
export * from './prebid.js';
export * from './prebid-ads.js';
export * from './naver-wcslog.js';
export * from './didomi-loader';
export * from './prebid';
export * from './prebid-ads';
export * from './naver-wcslog';
12 changes: 6 additions & 6 deletions src/scriptlets/remove-node-text.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
observeDocument,
handleEarlyNodes,
observeDocumentWithTimeout,
handleExistingNodes,
handleMutations,
replaceNodeText,
isTargetNode,
Expand Down Expand Up @@ -98,11 +98,11 @@ export function removeNodeText(source, nodeName, textMatch) {

// Apply dedicated handler to already rendered nodes...
if (document.documentElement) {
handleEarlyNodes(selector, handleNodes);
handleExistingNodes(selector, handleNodes);
}

// and newly added nodes
observeDocument((mutations) => handleMutations(mutations, handleNodes), {
observeDocumentWithTimeout((mutations) => handleMutations(mutations, handleNodes), {
childList: true,
subtree: true,
});
Expand All @@ -116,8 +116,8 @@ removeNodeText.names = [
];

removeNodeText.injections = [
observeDocument,
handleEarlyNodes,
observeDocumentWithTimeout,
handleExistingNodes,
handleMutations,
replaceNodeText,
isTargetNode,
Expand Down
12 changes: 6 additions & 6 deletions src/scriptlets/trusted-replace-node-text.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
observeDocument,
handleEarlyNodes,
observeDocumentWithTimeout,
handleExistingNodes,
handleMutations,
replaceNodeText,
isTargetNode,
Expand Down Expand Up @@ -120,11 +120,11 @@ export function trustedReplaceNodeText(source, nodeName, textMatch, pattern, rep

// Apply dedicated handler to already rendered nodes...
if (document.documentElement) {
handleEarlyNodes(selector, handleNodes);
handleExistingNodes(selector, handleNodes);
}

// and newly added nodes
observeDocument((mutations) => handleMutations(mutations, handleNodes), {
observeDocumentWithTimeout((mutations) => handleMutations(mutations, handleNodes), {
childList: true,
subtree: true,
});
Expand All @@ -139,8 +139,8 @@ trustedReplaceNodeText.names = [
];

trustedReplaceNodeText.injections = [
observeDocument,
handleEarlyNodes,
observeDocumentWithTimeout,
handleExistingNodes,
handleMutations,
replaceNodeText,
isTargetNode,
Expand Down
Loading

0 comments on commit f0f69d9

Please sign in to comment.