Skip to content

Commit

Permalink
tons of bugfixes and cleanup before the big refactoring
Browse files Browse the repository at this point in the history
v0.0.4
  • Loading branch information
michaelficarra committed Oct 21, 2012
1 parent 481ec4d commit 2218a53
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 143 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
*.pem *.pem
.*.sw[po]
11 changes: 11 additions & 0 deletions Makefile
@@ -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
16 changes: 2 additions & 14 deletions README.md
Expand Up @@ -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 *Note:* This extension requires the Transmission HTTP RPC. This can be enabled [through
the preferences 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-*` 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. values in transmission-daemon's `settings.json` file when using transmission-daemon.


Expand Down Expand Up @@ -80,18 +80,6 @@ values in transmission-daemon's `settings.json` file when using transmission-dae


## Building / Releasing ## Building / Releasing


0. Open `chrome://extensions` in chrome 0. `make clean dist`
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. Update README, screenshots 0. Update README, screenshots
0. Commit, tag, and push 0. Commit, tag, and push
16 changes: 2 additions & 14 deletions background.js
@@ -1,16 +1,4 @@
(function(global, undefined){ (function(global){

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([]);


var supportedUrls = var supportedUrls =
[ /^https?:\/\/([^\/]*\.)?torrentz\.(com|eu|me)\/(announce_)?[a-f0-9]{40}/i [ /^https?:\/\/([^\/]*\.)?torrentz\.(com|eu|me)\/(announce_)?[a-f0-9]{40}/i
Expand All @@ -19,7 +7,7 @@
]; ];
var isSupportedUrl = function(url){ var isSupportedUrl = function(url){
for(var i=0,l=supportedUrls.length; i<l; ++i) { 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; return false;
}; };
Expand Down
15 changes: 10 additions & 5 deletions handlers/generic.js
Expand Up @@ -4,11 +4,16 @@
if(chrome.extension.onRequest.hasListeners()) return; if(chrome.extension.onRequest.hasListeners()) return;


var getInfoHash = function(){ var getInfoHash = function(){
var magnet = document.querySelector('a[href^="magnet:?xt=urn:btih:"]'); var magnet, match;
if(!magnet) return; // try to find a magnet link
var match = magnet.href.match(/^magnet:\?xt=urn:btih:([a-f0-9]{40})/i); magnet = document.querySelector('a[href^="magnet:?xt=urn:btih:"]');
if(!match) return; if(magnet) {
return match[1]; 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){ chrome.extension.onRequest.addListener(function(request,sender,respond){
Expand Down
2 changes: 1 addition & 1 deletion handlers/torrentz.js
Expand Up @@ -2,7 +2,7 @@


var getInfoHash = function(){ var getInfoHash = function(){
var path = location.pathname, 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; if(!matches || matches.length < 2) return;
return matches[1]; return matches[1];
}; };
Expand Down
95 changes: 51 additions & 44 deletions manifest.json
@@ -1,47 +1,54 @@
{ "name" : "Transmission Torrent Downloader" { "manifest_version": 2
, "homepage_url" : "https://github.com/michaelficarra/transmissionDownload" , "name": "Transmission Torrent Downloader"
, "update_url" : "https://github.com/michaelficarra/transmissionDownload/updateInfo.xml" , "homepage_url": "https://github.com/michaelficarra/transmissionDownload"
, "version" : "0.0.3" , "update_url": "https://github.com/michaelficarra/transmissionDownload/updateInfo.xml"
, "description" : "Adds torrent to Transmission through RPC on supported websites" , "version": "0.0.4"
, "icons" : , "description": "Adds torrent to Transmission through RPC on supported websites"
{ "16" : "icons/transmission.16.alt.png" , "icons":
, "32" : "icons/transmission.32.png" { "16" : "icons/transmission.16.alt.png"
, "48" : "icons/transmission.48.png" , "32" : "icons/transmission.32.png"
, "64" : "icons/transmission.64.png" , "48" : "icons/transmission.48.png"
, "128": "icons/transmission.128.png" , "64" : "icons/transmission.64.png"
, "256": "icons/transmission.256.png" , "128": "icons/transmission.128.png"
} , "256": "icons/transmission.256.png"
}
, "page_action": , "page_action":
{ "default_icon" : "icons/transmission.16.alt.png" { "default_icon": "icons/transmission.16.alt.png"
, "default_title": "Add this torrent to Transmission" , "default_title": "Add this torrent to Transmission"
, "default_popup": "popup.html" , "default_popup": "popup.html"
} }
, "content_scripts": , "content_scripts":
[ [
{ "matches": { "matches":
[ "*://*.torrentz.eu/*" [ "*://*.torrentz.eu/*"
, "*://*.torrentz.com/*" , "*://*.torrentz.com/*"
, "*://*.torrentz.me/*" , "*://*.torrentz.me/*"
] ]
, "js" : ["handlers/torrentz.js"] , "js": ["handlers/torrentz.js"]
} }
, ,
{ "matches": [ "*://*/*" ] { "matches": [ "http://*/*", "https://*/*" ]
, "js" : ["handlers/generic.js"] , "js": ["handlers/generic.js"]
} }
] ]
, "permissions" : , "permissions":
[ "tabs" [ "tabs"
, "*://*.torrentz.eu/*" , "*://*.torrentz.eu/*"
, "*://*.torrentz.com/*" , "*://*.torrentz.com/*"
, "*://*.torrentz.me/*" , "*://*.torrentz.me/*"
, "*://*.bitsnoop.com/*" , "*://*.bitsnoop.com/*"
, "*://*.torrage.com/*" , "*://*.torrage.com/*"
, "*://*.torrage.ws/*" , "*://*.torrage.ws/*"
, "*://*.torcache.com/*" , "*://*.torcache.com/*"
, "*://*.zoink.it/*" , "*://*.zoink.it/*"
, "*://*/*" , "*://*/*"
] ]
, "options_page" : "options.html" , "options_page": "options.html"
, "background_page": "background.html" , "background":
{ "scripts":
[ "Base64.js"
, "util.js"
, "background.js"
]
}
} }
2 changes: 1 addition & 1 deletion popup.css
Expand Up @@ -26,4 +26,4 @@ input#symmetric_key {
color: #c94235; color: #c94235;
} }


button#addTorrent, button#close { width: 100%; } button { width: 100%; }
10 changes: 2 additions & 8 deletions popup.html
@@ -1,6 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> <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="chrome.css" />
<link rel="stylesheet" type="text/css" href="popup.css" /> <link rel="stylesheet" type="text/css" href="popup.css" />
Expand All @@ -21,14 +22,7 @@ <h3 id="rpc"></h3>
<input type="password" id="symmetric_key" value="" /> <input type="password" id="symmetric_key" value="" />
</p> </p>


<ol id="log" class="hidden"> <ol id="log"></ol>
<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>


<p> <p>
<button id="addTorrent" disabled="disabled">Add Torrent</button> <button id="addTorrent" disabled="disabled">Add Torrent</button>
Expand Down
66 changes: 37 additions & 29 deletions popup.js
Expand Up @@ -75,8 +75,13 @@
xhr.onreadystatechange = function(){ xhr.onreadystatechange = function(){
if(xhr.readyState!=4) return if(xhr.readyState!=4) return
var sessionId = xhr.getResponseHeader('X-Transmission-Session-Id'); var sessionId = xhr.getResponseHeader('X-Transmission-Session-Id');
if(xhr.status!=409 && xhr.status!=200 || !sessionId) if(xhr.status!=409 && xhr.status!=200 || !sessionId) {
return error('could not establish a secure session with the transmission server', xhr, 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; self.sessionId = sessionId;
info('secured transmission session', sessionId); info('secured transmission session', sessionId);
if(typeof callback=='function') callback(sessionId); if(typeof callback=='function') callback(sessionId);
Expand All @@ -90,7 +95,7 @@
var addTorrent = function(info_hash, callback){ var addTorrent = function(info_hash, callback){
if(!info_hash) return error('addTorrent called without info_hash', info_hash); if(!info_hash) return error('addTorrent called without info_hash', info_hash);
if(!this.sessionId) if(!this.sessionId)
return startSession(function(newSessionId){ return startSession.call(this, function(newSessionId){
if(!newSessionId) return; if(!newSessionId) return;
addTorrent(info_hash, callback); addTorrent(info_hash, callback);
}); });
Expand All @@ -114,7 +119,7 @@
if(xhr.readyState!=4) return; if(xhr.readyState!=4) return;
// handle 409s (for CSRF token timeout) by asking for a new token // handle 409s (for CSRF token timeout) by asking for a new token
if(xhr.status==409) if(xhr.status==409)
return startSession(function(newSessionId){ return startSession.call(self, function(newSessionId){
if(!newSessionId) return; if(!newSessionId) return;
addTorrent(info_hash, callback); addTorrent(info_hash, callback);
}); });
Expand Down Expand Up @@ -184,7 +189,7 @@
}; };




$('close').addEventListener('click', function(){ $('#close').addEventListener('click', function(){
window.close(); window.close();
}); });


Expand All @@ -204,18 +209,18 @@
auth.password = AES.decrypt(this.value, Base64.decode(password)); auth.password = AES.decrypt(this.value, Base64.decode(password));
info('decrypted username and password', auth.username, auth.password.replace(/./g,'*')); info('decrypted username and password', auth.username, auth.password.replace(/./g,'*'));
// TODO: modularize this part for future DRYness // TODO: modularize this part for future DRYness
addClass.call($('symmetricKeyContainer'), 'hidden'); addClass.call($('#symmetricKeyContainer'), 'hidden');
addClass.call($('close'), 'hidden'); addClass.call($('#close'), 'hidden');
$('addTorrent').disabled = false; $('#addTorrent').disabled = false;
removeClass.call($('addTorrent'), 'hidden'); removeClass.call($('#addTorrent'), 'hidden');
$('addTorrent').focus(); $('#addTorrent').focus();
} catch(e) { } catch(e) {
auth.username = username; auth.username = username;
auth.password = password; auth.password = password;
} }
}; };
})(); })();
var symmetricKeyInput = $('symmetric_key'); var symmetricKeyInput = $('#symmetric_key');
symmetricKeyInput.addEventListener('keyup', decrypt); symmetricKeyInput.addEventListener('keyup', decrypt);
symmetricKeyInput.addEventListener('paste', function(){ symmetricKeyInput.addEventListener('paste', function(){
setTimeout(function(){ decrypt.call(this); }.bind(this), 0); setTimeout(function(){ decrypt.call(this); }.bind(this), 0);
Expand All @@ -224,30 +229,33 @@


var start = function(){ var start = function(){
var context = generateOptions(); var context = generateOptions();
$('#log').innerHTML = '';
removeClass.call($('#addTorrent'), 'hidden');
addClass.call($('#retry'), 'hidden');
chrome.tabs.getSelected(null, function(tab) { chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {type:'info_hash'}, function(info_hash){ chrome.tabs.sendRequest(tab.id, {type:'info_hash'}, function(info_hash){
if(!info_hash) return error('could not determine info_hash', info_hash); if(!info_hash) return error('could not determine info_hash', info_hash);
info('determined info_hash', info_hash); info('determined info_hash', info_hash);
var success = true; 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); info('added torrent ' + JSON.stringify(torrent.name), torrent);
addTrackers.call(context, torrent, function(trackers){ addTrackers.call(context, torrent, function(trackers){
if(trackers) if(trackers)
info('added ' + trackers.length + ' additional trackers', trackers); info('added ' + trackers.length + ' additional trackers', trackers);
log('done')('done'); log('done')('done');
if(!success) removeClass.call($('retry'), 'hidden'); if(!success) removeClass.call($('#retry'), 'hidden');
removeClass.call($('close'), 'hidden'); removeClass.call($('#close'), 'hidden');
$(success ? 'close' : 'retry').focus(); $(success ? '#close' : '#retry').focus();
}); });
}); });
}); });
}); });
}; };
$('addTorrent').addEventListener('click', start); $('#addTorrent').addEventListener('click', start);
$('retry').addEventListener('click', start); $('#retry').addEventListener('click', start);


var generateOptions = function(){ var generateOptions = function(){
return return 0,
{ authentication: { authentication:
{ enabled : getOption('AuthenticationEnabled') { enabled : getOption('AuthenticationEnabled')
, encrypted : getOption('AuthenticationEncrypted') , encrypted : getOption('AuthenticationEncrypted')
Expand All @@ -262,24 +270,24 @@
} }
, sessionId: null , sessionId: null
}; };
); };


var options = generateOptions(), var options = generateOptions(),
auth = options.authentication, auth = options.authentication,
server = options.server, server = options.server,
needsDecryption = auth.enabled && auth.encrypted; needsDecryption = auth.enabled && auth.encrypted;
(needsDecryption ? removeClass : addClass).call($('symmetricKeyContainer'), 'hidden'); (needsDecryption ? removeClass : addClass).call($('#symmetricKeyContainer'), 'hidden');
if(needsDecryption) $('symmetric_key').focus(); if(needsDecryption) $('#symmetric_key').focus();
(needsDecryption ? addClass : removeClass).call($('addTorrent'), 'hidden'); //(needsDecryption ? addClass : removeClass).call($('#addTorrent'), 'hidden');
$('addTorrent').disabled = needsDecryption; $('#addTorrent').disabled = needsDecryption;
(needsDecryption ? removeClass : addClass).call($('close'), 'hidden'); (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($('#symmetricKeyContainer'), 'hidden');
addClass.call($('addTorrent'), 'hidden'); //addClass.call($('#addTorrent'), 'hidden');
$('log').innerHTML = ''; $('#log').innerHTML = '';
removeClass.call($('log'), 'hidden'); //removeClass.call($('#log'), 'hidden');


/* /*
chrome.extension.sendRequest(request, function(response){ chrome.extension.sendRequest(request, function(response){
Expand Down
Binary file modified transmissionDownload.crx
Binary file not shown.
2 changes: 1 addition & 1 deletion updateInfo.xml
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?> <?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'> <gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='kbhlogbpfllkkgignllokdlcnjohoehp'> <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> </app>
</gupdate> </gupdate>

0 comments on commit 2218a53

Please sign in to comment.