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

Commit

Permalink
Improve script
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoColomb committed Jan 7, 2020
1 parent 3587329 commit 75e574f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions source/background.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'webext-dynamic-content-scripts'
import localforage from 'localforage'
import { isEmpty } from './libs/utils'
import { renderBadge } from './libs/browser'
Expand Down
5 changes: 4 additions & 1 deletion source/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@
color: #edb200 !important;
}

/* close button */
.qui-possede-les-medias-button {
cursor: pointer;
background: none !important;
color: white !important;
border: none !important;
float: right !important;
float: left !important;
margin: -1.5em !important;
font-size: 1em;
}
3 changes: 1 addition & 2 deletions source/content.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'webext-dynamic-content-scripts'
import select from 'select-dom'
import elementReady from 'element-ready'

Expand Down Expand Up @@ -27,7 +26,7 @@ async function init () {

const button = document.createElement('button')
button.className = 'qui-possede-les-medias-button'
button.innerHTML = ''
button.innerHTML = '×'
button.addEventListener('click', (e) => e.currentTarget.parentNode.remove())
box.appendChild(button)

Expand Down
2 changes: 1 addition & 1 deletion source/libs/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const queryPermission = async (permission) => {

export const requestPermission = async (permission) => {
try {
return browser.permissions.request({permissions: [permission]})
return browser.permissions.request({origins: [permission]})
} catch (error) {
console.log(error)
return false
Expand Down
15 changes: 5 additions & 10 deletions source/libs/utils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
export const isEmpty = variable => (!variable || variable.length === 0 || Object.getOwnPropertyNames(variable).length === 0)

export const renderData = (data) => [
renderPlural(data.filter(entity => entity.type === 'group'), 'du groupe', 'des groupes'),
renderPlural(data.filter(entity => entity.type === 'holder'), 'appartient à', 'appartient à'),
].join(' ')

export const renderPlural = (data, preSingular, prePlural) => {
export const renderPlural = (data) => {
if (data.length < 1) {
return null
}
Expand All @@ -14,14 +9,14 @@ export const renderPlural = (data, preSingular, prePlural) => {
: entity.name
)
if (data.length === 1) {
return `${preSingular} ${data.pop()}`
return data.pop()
}
if (typeof Intl !== 'undefined' && Intl.ListFormat) {
const lf = new Intl.ListFormat('fr')
return `${prePlural} ${lf.format(data)}`
return lf.format(data)
}
const last = data.pop()
return prePlural + ' ' + [
return [
data.join(', '),
last
].join(' et ')
Expand All @@ -30,6 +25,6 @@ export const renderPlural = (data, preSingular, prePlural) => {
export const renderText = (data) => {
const text = document.createElement('p')
text.className = 'qui-possede-les-medias-text'
text.innerHTML = `Ce média ${renderData(data)}.`
text.innerHTML = `Ce média appartient à ${renderPlural(data)}.`
return text
}

0 comments on commit 75e574f

Please sign in to comment.