html-editor it's a tool for helping modification html elements
npm install @plohoj/html-editorhtml-editor it's a set of tools that helps find and modify HTML elements in the Rx stream. Useful for browser extensions and userscripts.observeElementMutationobserveQuerySelectorobserveQuerySelectorAllawaitElementawaitRandomElementurlChange$observeUrlChangesmergeMapAddedElementsmergeMapStringConditionobserveElementMutationExample:
``ts`
observeElementMutation(
document.querySelector('#my-element')!,
{ attributeFilter: ['data-my-data'] },
).subscribe(console.log);
Example:
`ts`
observeQuerySelector({
query: '.my-child',
parent: document.querySelector('#my-parent')!,
has: '.my-sub-child',
filter: element => element.classList.contains('.my-child-modifier'),
}).subscribe(console.log);`
Example log:ts`
{added: Element, target: Element, removed: undefined};
{added: undefined, target: undefined, removed: Element};
Example:
`ts`
observeQuerySelectorAll({
query: '.my-child',
parent: document.querySelector('#my-parent')!,
has: '.my-sub-child',
filter: element => element.classList.contains('.my-child-modifier'),
}).subscribe(console.log);`
Example log:ts`
{added: [Element], target: [Element, Element], removed: []};
{added: [], target: [Element], removed: [Element]};
Example:
`ts`
awaitElement('#my-element')
.subscribe(console.log);
Example:
`ts`
awaitRandomElement('.my-element')
.subscribe(console.log);
Example:
`ts`
urlChange$.subscribe(console.log);
changes that satisfy the conditions.Example:
`ts
observeUrlChanges({ condition: /my-url-segment/ })
.subscribe(console.log);
` Operators
mergeMapAddedElements
Conversion operator to a new stream for each new added element.Example:
`ts
observeQuerySelectorAll('.my-button').pipe(
mergeMapAddedElements(element => fromEvent(element, 'click'))
).subscribe(console.log);
`
It can be more convenient to use the project option in observeQuerySelector and observeQuerySelectorAll functions. Example:
`ts
observeQuerySelectorAll({
query: '.my-button',
project: element => fromEvent(element, 'click'),
}).subscribe(console.log);
`
mergeMapStringCondition
The operator creates a separate stream when the source string is validated.Example:
`ts
urlChange$.pipe(
mergeMapStringCondition(
/my-url-segment/,
() => observeQuerySelectorAll('.my-element'),
)
).subscribe(console.log);
`
It can be more convenient to use the project option in observeUrlChanges function. Example:
`ts
observeUrlChanges({
condition: /my-url-segment/,
project: () => observeQuerySelectorAll('.my-element')
}).subscribe(console.log);
``