Permalink
Browse files

tons of bugfixes and cleanup before the big refactoring

v0.0.4
  • Loading branch information...
michaelficarra committed Oct 21, 2012
1 parent 481ec4d commit 2218a53f88896c7f5bd927cf5ba802843b164e3b
Showing with 159 additions and 143 deletions.
  1. +1 −0 .gitignore
  2. +11 −0 Makefile
  3. +2 −14 README.md
  4. +2 −14 background.js
  5. +10 −5 handlers/generic.js
  6. +1 −1 handlers/torrentz.js
  7. +51 −44 manifest.json
  8. +1 −1 popup.css
  9. +2 −8 popup.html
  10. +37 −29 popup.js
  11. BIN transmissionDownload.crx
  12. +1 −1 updateInfo.xml
  13. +40 −26 util.js
View
@@ -1 +1,2 @@
*.pem
+.*.sw[po]
View
@@ -0,0 +1,11 @@
+default: clean dist
+
+dist: transmissionDownload.crx
+
+transmissionDownload.crx: transmissionDownload.pem
+ crxmake --pack-extension=. --pack-extension-key=transmissionDownload.pem --ignore-file='\.(pem|crx)$$|^\.' --ignore-dir=images
+
+.PHONY: clean
+
+clean:
+ rm -f transmissionDownload.crx
View
@@ -24,7 +24,7 @@ output, the torrent should now be added to the transmission server.
*Note:* This extension requires the Transmission HTTP RPC. This can be enabled [through
the preferences
-GUI](http://www.transmissionbt.com/help/gtk/2.2x/html/preferences.html#web)
+GUI](http://www.transmissionbt.com/help/gtk/2.3x/html/preferences.html#web)
when using transmission-gtk or by setting the `rpc-enabled` and related `rpc-*`
values in transmission-daemon's `settings.json` file when using transmission-daemon.
@@ -80,18 +80,6 @@ values in transmission-daemon's `settings.json` file when using transmission-dae
## Building / Releasing
-0. Open `chrome://extensions` in chrome
-0. Enable developer mode
-0. Delete `transmissionDownload.crx` from repo directory
-0. Delete `images/screenshots`
-0. Bump version number in `updateInfo.xml`
-0. Bump version number in `manifest.json`
-0. Press "Load unpacked extension..." button
-0. Choose repo directory
-0. Press "Pack extension..." button
-0. Choose repo directory
-0. If making an official release, choose signature file as well
-0. Move generated `transmissionDownload.crx` file to repo directory
-0. Checkout `images/screenshots`
+0. `make clean dist`
0. Update README, screenshots
0. Commit, tag, and push
View
@@ -1,16 +1,4 @@
-(function(global, undefined){
-
- localStorage.defaultServerProtocol = JSON.stringify('http');
- localStorage.defaultServerHost = JSON.stringify('localhost');
- localStorage.defaultServerPort = JSON.stringify(9091);
- localStorage.defaultServerPath = JSON.stringify('/transmission/rpc');
- localStorage.defaultAuthenticationEnabled = JSON.stringify(false);
- localStorage.defaultAuthenticationEncrypted = JSON.stringify(false);
- localStorage.defaultAuthenticationUsername = JSON.stringify('');
- localStorage.defaultAuthenticationPassword = JSON.stringify('');
- localStorage.defaultStartAutomatically = JSON.stringify(true);
- localStorage.defaultAddTrackers = JSON.stringify(true);
- localStorage.defaultAdditionalTrackers = JSON.stringify([]);
+(function(global){
var supportedUrls =
[ /^https?:\/\/([^\/]*\.)?torrentz\.(com|eu|me)\/(announce_)?[a-f0-9]{40}/i
@@ -19,7 +7,7 @@
];
var isSupportedUrl = function(url){
for(var i=0,l=supportedUrls.length; i<l; ++i) {
- if(supportedUrls[i](url)) return true;
+ if(supportedUrls[i].test(url)) return true;
}
return false;
};
View
@@ -4,11 +4,16 @@
if(chrome.extension.onRequest.hasListeners()) return;
var getInfoHash = function(){
- var magnet = document.querySelector('a[href^="magnet:?xt=urn:btih:"]');
- if(!magnet) return;
- var match = magnet.href.match(/^magnet:\?xt=urn:btih:([a-f0-9]{40})/i);
- if(!match) return;
- return match[1];
+ var magnet, match;
+ // try to find a magnet link
+ magnet = document.querySelector('a[href^="magnet:?xt=urn:btih:"]');
+ if(magnet) {
+ match = magnet.href.match(/^magnet:\?xt=urn:btih:([a-f0-9]{40})/i);
+ if(match) return match[1];
+ }
+ // try to find an info_hash somewhere in the text of the page
+ match = document.documentElement.innerText.match(/\b[a-f0-9]{40}\b/i);
+ if(match) return match[0];
};
chrome.extension.onRequest.addListener(function(request,sender,respond){
View
@@ -2,7 +2,7 @@
var getInfoHash = function(){
var path = location.pathname,
- matches = /^\/(?:announce_)?([a-f0-9]{40})/i(path);
+ matches = path.match(/^\/(?:announce_)?([a-f0-9]{40})/i);
if(!matches || matches.length < 2) return;
return matches[1];
};
View
@@ -1,47 +1,54 @@
-{ "name" : "Transmission Torrent Downloader"
-, "homepage_url" : "https://github.com/michaelficarra/transmissionDownload"
-, "update_url" : "https://github.com/michaelficarra/transmissionDownload/updateInfo.xml"
-, "version" : "0.0.3"
-, "description" : "Adds torrent to Transmission through RPC on supported websites"
-, "icons" :
- { "16" : "icons/transmission.16.alt.png"
- , "32" : "icons/transmission.32.png"
- , "48" : "icons/transmission.48.png"
- , "64" : "icons/transmission.64.png"
- , "128": "icons/transmission.128.png"
- , "256": "icons/transmission.256.png"
- }
+{ "manifest_version": 2
+, "name": "Transmission Torrent Downloader"
+, "homepage_url": "https://github.com/michaelficarra/transmissionDownload"
+, "update_url": "https://github.com/michaelficarra/transmissionDownload/updateInfo.xml"
+, "version": "0.0.4"
+, "description": "Adds torrent to Transmission through RPC on supported websites"
+, "icons":
+ { "16" : "icons/transmission.16.alt.png"
+ , "32" : "icons/transmission.32.png"
+ , "48" : "icons/transmission.48.png"
+ , "64" : "icons/transmission.64.png"
+ , "128": "icons/transmission.128.png"
+ , "256": "icons/transmission.256.png"
+ }
, "page_action":
- { "default_icon" : "icons/transmission.16.alt.png"
- , "default_title": "Add this torrent to Transmission"
- , "default_popup": "popup.html"
- }
+ { "default_icon": "icons/transmission.16.alt.png"
+ , "default_title": "Add this torrent to Transmission"
+ , "default_popup": "popup.html"
+ }
, "content_scripts":
- [
- { "matches":
- [ "*://*.torrentz.eu/*"
- , "*://*.torrentz.com/*"
- , "*://*.torrentz.me/*"
- ]
- , "js" : ["handlers/torrentz.js"]
- }
- ,
- { "matches": [ "*://*/*" ]
- , "js" : ["handlers/generic.js"]
- }
- ]
-, "permissions" :
- [ "tabs"
- , "*://*.torrentz.eu/*"
- , "*://*.torrentz.com/*"
- , "*://*.torrentz.me/*"
- , "*://*.bitsnoop.com/*"
- , "*://*.torrage.com/*"
- , "*://*.torrage.ws/*"
- , "*://*.torcache.com/*"
- , "*://*.zoink.it/*"
- , "*://*/*"
- ]
-, "options_page" : "options.html"
-, "background_page": "background.html"
+ [
+ { "matches":
+ [ "*://*.torrentz.eu/*"
+ , "*://*.torrentz.com/*"
+ , "*://*.torrentz.me/*"
+ ]
+ , "js": ["handlers/torrentz.js"]
+ }
+ ,
+ { "matches": [ "http://*/*", "https://*/*" ]
+ , "js": ["handlers/generic.js"]
+ }
+ ]
+, "permissions":
+ [ "tabs"
+ , "*://*.torrentz.eu/*"
+ , "*://*.torrentz.com/*"
+ , "*://*.torrentz.me/*"
+ , "*://*.bitsnoop.com/*"
+ , "*://*.torrage.com/*"
+ , "*://*.torrage.ws/*"
+ , "*://*.torcache.com/*"
+ , "*://*.zoink.it/*"
+ , "*://*/*"
+ ]
+, "options_page": "options.html"
+, "background":
+ { "scripts":
+ [ "Base64.js"
+ , "util.js"
+ , "background.js"
+ ]
+ }
}
View
@@ -26,4 +26,4 @@ input#symmetric_key {
color: #c94235;
}
-button#addTorrent, button#close { width: 100%; }
+button { width: 100%; }
View
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
+ <title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="chrome.css" />
<link rel="stylesheet" type="text/css" href="popup.css" />
@@ -21,14 +22,7 @@ <h3 id="rpc"></h3>
<input type="password" id="symmetric_key" value="" />
</p>
- <ol id="log" class="hidden">
- <li class="info">Established secure connection to transmission</li>
- <li class="info">Determined info_hash</li>
- <li class="info">Sent torrent to transmission</li>
- <li class="error">Error: duplicate torrent</li>
- <li class="info">Added additional trackers</li>
- <li class="info">Finished</li>
- </ol>
+ <ol id="log"></ol>
<p>
<button id="addTorrent" disabled="disabled">Add Torrent</button>
View
@@ -75,8 +75,13 @@
xhr.onreadystatechange = function(){
if(xhr.readyState!=4) return
var sessionId = xhr.getResponseHeader('X-Transmission-Session-Id');
- if(xhr.status!=409 && xhr.status!=200 || !sessionId)
- return error('could not establish a secure session with the transmission server', xhr, sessionId);
+ if(xhr.status!=409 && xhr.status!=200 || !sessionId) {
+ error('could not establish a secure session with the transmission server', xhr, sessionId);
+ addClass.call($('#addTorrent'), 'hidden');
+ removeClass.call($('#retry'), 'hidden');
+ $('#retry').focus();
+ return;
+ }
self.sessionId = sessionId;
info('secured transmission session', sessionId);
if(typeof callback=='function') callback(sessionId);
@@ -90,7 +95,7 @@
var addTorrent = function(info_hash, callback){
if(!info_hash) return error('addTorrent called without info_hash', info_hash);
if(!this.sessionId)
- return startSession(function(newSessionId){
+ return startSession.call(this, function(newSessionId){
if(!newSessionId) return;
addTorrent(info_hash, callback);
});
@@ -114,7 +119,7 @@
if(xhr.readyState!=4) return;
// handle 409s (for CSRF token timeout) by asking for a new token
if(xhr.status==409)
- return startSession(function(newSessionId){
+ return startSession.call(self, function(newSessionId){
if(!newSessionId) return;
addTorrent(info_hash, callback);
});
@@ -184,7 +189,7 @@
};
- $('close').addEventListener('click', function(){
+ $('#close').addEventListener('click', function(){
window.close();
});
@@ -204,18 +209,18 @@
auth.password = AES.decrypt(this.value, Base64.decode(password));
info('decrypted username and password', auth.username, auth.password.replace(/./g,'*'));
// TODO: modularize this part for future DRYness
- addClass.call($('symmetricKeyContainer'), 'hidden');
- addClass.call($('close'), 'hidden');
- $('addTorrent').disabled = false;
- removeClass.call($('addTorrent'), 'hidden');
- $('addTorrent').focus();
+ addClass.call($('#symmetricKeyContainer'), 'hidden');
+ addClass.call($('#close'), 'hidden');
+ $('#addTorrent').disabled = false;
+ removeClass.call($('#addTorrent'), 'hidden');
+ $('#addTorrent').focus();
} catch(e) {
auth.username = username;
auth.password = password;
}
};
})();
- var symmetricKeyInput = $('symmetric_key');
+ var symmetricKeyInput = $('#symmetric_key');
symmetricKeyInput.addEventListener('keyup', decrypt);
symmetricKeyInput.addEventListener('paste', function(){
setTimeout(function(){ decrypt.call(this); }.bind(this), 0);
@@ -224,30 +229,33 @@
var start = function(){
var context = generateOptions();
+ $('#log').innerHTML = '';
+ removeClass.call($('#addTorrent'), 'hidden');
+ addClass.call($('#retry'), 'hidden');
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {type:'info_hash'}, function(info_hash){
if(!info_hash) return error('could not determine info_hash', info_hash);
info('determined info_hash', info_hash);
var success = true;
- addTorrent.call(contex, info_hash, function(torrent){
+ addTorrent.call(context, info_hash, function(torrent){
info('added torrent ' + JSON.stringify(torrent.name), torrent);
addTrackers.call(context, torrent, function(trackers){
if(trackers)
info('added ' + trackers.length + ' additional trackers', trackers);
log('done')('done');
- if(!success) removeClass.call($('retry'), 'hidden');
- removeClass.call($('close'), 'hidden');
- $(success ? 'close' : 'retry').focus();
+ if(!success) removeClass.call($('#retry'), 'hidden');
+ removeClass.call($('#close'), 'hidden');
+ $(success ? '#close' : '#retry').focus();
});
});
});
});
};
- $('addTorrent').addEventListener('click', start);
- $('retry').addEventListener('click', start);
+ $('#addTorrent').addEventListener('click', start);
+ $('#retry').addEventListener('click', start);
var generateOptions = function(){
- return
+ return 0,
{ authentication:
{ enabled : getOption('AuthenticationEnabled')
, encrypted : getOption('AuthenticationEncrypted')
@@ -262,24 +270,24 @@
}
, sessionId: null
};
- );
+ };
var options = generateOptions(),
auth = options.authentication,
server = options.server,
needsDecryption = auth.enabled && auth.encrypted;
- (needsDecryption ? removeClass : addClass).call($('symmetricKeyContainer'), 'hidden');
- if(needsDecryption) $('symmetric_key').focus();
- (needsDecryption ? addClass : removeClass).call($('addTorrent'), 'hidden');
- $('addTorrent').disabled = needsDecryption;
- (needsDecryption ? removeClass : addClass).call($('close'), 'hidden');
+ (needsDecryption ? removeClass : addClass).call($('#symmetricKeyContainer'), 'hidden');
+ if(needsDecryption) $('#symmetric_key').focus();
+ //(needsDecryption ? addClass : removeClass).call($('#addTorrent'), 'hidden');
+ $('#addTorrent').disabled = needsDecryption;
+ (needsDecryption ? removeClass : addClass).call($('#close'), 'hidden');
- $('rpc').innerText = buildUrl(server.protocol, server.host, server.port, server.path);
+ $('#rpc').innerText = buildUrl(server.protocol, server.host, server.port, server.path);
- addClass.call($('symmetricKeyContainer'), 'hidden');
- addClass.call($('addTorrent'), 'hidden');
- $('log').innerHTML = '';
- removeClass.call($('log'), 'hidden');
+ //addClass.call($('#symmetricKeyContainer'), 'hidden');
+ //addClass.call($('#addTorrent'), 'hidden');
+ $('#log').innerHTML = '';
+ //removeClass.call($('#log'), 'hidden');
/*
chrome.extension.sendRequest(request, function(response){
View
Binary file not shown.
View
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='kbhlogbpfllkkgignllokdlcnjohoehp'>
- <updatecheck codebase='https://github.com/michaelficarra/transmissionDownload/raw/master/transmissionDownload.crx' version='0.0.3' />
+ <updatecheck codebase='https://github.com/michaelficarra/transmissionDownload/raw/master/transmissionDownload.crx' version='0.0.4' />
</app>
</gupdate>
Oops, something went wrong.

0 comments on commit 2218a53

Please sign in to comment.