Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Refactor renderText
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoColomb committed Mar 3, 2019
1 parent 35bcb65 commit 2142f71
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
7 changes: 2 additions & 5 deletions source/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'webext-dynamic-content-scripts'
import select from 'select-dom'

import { safeElementReady } from './libs/document'
import { isEmpty, renderData } from './libs/utils'
import {isEmpty, renderText} from './libs/utils'

// Add globals for easier debugging
window.select = select
Expand All @@ -29,10 +29,7 @@ async function init () {
button.addEventListener('click', (e) => e.currentTarget.parentNode.remove())
box.appendChild(button)

const text = document.createElement('p')
text.className = 'qui-possede-les-medias-text'
text.innerHTML = `Ce média ${renderData(boxData)}.`
box.appendChild(text)
box.appendChild(renderText(boxData))

select('body').append(box)
}
Expand Down
7 changes: 7 additions & 0 deletions source/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ export const renderPlural = (data, preSingular, prePlural) => {
last
].join(' et ')
}

export const renderText = (data) => {
const text = document.createElement('p')
text.className = 'qui-possede-les-medias-text'
text.innerHTML = `Ce média ${renderData(data)}.`
return text
}
7 changes: 2 additions & 5 deletions source/popup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isEmpty, renderData } from './libs/utils'
import { isEmpty, renderText } from './libs/utils'

async function init () {
const tabs = await browser.tabs.query({
Expand All @@ -18,10 +18,7 @@ async function init () {
const box = document.createElement('div')
box.className = 'qui-possede-les-medias-box'

const text = document.createElement('p')
text.className = 'qui-possede-les-medias-text'
text.innerHTML = `Ce média ${renderData(boxData)}.`
box.appendChild(text)
box.appendChild(renderText(boxData))

document.querySelector('body').append(box)
}
Expand Down

0 comments on commit 2142f71

Please sign in to comment.