Compare commits
	
		
			10 Commits
		
	
	
		
			949106ce50
			...
			a251acec86
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						a251acec86
	
				 | 
					
					
						|||
| 
						 | 
					39ba18438c | ||
| 
						 | 
					48ce7ac0c1 | ||
| 
						 | 
					01842d265b | ||
| 
						 | 
					53c583464d | ||
| 
						 | 
					40fa9b9f07 | ||
| 
						 | 
					9cfcefb1dd | ||
| 
						 | 
					8d0cf41d73 | ||
| 
						 | 
					a10e24198e | ||
| 
						 | 
					c5a6d8fc53 | 
							
								
								
									
										15
									
								
								.editorconfig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								.editorconfig
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					./.idea
 | 
				
			||||||
 | 
					*.xpi
 | 
				
			||||||
							
								
								
									
										6
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								Makefile
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										
											BIN
										
									
								
								icons/postify-48.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 1.0 KiB  | 
@@ -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
									
								
							
							
						
						
									
										43
									
								
								options.html
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										64
									
								
								options.js
									
									
									
									
									
										Normal 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);
 | 
				
			||||||
							
								
								
									
										61
									
								
								postify.js
									
									
									
									
									
								
							
							
						
						
									
										61
									
								
								postify.js
									
									
									
									
									
								
							@@ -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
									
								
							
							
						
						
									
										22
									
								
								readme.md
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										5
									
								
								server.php
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										24
									
								
								storage.js
									
									
									
									
									
										Normal 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');
 | 
				
			||||||
		Reference in New Issue
	
	Block a user