Compare commits

...

10 Commits

Author SHA1 Message Date
a251acec86
Some fixes 2021-03-30 16:01:30 +03:00
Anton Vakhrushev
39ba18438c Fix notifications 2018-08-23 15:00:16 +03:00
Anton Vakhrushev
48ce7ac0c1 Fix parsing 2018-08-23 14:23:42 +03:00
Anton Vakhrushev
01842d265b Add editorconfig 2018-08-23 13:59:20 +03:00
Anton Vakhrushev
53c583464d Simplify code 2018-08-23 13:57:19 +03:00
Anton Vakhrushev
40fa9b9f07 Add settings 2018-08-23 13:33:47 +03:00
Anton Vakhrushev
9cfcefb1dd Add readme 2018-08-23 09:56:00 +03:00
Anton Vakhrushev
8d0cf41d73 Add test sever 2018-08-23 09:49:40 +03:00
Anton Vakhrushev
a10e24198e Add shortcut 2018-08-23 09:16:44 +03:00
Anton Vakhrushev
c5a6d8fc53 Add current url detection 2018-08-22 17:42:02 +03:00
11 changed files with 266 additions and 13 deletions

15
.editorconfig Normal file
View File

@ -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

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
./.idea
*.xpi

6
Makefile Normal file
View File

@ -0,0 +1,6 @@
build-xpi:
rm -f postify.xpi
zip -r -FS ./postify.xpi * \
--exclude '*.git*' \
--exclude '*.php' \
--exclude '*.xpi'

BIN
icons/postify-48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,26 +1,39 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Postify", "name": "Postify",
"version": "1.0", "version": "1.0.6",
"description": "Post current url to external web-server.", "description": "Post current url to external web-server.",
"icons": {
"48": "icons/postify-48.png"
},
"applications": { "applications": {
"gecko": { "gecko": {
"id": "postify@mozilla.org", "id": "postify@mozilla.org",
"strict_min_version": "45.0" "strict_min_version": "45.0"
} }
}, },
"content_scripts": [ "permissions": [
{ "activeTab",
"matches": [ "notifications",
"*://*.mozilla.org/*" "storage",
], "webRequest",
"js": [ "*://localhost/*"
"postify.js"
]
}
], ],
"background": {
"scripts": ["storage.js", "postify.js"]
},
"browser_action": { "browser_action": {
"default_icon": "icons/postify-32.png", "default_icon": "icons/postify-32.png",
"default_title": "Beastify" "default_title": "Postify"
},
"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Shift+D"
}
}
},
"options_ui": {
"page": "options.html"
} }
} }

43
options.html Normal file
View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<style type="text/css">
.left {
text-align: left;
}
</style>
<body>
<form class="js-form">
<p>
Specify servers and url patterns.
</p>
<table>
<thead>
<tr>
<th class="left">Server address</th>
<th class="left">Url pattern</th>
</tr>
</thead>
<tbody class="js-pattern-rows">
</tbody>
</table>
<button type="submit" class="js-submit">Save</button>
<button class="js-add">Add</button>
</form>
<script src="storage.js"></script>
<script src="options.js"></script>
</body>
</html>

64
options.js Normal file
View File

@ -0,0 +1,64 @@
const PATTERN_ROW = (addr, pattern) => `
<tr>
<td><input type="text" name="server" value="${addr}"></td>
<td><input type="text" name="pattern" value="${pattern}"></td>
</tr>
`;
function defaultPatterns() {
return [
{ server: '', pattern: '.*' },
];
}
function setPatterns(patterns) {
if (!patterns || patterns.length === 0) {
patterns = defaultPatterns();
}
console.log('PATTERNS', patterns);
const reducer = (acc, item) => acc + PATTERN_ROW(item.server, item.pattern);
const html = patterns.reduce(reducer, '');
document.querySelector(".js-pattern-rows").innerHTML = html;
}
function restoreOptions() {
PatternStorage.get().then(
setPatterns,
(error) => {
console.log(`Error: ${error}`)
}
);
}
function parseForm() {
const formData = [];
const rows = document.querySelectorAll(".js-pattern-rows tr");
rows.forEach(row => {
var server = row.querySelector('[name="server"]').value;
var pattern = row.querySelector('[name="pattern"]').value;
formData.push({server: server, pattern: pattern});
});
return formData;
}
function saveOptions(evt) {
evt.preventDefault();
const formData = parseForm();
const filter = item => item.server;
const patterns = formData.filter(filter);
PatternStorage.set(patterns);
}
function addRow(evt) {
evt.preventDefault();
const el = document.querySelector(".js-pattern-rows");
el.innerHTML += PATTERN_ROW('', '');
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector(".js-submit").addEventListener("click", saveOptions);
document.querySelector(".js-add").addEventListener("click", addRow);

View File

@ -1 +1,60 @@
console.log('Yeah!') const APP_NAME = 'Postify';
function sendUrlToServer(url, addr) {
console.log('Send url to server', url, addr);
return fetch(addr, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: url,
}),
});
}
function showNotification(url, addr) {
console.log('NOTIFY', url, addr);
var id = Math.random().toString(36).substr(2);
browser.notifications.create(id, {
"type": "basic",
"iconUrl": browser.extension.getURL("icons/postify-48.png"),
"title": APP_NAME,
"message": `Sent "${url}" to ${addr}.`,
});
var close = function () {
browser.notifications.clear(id);
}
setTimeout(close, 2000);
}
function sendUrlToServers(url, patterns) {
patterns.forEach(item => {
const regex = new RegExp(item.pattern || '.*', 'i');
if (regex.test(url) && item.server) {
sendUrlToServer(url, item.server).then(
() => showNotification(url, item.server),
(e) => console.log('SEND ERROR', e)
);
}
});
}
function sendUrl(url) {
PatternStorage.get().then(patterns => {
sendUrlToServers(url, patterns);
});
}
function sendCurrentUrl(args) {
if (args.url) {
sendUrl(args.url)
}
}
browser.browserAction.onClicked.addListener(sendCurrentUrl);

22
readme.md Normal file
View File

@ -0,0 +1,22 @@
# Postify
Post current url to external http server.
## Install
First, build xpi file
```shell
make build-xpi
```
Next, change firefox extension signature preferences
* open `about:config`
* change `xpinstall.signatures.required` to `false`
Finally, install extension via "Install Add-on from a file".
## See also
* https://github.com/ibizaman/jsondispatch

5
server.php Normal file
View File

@ -0,0 +1,5 @@
<?php
ob_start();
var_dump(file_get_contents('php://input'));
error_log(ob_get_clean(), 4);

24
storage.js Normal file
View File

@ -0,0 +1,24 @@
function PropertyStorage(name) {
const parse = function (data) {
const propertyData = data[name];
if (!propertyData) {
return null;
}
try {
return JSON.parse(propertyData);
} catch (e) {
return null;
}
};
this.get = function () {
const getting = browser.storage.local.get(name);
return getting.then(parse);
};
this.set = function (value) {
return browser.storage.local.set({ patterns: JSON.stringify(value) });
};
}
PatternStorage = new PropertyStorage('patterns');