1.0.0 • Published 2 years ago

@rakot/injir v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

⭐️ Features

Library for assist injecting content into different sites with browser extension. It allows using configs for parsing containers / content and pull them from external sources.

📦 Getting Started

Include injir.js

const inst = new Injir({
    container: '.wrapper .row'
}, (result) => {console.log(result);});

💎 Customization

Config description

KeyTypeDefaultDescription
containerstringnone (req)Any jQuery supported selector
pollInTimeoutintundefinedIf need to poll for element, instead of running once
overwriteCheckerobjectundefinedSometimes site overwrites elements, it can erase injected content, you can pass jQuery selector or function to check, was injected content removed and need to re-run worker
alreadyCapturedobject{type: 'data', name: 'injir-captured', value: 'yes'}If you are using pollInTimeout, you need to mark container already captured by instance. By default it will add data attribute to container, but you can customize it
dataToParsearrayundefindedIf your worker needs to have some data parsed inside the container, you can define it. It should be array of objects.

Examples

overwriteChecker:

overwriteChecker: {
    selector: '.injected-content',
    parseData: true,
    mutationObserver: {
        attributes: false
    },
    timeout: 1000
}

alreadyCaptured:

alreadyCaptured: {type: 'data', name: 'injir-captured', value: 'yes'}

or

alreadyCaptured: {type: 'class', value: 'injir-captured'}

or

alreadyCaptured: {type: 'content', value: '.injir-captured'}

dataToParse:

dataToParse: [
    {
        key: 'price',
        container: '.product_price_sale, .product_price_original',
        textFilter: {
            textNode: {
                position: 'LAST',                
            },
            separator: {
                separator: 'SPACE',
                position: 'FIRST',
            }
            replaceFix: [
                {
                    from: '. ',
                    to: '.'
                }
            ],
        }
    }
]