How to use element-ready - 10 common examples

To help you get started, we’ve selected a few element-ready examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / refined-github / source / features / deprioritize-marketplace-link.tsx View on Github external
async function init(): Promise {
	const marketPlaceLink = (await elementReady('.Header-link[href="/marketplace"]'));
	if (marketPlaceLink) {
		// The Marketplace link seems to have an additional wrapper that other links don't have https://i.imgur.com/KV9rtSq.png
		marketPlaceLink.closest('.border-top, .mr-3')!.remove();
	}

	await domLoaded;

	select.last('.header-nav-current-user ~ .dropdown-divider')!.before(
		<div></div>,
		<a href="/marketplace">Marketplace</a>
	);
}
github refined-bitbucket / refined-bitbucket / src / pullrequest-template / pullrequest-template.js View on Github external
export async function insertPullrequestTemplate(template: string) {
    const defaultEditor = elementReady('textarea[id="id_description"]')
    const atlassianEditor = elementReady(
        '#ak_editor_description div[contenteditable="true"]'
    )
    const editorPromises = [defaultEditor, atlassianEditor]
    const editor = await Promise.race(editorPromises)
    // $FlowIgnore Resolve when `element-ready` libdefs have `p-cancelable` libdefs
    editorPromises.forEach(p => requestAnimationFrame(() => p.cancel()))

    if (editor instanceof HTMLTextAreaElement) {
        editor.value = template
    } else if (editor instanceof HTMLDivElement) {
        const html = marked(template)
        editor.innerHTML = html
    } else {
        console.warn(
            'refined-bitbucket(pullrequest-template): Could not find pull request editor.'
        )
github refined-bitbucket / refined-bitbucket / src / pullrequest-template / pullrequest-template.js View on Github external
export async function insertPullrequestTemplate(template: string) {
    const defaultEditor = elementReady('textarea[id="id_description"]')
    const atlassianEditor = elementReady(
        '#ak_editor_description div[contenteditable="true"]'
    )
    const editorPromises = [defaultEditor, atlassianEditor]
    const editor = await Promise.race(editorPromises)
    // $FlowIgnore Resolve when `element-ready` libdefs have `p-cancelable` libdefs
    editorPromises.forEach(p => requestAnimationFrame(() => p.cancel()))

    if (editor instanceof HTMLTextAreaElement) {
        editor.value = template
    } else if (editor instanceof HTMLDivElement) {
        const html = marked(template)
        editor.innerHTML = html
    } else {
        console.warn(
            'refined-bitbucket(pullrequest-template): Could not find pull request editor.'
github fregante / github-clean-feed / src / content.js View on Github external
async function init() {
	[options] = await Promise.all([
		new OptSync().getAll(),
		elementReady('.ajax-pagination-form')
	]);

	apply($('.account-switcher + *') || $('.news.column &gt; :first-child'));

	const pages = [];

	// Prefetch all pages in parallel
	for (let i = 0; i &lt; options.preloadPagesCount; i++) {
		pages.push(requestPage(i + 2));
	}

	// Append pages in series
	// uses the same method used by GitHub
	for (const page of pages) {
		// eslint-disable-next-line no-await-in-loop
		const updates = await page;
github refined-bitbucket / refined-bitbucket / src / pullrequest-commit-amount / pullrequest-commit-amount.js View on Github external
export default async function pullrequestCommitAmount() {
    const prNode = await elementReady('#pullrequest')
    const prId = prNode.dataset.localId

    const pullrequestCommits = await api.getPullrequestCommits(prId)

    // eslint-disable-next-line eqeqeq, no-eq-null
    if (pullrequestCommits &amp;&amp; pullrequestCommits.size != null) {
        const badge = (
            <span class="__rbb-commit-ammount">{pullrequestCommits.size}</span>
        )
        const commitsLink: HTMLElement = (document.getElementById(
            'pr-menu-commits'
        ): any)
        commitsLink.appendChild(badge)
    }

    return prNode
github sindresorhus / refined-github / source / features / trending-menu-item.tsx View on Github external
async function init(): Promise {
	const exploreLink = await elementReady('.Header-link[href="/explore"]');
	if (!exploreLink) {
		return false;
	}

	exploreLink.before(
		<a data-hotkey="g t" href="/trending">Trending</a>
	);
}
github sindresorhus / refined-github / source / features / linkify-branch-references.tsx View on Github external
async function init(): Promise {
	const element = await elementReady('.branch-name');
	if (element) {
		const branchUrl = `/${getRepoURL()}/tree/${element.textContent!}`;
		wrap(element.closest('.branch-name')!, <a href="{branchUrl}"></a>);
	}
}
github fanfoujs / space-fanfou / src / features / remove-brackets / @content.js View on Github external
async function removeBrackets(selector) {
  const found = await elementReady(selector)
  if (!found) return

  for (const element of select.all(selector)) {
    const html = element.innerHTML

    if (html.startsWith('(')) {
      element.innerHTML = html.replace(/^\(|\)$/g, '')
    }
  }
}
github ESWAT / voidview / src / renderer / index.js View on Github external
async function transitionToGrid () {
  const promise = await elementReady('.list')

  if (promise) {
    let jsLoader = document.querySelector('.js-loader')
    jsLoader.classList.add('has-loaded')
    jsLoader.addEventListener('animationend', () => {
      jsLoader.remove()
      jsLoader = null
    }, { once: true })
  }
}
github fanfoujs / space-fanfou / src / features / remove-personalized-theme / @content.js View on Github external
async function extractUserIdFromMeta() {
    const meta = await elementReady('meta[name="author"]')

    if (meta) {
      const rawValue = meta.getAttribute('content')

      return rawValue.match(/\((.+)\)$/)[1]
    }
  }

element-ready

Detect when an element is ready in the DOM

MIT
Latest version published 5 months ago

Package Health Score

72 / 100
Full package analysis

Popular element-ready functions