diff --git a/src/components/Utils.js b/src/components/Utils.js index d788a2c..57dc2d3 100644 --- a/src/components/Utils.js +++ b/src/components/Utils.js @@ -1,3 +1,6 @@ +/** + * + */ export function logAndReturn(e) { console.warn(e) return e @@ -18,11 +21,7 @@ export class XHR { } static fetch(url, options) { - return window - .fetch(url, options) - .then(XHR.checkStatus) - .then(XHR.parseJSON) - .catch(logAndReturn) + return window.fetch(url, options).then(XHR.checkStatus).then(XHR.parseJSON).catch(logAndReturn) } } @@ -53,26 +52,18 @@ class Storage { set(key, value) { return this.promise((resolve, reject) => - chrome.storage[this.STORAGE].set({ [key]: value }, data => - Storage.check(data, resolve, reject) - ) + chrome.storage[this.STORAGE].set({ [key]: value }, data => Storage.check(data, resolve, reject)) ) } get(key, defaultValue) { return this.promise((resolve, reject) => - chrome.storage[this.STORAGE].get({ [key]: defaultValue }, data => - Storage.check(data[key], resolve, reject) - ) + chrome.storage[this.STORAGE].get({ [key]: defaultValue }, data => Storage.check(data[key], resolve, reject)) ) } remove(key) { - return this.promise((resolve, reject) => - chrome.storage[this.STORAGE].remove(key, data => - Storage.check(data, resolve, reject) - ) - ) + return this.promise((resolve, reject) => chrome.storage[this.STORAGE].remove(key, data => Storage.check(data, resolve, reject))) } static check(data, resolve, reject) { @@ -94,11 +85,7 @@ export class Chrome { index = search.indexOf('tabid') if (index !== -1) { console.log('sending req', action, additional) - chrome.tabs.sendMessage( - +search[index + 1], - { action, ...additional }, - null - ) + chrome.tabs.sendMessage(+search[index + 1], { action, ...additional }, null) return true } return false @@ -112,11 +99,17 @@ export class Chrome { export const i18n = Chrome.i18n //const regex = /-fr[atx]\d-\d/ +/** + * + */ export function updateCDN(url) { return url // return url.replace(regex, '-frt3-1') // 10.08.2017 } +/** + * + */ export function shallowDiffers(a, b) { for (const key in a) if (a[key] !== b[key]) return true for (const key in b) if (!(key in a)) return true @@ -136,24 +129,23 @@ self.addEventListener('message', event => { }) ` +/** + * + */ export function documentReady() { return new Promise((resolve, reject) => { - if ( - document.readyState === 'interactive' || - document.readyState === 'complete' - ) - resolve() + if (document.readyState === 'interactive' || document.readyState === 'complete') resolve() else document.addEventListener('DOMContentLoaded', resolve) }) } let workerBlob +/** + * + */ export async function getWorkerBlob() { await documentReady() // creating a blob is synchronous and takes around 120ms on a powerful machine - if (workerBlob === undefined) - workerBlob = URL.createObjectURL( - new Blob([webWorkerScript], { type: 'application/javascript' }) - ) + if (workerBlob === undefined) workerBlob = URL.createObjectURL(new Blob([webWorkerScript], { type: 'application/javascript' })) return workerBlob } @@ -164,14 +156,8 @@ const formReducer = (data, element) => { else if (type === 'checkbox') // option data[element.name] = element.checked - else if (type.indexOf('select') !== -1) - data[element.name] = [].reduce.call(element.options, formReducer, []) - else if ( - type === 'button' || - element.name.indexOf('_add') !== -1 || - type === 'submit' - ) - undefined + else if (type.indexOf('select') !== -1) data[element.name] = [].reduce.call(element.options, formReducer, []) + else if (type === 'button' || element.name.indexOf('_add') !== -1 || type === 'submit') undefined else if (type === 'number') data[element.name] = +element.value else data[element.name] = element.value // number, text, etc @@ -222,3 +208,11 @@ export function debounce(fn, delay) { inDebounce = setTimeout(() => fn.apply(this, args), delay) } } + +/** + * + */ +export function markAtsAndHashtags(text) { + const ats = text.replace(/(\s)@([\w-]+)/g, '$1@$2') + return ats.replace(/(\s)#([\w-]+)/g, '$1@$2') +} diff --git a/src/components/feed/Comments.js b/src/components/feed/Comments.js index d93f580..d2e8755 100644 --- a/src/components/feed/Comments.js +++ b/src/components/feed/Comments.js @@ -1,6 +1,7 @@ import Heart from './Heart' import PropTypes from 'prop-types' import { Component, h } from 'preact' +import { markAtsAndHashtags } from '../Utils' const Comments = props => (