commit adb84ffd71bfa549175a23aa56d56340807a29d5 Author: s2 Date: Mon Mar 18 14:42:14 2019 +0100 initial draft diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ac287db --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# Editor configuration, see http://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = tab +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true +end_of_line = lf + +[*.md] +max_line_length = off +trim_trailing_whitespace = false diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..0e3fca7 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +node_modules +thirdparty +app/* +!app/js diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..9b91def --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,36 @@ +{"parserOptions": + { + "ecmaVersion": 6, + "sourceType": "module" + }, + "rules": { + "quotes": [2, "single", {"allowTemplateLiterals": true}], + "curly": [2, "all"], + "keyword-spacing": [2, {"overrides": {"else": {"before": true}, "catch": {"before": true, "after": false}}}], + "space-before-blocks": [2, "always"], + "wrap-iife": [2, "inside"], + "space-before-function-paren": [2, "never"], + "one-var": [2, "never"], + "vars-on-top": 0, "no-empty": [2, {"allowEmptyCatch": true}], + "array-bracket-spacing": [2, "never"], + "space-in-parens": [2, "never"], + "no-underscore-dangle": 0, + "comma-style": [2, "last"], + "comma-spacing": [2, {"before": false, "after": true}], + "space-unary-ops": [2, {"words": false, "nonwords": false}], + "no-multi-spaces": 2, + "space-infix-ops": 2, + "no-with": 2, + "indent": [2, "tab", {"SwitchCase": 1, "FunctionExpression": {"body": 1, "parameters": 1}, "MemberExpression": 0}], + "no-mixed-spaces-and-tabs": 2, + "no-trailing-spaces": 2, + "comma-dangle": [2, "never"], + "semi": [2, "always"], + "brace-style": [2, "1tbs", {"allowSingleLine": true}], + "eol-last": 2, + "dot-notation": 0, + "no-multi-str": 2, + "key-spacing": [2, {"afterColon": true}], + "func-call-spacing": [2, "never"] + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8fe4fa --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.project diff --git a/README.md b/README.md new file mode 100644 index 0000000..87f659e --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# ping + +## What it does + +A firefox addon that pings a server you configure, and shows an icon for up status, and a different icon for down status. + +## install + +On amo! +[https://addons.mozilla.org/firefox/addon/ping/](https://addons.mozilla.org/firefox/addon/ping/) + + +## develop + +Clone this repo, open firefox on [about:debugging](about:debugging) and load the extension by selecting the cloned folder. +Start coding! + +## make a release + +zip the src folder and upload to https://addons.mozilla.org/ diff --git a/src/background-page.html b/src/background-page.html new file mode 100644 index 0000000..c6bd27c --- /dev/null +++ b/src/background-page.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/background-pinger.js b/src/background-pinger.js new file mode 100644 index 0000000..7ec7a72 --- /dev/null +++ b/src/background-pinger.js @@ -0,0 +1,34 @@ +import { loadOptions } from './utils.js'; + +let options = {}; + +function ping(server) { + console.log('pinging ' + server); +} + +function reloadConfig() { + loadOptions().then((savedOptions) => { + options.server = savedOptions.server; + options.interval = savedOptions.interval; + + if (options.server && options.interval >= 1) { + ping(options.server); + + if (options.pinger) { + clearInterval(options.pinger); + } + options.pinger = setInterval(function() { + ping(options.server); + }, options.interval * 1000); + } + }); +} + +browser.runtime.onMessage.addListener(function(request, sender, sendResponse) { + if (request === 'configChanged') { + reloadConfig(); + } +}); + +//startup +reloadConfig(); diff --git a/src/icons/available-32.png b/src/icons/available-32.png new file mode 100644 index 0000000..6f0026d Binary files /dev/null and b/src/icons/available-32.png differ diff --git a/src/icons/available-48.png b/src/icons/available-48.png new file mode 100644 index 0000000..e6e2f0a Binary files /dev/null and b/src/icons/available-48.png differ diff --git a/src/icons/available.png b/src/icons/available.png new file mode 100644 index 0000000..dd8a0a8 Binary files /dev/null and b/src/icons/available.png differ diff --git a/src/icons/offline-32.png b/src/icons/offline-32.png new file mode 100644 index 0000000..1915118 Binary files /dev/null and b/src/icons/offline-32.png differ diff --git a/src/icons/offline-48.png b/src/icons/offline-48.png new file mode 100644 index 0000000..60f7c0f Binary files /dev/null and b/src/icons/offline-48.png differ diff --git a/src/icons/offline.png b/src/icons/offline.png new file mode 100644 index 0000000..ccf2f1a Binary files /dev/null and b/src/icons/offline.png differ diff --git a/src/manifest.json b/src/manifest.json new file mode 100644 index 0000000..05925b1 --- /dev/null +++ b/src/manifest.json @@ -0,0 +1,33 @@ +{ + "description": "Just a toolbar button that shows if a server is up or not.", + "manifest_version": 2, + "name": "ping", + "version": "1.1.23", + "homepage_url": "https://github.com/S2-/ping", + "applications": { + "gecko": { + "id": "{46b66c4d-605f-4f4d-8689-20b44b45656c}" + } + }, + "icons": { + "48": "icons/offline-48.png" + }, + "browser_action": { + "default_icon": "icons/offline-32.png", + "theme_icons": [{ + "light": "icons/offline-32-light.png", + "dark": "icons/offline-32.png", + "size": 32 + }], + "default_title": "ping", + "default_popup": "popup/ping.html" + }, + "background": { + "page": "background-page.html" + }, + "permissions": [ + "storage", + "", + "webRequest" + ] +} diff --git a/src/popup/ping.css b/src/popup/ping.css new file mode 100644 index 0000000..d520448 --- /dev/null +++ b/src/popup/ping.css @@ -0,0 +1,74 @@ +body { + margin: 15px; +} + +div { + margin-top: 5px; +} + +input[type="number"] { + -moz-appearance: none; + color: var(--in-content-text-color); + border: 1px solid var(--in-content-box-border-color); + -moz-border-top-colors: none !important; + -moz-border-right-colors: none !important; + -moz-border-bottom-colors: none !important; + -moz-border-left-colors: none !important; + border-radius: 2px; + background-color: var(--in-content-box-background); + + font-family: inherit; + font-size: inherit; + padding: 5px 10px; + + width: 50px; +} + +#length-min { + margin-right: 10px; +} + +input[type="checkbox"] { + margin-bottom: -7px; +} + +#pw { + border: 2px black solid; + width: 250px; +} + +#copy { + margin-left: 0px; +} + +#exclude { + width: 183px; +} + +.copied { + pointer-events: none; + height: 26px; + width: 100%; + background-color: #FFF8DC; + position: absolute; + padding-right: 0; + padding-left: 0; + padding-top: 5px; + padding-bottom: 5px; + text-align: center; + margin-right: -15px; + margin-left: -19px; + margin-top: -27px; +} + +.fadein { + visibility: visible; + opacity: 1; + transition: opacity 1s linear; +} + +.fadeout { + visibility: hidden; + opacity: 0; + transition: visibility 0s 1s, opacity 1s linear; +} diff --git a/src/popup/ping.html b/src/popup/ping.html new file mode 100644 index 0000000..bee8bab --- /dev/null +++ b/src/popup/ping.html @@ -0,0 +1,27 @@ + + + + + + + + + + + + +
+
+ + +
+ +
+ + +
+
+ + + + diff --git a/src/popup/ping.js b/src/popup/ping.js new file mode 100644 index 0000000..6c97ac8 --- /dev/null +++ b/src/popup/ping.js @@ -0,0 +1,26 @@ +import { loadOptions, saveOptions } from '../utils.js'; + +function getParams() { + return { + server: document.getElementById('server').value, + interval: parseInt(document.getElementById('interval').value) + }; +}; + +document.addEventListener('DOMContentLoaded', function() { + var list = document.getElementsByTagName('input'); + for (var i = 0; i < list.length; i++) { + list[i].addEventListener('change', (ev) => { + saveOptions(getParams()); + browser.runtime.sendMessage('configChanged'); + }); + } + + loadOptions().then((options) => { + document.getElementById('server').value = options.server; + document.getElementById('interval').value = options.interval; + + browser.runtime.sendMessage('configChanged'); + }); + +}); diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..f488b8d --- /dev/null +++ b/src/utils.js @@ -0,0 +1,19 @@ +function loadOptions() { + return browser.storage.local.get({ + server: '', + interval: 60 + }); +}; + +function saveOptions(options) { + return browser.storage.local.set(options); +}; + +if (typeof(window['ping'] === 'undefined')) { + window.ping = {}; +} + +export { + loadOptions, + saveOptions +};