Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Got it all working.

  • Loading branch information...
commit 4b797dfb38fdc62ef6a643971de203c725d81bd4 1 parent da04665
Mikeal Rogers authored
15 extension/content/index.html
@@ -22,17 +22,26 @@
22 22 prefs.setBoolPref('delicious.enabled', prefValues.deliciousEnabled);
23 23 prefs.setCharPref('delicious.username', prefValues.deliciousUsername);
24 24 prefs.setCharPref('delicious.password', prefValues.deliciousPassword);
25   - service = {};
  25 + var service = {};
26 26 Components.utils.import('resource://pushmarks/modules/service.js', service);
27 27 service.refreshFromPrefs();
28 28 }
29 29
  30 +function sync() {
  31 + save();
  32 + var pushmarks = {};
  33 + Components.utils.import('resource://pushmarks/modules/init.js', pushmarks);
  34 + pushmarks.fullSync();
  35 +}
  36 +
30 37 function initialize () {
31 38 $('input[name=deliciousEnabled]')[0].checked = prefs.getBoolPref('delicious.enabled');
32 39 $('input[name=deliciousUsername]')[0].value = prefs.getCharPref('delicious.username');
33 40 $('input[name=deliciousPassword]')[0].value = prefs.getCharPref('delicious.password');
34 41 }
35 42
  43 +
  44 +
36 45 $(document).ready(initialize);
37 46
38 47 </script>
@@ -41,8 +50,8 @@
41 50 Delicious
42 51 <input type="checkbox" name="deliciousEnabled"> enabled <br>
43 52 Username: <input type="text" name="deliciousUsername" /> <br>
44   - Password <input type="text" name="deliciousPassword"/> <br>
45   - <a href="javascript:save()">save</a>
  53 + Password <input type="password" name="deliciousPassword"/> <br>
  54 + <a href="javascript:save()">save</a><tab><a href="javascript:sync()">sync</a>
46 55 </div>
47 56 </div>
48 57 </body>
63 extension/resource/modules/init.js
@@ -121,17 +121,17 @@ Bookmark.prototype.push = function() {
121 121 Service.add(this);
122 122 }
123 123
124   -// var getDelicious = function (username, password) {
125   -// var XMLHttpRequest = utils.getMethodInWindows('XMLHttpRequest');
126   -// var req = new XMLHttpRequest();
127   -// req.open('GET', 'https://api.del.icio.us/v1/posts/all', false, username, password);
128   -// req.setRequestHeader('User-Agent', 'pushmarks-0.1')
129   -// req.send(null);
130   -// if (req.status != 200) {
131   -// throw "Request to delicious fails, status code "+req.status+". Message: "+String(req.responseText)
132   -// }
133   -// return req.responseXML;
134   -// }
  124 +var getDelicious = function (username, password) {
  125 + var XMLHttpRequest = utils.getMethodInWindows('XMLHttpRequest');
  126 + var req = new XMLHttpRequest();
  127 + req.open('GET', 'https://api.del.icio.us/v1/posts/all', false, username, password);
  128 + req.setRequestHeader('User-Agent', 'pushmarks-0.1')
  129 + req.send(null);
  130 + if (req.status != 200) {
  131 + throw "Request to delicious fails, status code "+req.status+". Message: "+String(req.responseText)
  132 + }
  133 + return req.responseXML;
  134 +}
