Browse code
initial---still need to get an icon
fiddlerwoaroof authored on 17/03/2015 10:43:08
Showing 6 changed files
Showing 6 changed files
3 | 3 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,22 @@ |
1 |
+{ |
|
2 |
+"manifest_version": 2, |
|
3 |
+ |
|
4 |
+"name": "Add to Marrow", |
|
5 |
+"description": "This extension adds the current page to your marrow list", |
|
6 |
+"version": "1.0", |
|
7 |
+ |
|
8 |
+"browser_action": { |
|
9 |
+ "default_icon": "icon.png", |
|
10 |
+ "default_popup": "popup.html" |
|
11 |
+}, |
|
12 |
+ |
|
13 |
+"permissions": [ |
|
14 |
+ "storage", |
|
15 |
+ "activeTab", |
|
16 |
+ "https://themarrow.is/" |
|
17 |
+], |
|
18 |
+ |
|
19 |
+"options_ui": { |
|
20 |
+ "page": "options.html", |
|
21 |
+ "chrome_style": true |
|
22 |
+}} |
0 | 23 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,19 @@ |
1 |
+<!DOCTYPE html> |
|
2 |
+<html> |
|
3 |
+<head> |
|
4 |
+ <title>My Test Extension Options</title> |
|
5 |
+ <style> |
|
6 |
+ body: { padding: 10px; } |
|
7 |
+ </style> |
|
8 |
+</head> |
|
9 |
+ |
|
10 |
+<body> |
|
11 |
+ <input id="username" type="text" placeholder="Username" /> |
|
12 |
+ <input id="password" type="password" placeholder="Password" /> |
|
13 |
+ <div id="status"></div> |
|
14 |
+ <button id="save">Save</button> |
|
15 |
+ |
|
16 |
+ <script src="options.js"></script> |
|
17 |
+</body> |
|
18 |
+</html> |
|
19 |
+ |
0 | 20 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,33 @@ |
1 |
+// Saves options to chrome.storage.sync. |
|
2 |
+function save_options() { |
|
3 |
+ var username = document.getElementById('username').value; |
|
4 |
+ var password = document.getElementById('password').value; |
|
5 |
+ chrome.storage.sync.set({ |
|
6 |
+ username: username, |
|
7 |
+ password: password |
|
8 |
+ }, function() { |
|
9 |
+ // Update status to let user know options were saved. |
|
10 |
+ var status = document.getElementById('status'); |
|
11 |
+ status.textContent = 'Options saved.'; |
|
12 |
+ setTimeout(function() { |
|
13 |
+ status.textContent = ''; |
|
14 |
+ }, 750); |
|
15 |
+ }); |
|
16 |
+} |
|
17 |
+ |
|
18 |
+// Restores select box and checkbox state using the preferences |
|
19 |
+// stored in chrome.storage. |
|
20 |
+function restore_options() { |
|
21 |
+ // Use default value color = 'red' and likesColor = true. |
|
22 |
+ chrome.storage.sync.get({ |
|
23 |
+ username: '', |
|
24 |
+ password: '' |
|
25 |
+ }, function(items) { |
|
26 |
+ document.getElementById('username').value = items.username; |
|
27 |
+ document.getElementById('password').value = items.password; |
|
28 |
+ }); |
|
29 |
+} |
|
30 |
+document.addEventListener('DOMContentLoaded', restore_options); |
|
31 |
+document.getElementById('save').addEventListener('click', |
|
32 |
+ save_options); |
|
33 |
+ |
0 | 34 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,37 @@ |
1 |
+<!doctype html> |
|
2 |
+<!-- |
|
3 |
+ This page is shown when the extension button is clicked, because the |
|
4 |
+ "browser_action" field in manifest.json contains the "default_popup" key with |
|
5 |
+ value "popup.html". |
|
6 |
+ --> |
|
7 |
+<html> |
|
8 |
+ <head> |
|
9 |
+ <title>Getting Started Extension's Popup</title> |
|
10 |
+ <style> |
|
11 |
+ body { |
|
12 |
+ font-family: "Segoe UI", "Lucida Grande", Tahoma, sans-serif; |
|
13 |
+ font-size: 100%; |
|
14 |
+ } |
|
15 |
+ #status { |
|
16 |
+ /* avoid an excessively wide status text */ |
|
17 |
+ white-space: pre; |
|
18 |
+ text-overflow: ellipsis; |
|
19 |
+ overflow: hidden; |
|
20 |
+ max-width: 400px; |
|
21 |
+ } |
|
22 |
+ </style> |
|
23 |
+ |
|
24 |
+ <!-- |
|
25 |
+ - JavaScript and HTML must be in separate files: see our Content Security |
|
26 |
+ - Policy documentation[1] for details and explanation. |
|
27 |
+ - |
|
28 |
+ - [1]: https://developer.chrome.com/extensions/contentSecurityPolicy |
|
29 |
+ --> |
|
30 |
+ <script src="popup.js"></script> |
|
31 |
+ </head> |
|
32 |
+ <body> |
|
33 |
+ <div id="status"></div> |
|
34 |
+ <img id="image-result" hidden> |
|
35 |
+ </body> |
|
36 |
+</html> |
|
37 |
+ |
0 | 38 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,79 @@ |
1 |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
|
2 |
+// Use of this source code is governed by a BSD-style license that can be |
|
3 |
+// found in the LICENSE file. |
|
4 |
+ |
|
5 |
+function getCurrentTabUrl(callback) { |
|
6 |
+ var queryInfo = {active: true, currentWindow: true}; |
|
7 |
+ |
|
8 |
+ chrome.tabs.query(queryInfo, function(tabs) { |
|
9 |
+ var tab = tabs[0]; |
|
10 |
+ var url = tab.url; |
|
11 |
+ console.assert(typeof url == 'string', 'tab.url should be a string'); |
|
12 |
+ callback(url, tab.title); |
|
13 |
+ }); |
|
14 |
+} |
|
15 |
+ |
|
16 |
+function postURL(url, title, username, ak, callback, errorCallback) { |
|
17 |
+ //{"url":"https://medium.com/matter/the-boy-whose-brain-could-unlock-autism-70c3d64ff221","title":""} |
|
18 |
+ var urlObj = JSON.stringify({"url": url, "title": title, "username": username, "ak": ak}); |
|
19 |
+ var addUrl = 'https://themarrow.is/api/bones/add'; |
|
20 |
+ var x = new XMLHttpRequest(); |
|
21 |
+ x.open('POST', addUrl); |
|
22 |
+ x.setRequestHeader("Content-type","application/json"); |
|
23 |
+ x.responseType = 'json'; |
|
24 |
+ x.onload = function() { |
|
25 |
+ var response = x.response; |
|
26 |
+ callback(response); |
|
27 |
+ }; |
|
28 |
+ x.onerror = function() { |
|
29 |
+ errorCallback('Network error.'); |
|
30 |
+ }; |
|
31 |
+ x.send(urlObj); |
|
32 |
+} |
|
33 |
+ |
|
34 |
+function renderStatus(statusText) { |
|
35 |
+ document.getElementById('status').textContent = statusText; |
|
36 |
+} |
|
37 |
+ |
|
38 |
+document.addEventListener('DOMContentLoaded', function() { |
|
39 |
+ chrome.storage.sync.get({ |
|
40 |
+ username: '', |
|
41 |
+ password: '' |
|
42 |
+ }, function (items) { |
|
43 |
+ var username = items.username; |
|
44 |
+ var password = items.password; |
|
45 |
+ if (username === '') { |
|
46 |
+ renderStatus('Fail :('); |
|
47 |
+ return; |
|
48 |
+ } |
|
49 |
+ var y = new XMLHttpRequest(); |
|
50 |
+ y.open('POST', 'https://themarrow.is/api/user/login?ak=1'); |
|
51 |
+ y.responseType = 'json'; |
|
52 |
+ y.setRequestHeader("Content-type","application/json"); |
|
53 |
+ y.onload = (function() { |
|
54 |
+ var response = y.response; |
|
55 |
+ if (response === false) { |
|
56 |
+ renderStatus('Fail :('); |
|
57 |
+ } else { |
|
58 |
+ getCurrentTabUrl(function(url, title) { |
|
59 |
+ renderStatus('Submitting url ' + url + ' to Marrow'); |
|
60 |
+ postURL(url, title, username, response.ak, |
|
61 |
+ function(response) { |
|
62 |
+ if (response.success === true) { |
|
63 |
+ console.log('posted successfully'); |
|
64 |
+ renderStatus('Success :)'); |
|
65 |
+ } else { |
|
66 |
+ console.log('fail!'); |
|
67 |
+ console.log(response); |
|
68 |
+ renderStatus('Fail :('); |
|
69 |
+ } |
|
70 |
+ }, function(errorMessage) { |
|
71 |
+ renderStatus('Unexpected Error: ' + errorMessage); |
|
72 |
+ }); |
|
73 |
+ }); |
|
74 |
+ } |
|
75 |
+ }); |
|
76 |
+ var postData = JSON.stringify({"username":username,"password":password}); |
|
77 |
+ y.send(postData); |
|
78 |
+ }); |
|
79 |
+}); |