Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better organization of the code and a new html configuration page.
- Loading branch information
Showing
6 changed files
with
256 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<html> | ||
<head> | ||
<title>PushMarks</title> | ||
<script type="text/javascript" src="jquery-1.3.1.min.js"></script> | ||
</head> | ||
|
||
<body> | ||
|
||
<script language="javascript" type="text/javascript"> | ||
|
||
var prefs = Components.classes["@mozilla.org/preferences-service;1"] | ||
.getService(Components.interfaces.nsIPrefService); | ||
prefs = prefs.getBranch("extensions.pushmarks."); | ||
|
||
function save () { | ||
var prefValues = { | ||
"deliciousEnabled" : $('input[@name=deliciousEnabled]')[0].checked, | ||
"deliciousUsername" : $('input[@name=deliciousUsername]')[0].value, | ||
"deliciousPassword" : $('input[@name=deliciousPassword]')[0].value, | ||
}; | ||
|
||
prefs.setBoolPref('delicious.enabled', prefValues.deliciousEnabled); | ||
prefs.setCharPref('delicious.username', prefValues.deliciousUsername); | ||
prefs.setCharPref('delicious.password', prefValues.deliciousPassword); | ||
service = {}; | ||
Components.utils.import('resource://pushmarks/modules/service.js', service); | ||
service.refreshFromPrefs(); | ||
} | ||
|
||
function initialize () { | ||
$('input[@name=deliciousEnabled]')[0].checked = prefs.getBoolPref('delicious.enabled'); | ||
$('input[@name=deliciousUsername]')[0].value = prefs.getCharPref('delicious.username'); | ||
$('input[@name=deliciousPassword]')[0].value = prefs.getCharPref('delicious.password'); | ||
} | ||
|
||
$(document).ready(initialize); | ||
|
||
</script> | ||
|
||
<div class="in"> | ||
Delicious | ||
<input type="checkbox" name="deliciousEnabled"> enabled <br> | ||
Username: <input type="text" name="deliciousUsername" /> <br> | ||
Password <input type="text" name="deliciousPassword"/> <br> | ||
<a href="javascript:save()">save</a> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pref("extensions.pushmarks.delicious.enabled", false); | ||
pref("extensions.pushmarks.delicious.username", ""); | ||
pref("extensions.pushmarks.delicious.password", ""); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// ***** BEGIN LICENSE BLOCK ***** | ||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1 | ||
// | ||
// The contents of this file are subject to the Mozilla Public License Version | ||
// 1.1 (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// http://www.mozilla.org/MPL/ | ||
// | ||
// Software distributed under the License is distributed on an "AS IS" basis, | ||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
// for the specific language governing rights and limitations under the | ||
// License. | ||
// | ||
// The Original Code is Mozilla Corporation Code. | ||
// | ||
// The Initial Developer of the Original Code is | ||
// Mikeal Rogers. | ||
// Portions created by the Initial Developer are Copyright (C) 2009 | ||
// the Initial Developer. All Rights Reserved. | ||
// | ||
// Contributor(s): | ||
// Mikeal Rogers <mikeal.rogers@gmail.com> | ||
// | ||
// Alternatively, the contents of this file may be used under the terms of | ||
// either the GNU General Public License Version 2 or later (the "GPL"), or | ||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
// in which case the provisions of the GPL or the LGPL are applicable instead | ||
// of those above. If you wish to allow use of your version of this file only | ||
// under the terms of either the GPL or the LGPL, and not to allow others to | ||
// use your version of this file under the terms of the MPL, indicate your | ||
// decision by deleting the provisions above and replace them with the notice | ||
// and other provisions required by the GPL or the LGPL. If you do not delete | ||
// the provisions above, a recipient may use your version of this file under | ||
// the terms of any one of the MPL, the GPL or the LGPL. | ||
|
||
var EXPORTED_SYMBOLS = ['Service', 'refreshFromPrefs'] | ||
|
||
var utils = {}; Components.utils.import('resource://pushmarks/modules/utils.js', utils); | ||
|
||
var Service = {}; | ||
Service.add = function (bookmark) { | ||
if (Service.deliciousEnabled) { | ||
|
||
Service.deliciousAdd(bookmark); | ||
} | ||
} | ||
Service.getFromDelicious = function (bookmark) { | ||
|
||
} | ||
Service._deliciousAdd = function (bookmark) { | ||
var XMLHttpRequest = utils.getMethodInWindows('XMLHttpRequest'); | ||
var req = new XMLHttpRequest(); | ||
var url = 'https://api.del.icio.us/v1/posts/add?'; | ||
url += '&url='+bookmark.uri; | ||
url += '&description='+bookmark.title; | ||
url += '&extended='+bookmark.title; | ||
url += '&tags='+bookmark.tags.join(' '); | ||
req.open('GET', url, false, Service.deliciousUsername, Service.deliciousPassword); | ||
req.setRequestHeader('User-Agent', 'pushmarks-0.1'); | ||
req.send(null); | ||
if (req.status != 200) { | ||
throw "Request to delicious failed, status code "+req.status+". Message: "+String(req.responseText); | ||
} | ||
return req | ||
} | ||
Service._deliciousAddQueue = []; | ||
Service.deliciousAdd = function (bookmark) { | ||
Service._deliciousAddQueue.push(bookmark); | ||
if (Service.timeoutSet == false) { | ||
Service.setTimeoutQueue(); | ||
} | ||
} | ||
Service.timeoutSet = false; | ||
Service.queueDo = function () { | ||
if (Service._deliciousAddQueue.length == 0) { | ||
hwindow.clearInterval(Service.timeoutSet); | ||
Service.timeoutSet = false; | ||
} else { | ||
Service._deliciousAdd(Service._deliciousAddQueue.pop()) | ||
} | ||
} | ||
Service.setTimeoutQueue = function () { | ||
hwindow.Service = Service; | ||
Service.timeoutSet = hwindow.setInterval("Service.queueDo()", 5000); | ||
} | ||
Service.deliciousUsername = null; | ||
Service.deliciousPassword = null; | ||
|
||
|
||
var prefs = Components.classes["@mozilla.org/preferences-service;1"] | ||
.getService(Components.interfaces.nsIPrefService); | ||
prefs = prefs.getBranch("extensions.pushmarks."); | ||
|
||
var refreshFromPrefs = function () { | ||
Service.deliciousEnabled = prefs.getBoolPref('delicious.enabled'); | ||
Service.deliciousUsername = prefs.getBoolPref('delicious.username'); | ||
Service.deliciousPassword = prefs.getBoolPref('delicious.password'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// ***** BEGIN LICENSE BLOCK ***** | ||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1 | ||
// | ||
// The contents of this file are subject to the Mozilla Public License Version | ||
// 1.1 (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// http://www.mozilla.org/MPL/ | ||
// | ||
// Software distributed under the License is distributed on an "AS IS" basis, | ||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
// for the specific language governing rights and limitations under the | ||
// License. | ||
// | ||
// The Original Code is Mozilla Corporation Code. | ||
// | ||
// The Initial Developer of the Original Code is | ||
// Mikeal Rogers. | ||
// Portions created by the Initial Developer are Copyright (C) 2009 | ||
// the Initial Developer. All Rights Reserved. | ||
// | ||
// Contributor(s): | ||
// Mikeal Rogers <mikeal.rogers@gmail.com> | ||
// | ||
// Alternatively, the contents of this file may be used under the terms of | ||
// either the GNU General Public License Version 2 or later (the "GPL"), or | ||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | ||
// in which case the provisions of the GPL or the LGPL are applicable instead | ||
// of those above. If you wish to allow use of your version of this file only | ||
// under the terms of either the GPL or the LGPL, and not to allow others to | ||
// use your version of this file under the terms of the MPL, indicate your | ||
// decision by deleting the provisions above and replace them with the notice | ||
// and other provisions required by the GPL or the LGPL. If you do not delete | ||
// the provisions above, a recipient may use your version of this file under | ||
// the terms of any one of the MPL, the GPL or the LGPL. | ||
|
||
var EXPORTED_SYMBOLS = ['tempfile', 'getWindows', 'getMethodInWindows']; | ||
|
||
var ios = Components.classes["@mozilla.org/network/io-service;1"] | ||
.getService(Components.interfaces.nsIIOService); | ||
var hwindow = Components.classes["@mozilla.org/appshell/appShellService;1"] | ||
.getService(Components.interfaces.nsIAppShellService) | ||
.hiddenDOMWindow; | ||
var uuidgen = Components.classes["@mozilla.org/uuid-generator;1"] | ||
.getService(Components.interfaces.nsIUUIDGenerator); | ||
|
||
function tempfile(appention) { | ||
if (appention == undefined) { | ||
var appention = "mozmill.utils.tempfile" | ||
} | ||
var tempfile = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("TmpD", Components.interfaces.nsIFile); | ||
tempfile.append(uuidgen.generateUUID().toString().replace('-', '').replace('{', '').replace('}','')) | ||
tempfile.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777); | ||
tempfile.append(appention); | ||
tempfile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666); | ||
// do whatever you need to the created file | ||
return tempfile.clone(); | ||
} | ||
|
||
function getWindows(type) { | ||
if (type == undefined) { | ||
var type = ""; | ||
} | ||
var windows = [] | ||
var enumerator = Components.classes["@mozilla.org/appshell/window-mediator;1"] | ||
.getService(Components.interfaces.nsIWindowMediator) | ||
.getEnumerator(type); | ||
while(enumerator.hasMoreElements()) { | ||
windows.push(enumerator.getNext()); | ||
} | ||
return windows; | ||
} | ||
|
||
function getMethodInWindows (methodName) { | ||
for each(w in getWindows()) { | ||
if (w[methodName] != undefined) { | ||
return w[methodName]; | ||
} | ||
} | ||
throw "Method with name: '"+methodName+"' is not in any open window."; | ||
} |