135 135
136 136
137 137 var readFile = function (file) {
@@ -153,16 +153,26 @@ var readFile = function (file) {
153 153 fstream.close();
154 154 return data;
155 155 }
156   -
  156 +//
157 157 var getDelicious = function(username, password) {
158   - var file = Components.classes["@mozilla.org/file/local;1"].
159   - createInstance(Components.interfaces.nsILocalFile);
160   - file.initWithPath("/Users/mikeal/Documents/git/pushmarks/all.xml");
161   - // |file| is nsIFile
162   - data = readFile(file)
163   - var parser = new utils.getMethodInWindows('DOMParser')();
164   - var dom = parser.parseFromString(data, "text/xml");
165   - posts = dom.getElementsByTagName('post');
  158 + // var file = Components.classes["@mozilla.org/file/local;1"].
  159 + // createInstance(Components.interfaces.nsILocalFile);
  160 + // file.initWithPath("/Users/mikeal/Documents/git/pushmarks/all.xml");
  161 + // // |file| is nsIFile
  162 + // data = readFile(file)
  163 + var XMLHttpRequest = utils.getMethodInWindows('XMLHttpRequest');
  164 + var req = new XMLHttpRequest();
  165 + req.open('GET', 'https://api.del.icio.us/v1/posts/all', false, username, password);
  166 + req.setRequestHeader('User-Agent', 'pushmarks-0.1')
  167 + req.send(null);
  168 + if (req.status != 200) {
  169 + throw "Request to delicious fails, status code "+req.status+". Message: "+String(req.responseText)
  170 + }
  171 + // return
  172 + // var data = req.responseXML;
  173 + // var parser = new utils.getMethodInWindows('DOMParser')();
  174 + // var dom = parser.parseFromString(data, "text/xml");
  175 + posts = req.responseXML.getElementsByTagName('post');
166 176 bookmarks = []
167 177 for each(post in posts) {
168 178 if (post.getAttribute != undefined) {
@@ -188,7 +198,7 @@ importing = false;
188 198
189 199 var fullSync = function() {
190 200 importing = true;
191   - var deliciousBookmarks = getDelicious(null, null);
  201 + var deliciousBookmarks = getDelicious(Service.deliciousUsername, Service.deliciousPassword);
192 202 var localBookmarks = getAllBookmarks();
193 203 for each(bookmark in deliciousBookmarks) {
194 204 bookmark.save();
@@ -276,8 +286,15 @@ var MyExtension = {
276 286 callbackArgs: [],
277 287 _itemAdded: function (aItemId, aFolder, aIndex) {
278 288 if (!livemarkService.isLivemark(aFolder) &&
279   - !isAddedByExtension(aItemId)) {
280   -
  289 + !isAddedByExtension(aItemId) &&
  290 + bmsvc.getItemType(aItemId) == 1) {
  291 + var uri = bmsvc.getBookmarkURI(aItemId);
  292 + var title = bmsvc.getItemTitle(aItemId);
  293 + if (title != null && title != 'History' && title != 'Tags') {
  294 + var bookmark = new Bookmark(uri.spec, title, taggingSvc.getTagsForURI(uri, {}));
  295 + consoleService.logStringMessage(String(bmsvc.getItemTitle(aItemId)))
  296 + bookmark.push();
  297 + }
281 298 }
282 299
283 300 },
28 extension/resource/modules/service.js
@@ -35,6 +35,29 @@
35 35
36 36 var EXPORTED_SYMBOLS = ['Service', 'refreshFromPrefs']
37 37
  38 +var ios = Components.classes["@mozilla.org/network/io-service;1"]
  39 + .getService(Components.interfaces.nsIIOService);
  40 +
  41 +var taggingSvc = Components.classes["@mozilla.org/browser/tagging-service;1"]
  42 + .getService(Components.interfaces.nsITaggingService);
  43 +
  44 +var bmsvc = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
  45 + .getService(Components.interfaces.nsINavBookmarksService);
  46 +var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
  47 + .getService(Components.interfaces.nsIConsoleService);
  48 +var livemarkService = Components.classes["@mozilla.org/browser/livemark-service;2"]
  49 + .getService(Components.interfaces.nsILivemarkService);
  50 +var hwindow = Components.classes["@mozilla.org/appshell/appShellService;1"]
  51 + .getService(Components.interfaces.nsIAppShellService)
  52 + .hiddenDOMWindow;
  53 +var historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"]
  54 + .getService(Components.interfaces.nsINavHistoryService);
  55 +var uuidgen = Components.classes["@mozilla.org/uuid-generator;1"]
  56 + .getService(Components.interfaces.nsIUUIDGenerator);
  57 +
  58 +
  59 +var withs = {}; Components.utils.import('resource://pushmarks/modules/withs.js', withs);
  60 +var arrays = {}; Components.utils.import('resource://pushmarks/modules/arrays.js', arrays);
38 61 var utils = {}; Components.utils.import('resource://pushmarks/modules/utils.js', utils);
39 62
40 63 var Service = {};
@@ -93,6 +116,7 @@ prefs = prefs.getBranch("extensions.pushmarks.");
93 116
94 117 var refreshFromPrefs = function () {
95 118 Service.deliciousEnabled = prefs.getBoolPref('delicious.enabled');
96   - Service.deliciousUsername = prefs.getBoolPref('delicious.username');
97   - Service.deliciousPassword = prefs.getBoolPref('delicious.password');
  119 + Service.deliciousUsername = prefs.getCharPref('delicious.username');
  120 + Service.deliciousPassword = prefs.getCharPref('delicious.password');
98 121 }
  122 +refreshFromPrefs();

0 comments on commit 4b797df

Please sign in to comment.
Something went wrong with that request. Please try again.