diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ef8a34a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 + +[*.js] +indent_style = space +indent_size = 4 + +# 4 space indentation +[*.html] +indent_style = space +indent_size = 2 diff --git a/options.js b/options.js index ff6c3f2..6eb6559 100644 --- a/options.js +++ b/options.js @@ -1,58 +1,58 @@ const PATTERN_ROW = (addr, pattern) => ` - - + + `; function defaultPatterns() { - return [ - { server: '', pattern: '.*' }, - ]; + return [ + { server: '', pattern: '.*' }, + ]; } function setPatterns(patterns) { - if (!patterns || patterns.length === 0) { - patterns = defaultPatterns(); - } + if (!patterns || patterns.length === 0) { + patterns = defaultPatterns(); + } - console.log('PATTERNS', patterns); + console.log('PATTERNS', patterns); - var reducer = (acc, item) => acc + PATTERN_ROW(item.server, item.pattern); + var reducer = (acc, item) => acc + PATTERN_ROW(item.server, item.pattern); - var html = patterns.reduce(reducer, ''); + var html = patterns.reduce(reducer, ''); - document.querySelector(".js-pattern-rows").innerHTML = html; + document.querySelector(".js-pattern-rows").innerHTML = html; } function restoreOptions() { - PatternStorage.get().then( - setPatterns, - (error) => { - console.log(`Error: ${error}`) - } - ); + PatternStorage.get().then( + setPatterns, + (error) => { + console.log(`Error: ${error}`) + } + ); } function saveOptions(evt) { - evt.preventDefault(); - var patterns = []; - var rows = document.querySelectorAll(".js-pattern-rows tr"); - rows.forEach(row => { - var server = row.querySelector('[name="server"]').value; - var pattern = row.querySelector('[name="pattern"]').value; - if (server) { - patterns.push({server: server, pattern: pattern}); - } - }); + evt.preventDefault(); + var patterns = []; + var rows = document.querySelectorAll(".js-pattern-rows tr"); + rows.forEach(row => { + var server = row.querySelector('[name="server"]').value; + var pattern = row.querySelector('[name="pattern"]').value; + if (server) { + patterns.push({server: server, pattern: pattern}); + } + }); - PatternStorage.set(patterns); + PatternStorage.set(patterns); } function addRow(evt) { - evt.preventDefault(); - var el = document.querySelector(".js-pattern-rows"); - el.innerHTML += PATTERN_ROW('', ''); + evt.preventDefault(); + var el = document.querySelector(".js-pattern-rows"); + el.innerHTML += PATTERN_ROW('', ''); } document.addEventListener("DOMContentLoaded", restoreOptions); diff --git a/postify.js b/postify.js index 49208fd..1b28c6b 100644 --- a/postify.js +++ b/postify.js @@ -2,29 +2,29 @@ const APP_NAME = 'Postify'; const SERVER_ADDR = 'http://127.0.0.1:9999'; function sendUrl(url) { - browser.notifications.create({ - "type": "basic", - "iconUrl": browser.extension.getURL("icons/postify-48.png"), - "title": APP_NAME, - "message": url, - }); + browser.notifications.create({ + "type": "basic", + "iconUrl": browser.extension.getURL("icons/postify-48.png"), + "title": APP_NAME, + "message": url, + }); - fetch(SERVER_ADDR, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - url: url - }) - }); + fetch(SERVER_ADDR, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + url: url + }) + }); } function sendCurrentUrl(args) { - if (args.url) { - sendUrl(args.url) - } + if (args.url) { + sendUrl(args.url) + } } browser.browserAction.onClicked.addListener(sendCurrentUrl); diff --git a/storage.js b/storage.js index 6a7f487..7529bbf 100644 --- a/storage.js +++ b/storage.js @@ -1,24 +1,24 @@ function PropertyStorage(name) { - parse = function (data) { - var propertyData = data[name]; - if (!propertyData) { - return null; - } - try { - return JSON.parse(propertyData); - } catch (e) { - return null; - } - }; + parse = function (data) { + var propertyData = data[name]; + if (!propertyData) { + return null; + } + try { + return JSON.parse(propertyData); + } catch (e) { + return null; + } + }; - this.get = function () { - var getting = browser.storage.local.get(name); - return getting.then(parse); - }; + this.get = function () { + var getting = browser.storage.local.get(name); + return getting.then(parse); + }; - this.set = function (value) { - return browser.storage.local.set({ patterns: JSON.stringify(value) }); - }; + this.set = function (value) { + return browser.storage.local.set({ patterns: JSON.stringify(value) }); + }; } PatternStorage = new PropertyStorage('patterns');