diff --git a/bundle.js b/bundle.js index cb66ebb..7ddf9da 100644 --- a/bundle.js +++ b/bundle.js @@ -11884,11 +11884,11 @@ function wrappy (fn, cb) { } },{}],24:[function(require,module,exports){ +const clipboard = require('clipboard'); const parser = require('parse-torrent'); const Buffer = require('Buffer'); const bytes = require('bytes'); const mime = require('mime-types'); -const clipboard = require('clipboard'); var name = document.getElementById('name'); var creationDate = document.getElementById('creationDate'); @@ -11898,6 +11898,7 @@ var hash = document.getElementById('hash'); var trackers = document.getElementById('trackers'); var webseeds = document.getElementById('webseeds'); var files = document.getElementById('filesBody'); +var copyURL = document.getElementById('copyURL'); var copyMagnet = document.getElementById('copyMagnet'); var downloadTorrent = document.getElementById('downloadTorrent'); var parsed; @@ -11918,9 +11919,27 @@ function start() { event.target.files[0].arrayBuffer().then(arrayBuffer => parse(Buffer.from(arrayBuffer))); }); - new clipboard('#copyMagnet'); // TODO: Alert user to success + let copyurl = new clipboard('#copyURL'); + copyurl.on('success', function(e) { + console.info(e); // TODO: Alert user to success + }); + copyurl.on('failure', function(e) { + console.error(e); + }); + + let copymagnet = new clipboard('#copyMagnet'); + copymagnet.on('success', function(e) { + console.info(e); // TODO: Alert user to success + }); + copymagnet.on('failure', function(e) { + console.error(e); + }); + downloadTorrent.addEventListener('click', saveTorrent); + if (window.location.hash) parse(window.location.hash.split('#')[1]); + window.addEventListener('hashchange', function() { if (window.location.hash) parse(window.location.hash.split('#')[1]); }); + } function parse(toLoad) { @@ -11930,9 +11949,13 @@ function parse(toLoad) { display(); } catch(e) { - console.warn("That didn't work. Attempting remote parse."); + console.warn(e); + console.info("Attempting remote parse"); parser.remote(toLoad, function(err, result) { - if (err) return; // TODO: Display error to user + if (err) { // TODO: Display error to user + console.error(err); + return; + } parsed = result; display(); }); @@ -11995,6 +12018,7 @@ function display() { files.innerHTML = "Files information isn't included in the URL/File provided"; } + copyURL.setAttribute('data-clipboard-text', window.location.origin + "#" + parser.toMagnetURI(parsed)); copyMagnet.setAttribute('data-clipboard-text', parser.toMagnetURI(parsed)); } diff --git a/index.html b/index.html index 78dfcfd..e785864 100644 --- a/index.html +++ b/index.html @@ -54,6 +54,12 @@
+
+ + + + +
diff --git a/parse.js b/parse.js index df64325..210485a 100644 --- a/parse.js +++ b/parse.js @@ -1,8 +1,8 @@ +const clipboard = require('clipboard'); const parser = require('parse-torrent'); const Buffer = require('Buffer'); const bytes = require('bytes'); const mime = require('mime-types'); -const clipboard = require('clipboard'); var name = document.getElementById('name'); var creationDate = document.getElementById('creationDate'); @@ -12,6 +12,7 @@ var hash = document.getElementById('hash'); var trackers = document.getElementById('trackers'); var webseeds = document.getElementById('webseeds'); var files = document.getElementById('filesBody'); +var copyURL = document.getElementById('copyURL'); var copyMagnet = document.getElementById('copyMagnet'); var downloadTorrent = document.getElementById('downloadTorrent'); var parsed; @@ -32,9 +33,27 @@ function start() { event.target.files[0].arrayBuffer().then(arrayBuffer => parse(Buffer.from(arrayBuffer))); }); - new clipboard('#copyMagnet'); // TODO: Alert user to success + let copyurl = new clipboard('#copyURL'); + copyurl.on('success', function(e) { + console.info(e); // TODO: Alert user to success + }); + copyurl.on('failure', function(e) { + console.error(e); + }); + + let copymagnet = new clipboard('#copyMagnet'); + copymagnet.on('success', function(e) { + console.info(e); // TODO: Alert user to success + }); + copymagnet.on('failure', function(e) { + console.error(e); + }); + downloadTorrent.addEventListener('click', saveTorrent); + if (window.location.hash) parse(window.location.hash.split('#')[1]); + window.addEventListener('hashchange', function() { if (window.location.hash) parse(window.location.hash.split('#')[1]); }); + } function parse(toLoad) { @@ -44,9 +63,13 @@ function parse(toLoad) { display(); } catch(e) { - console.warn("That didn't work. Attempting remote parse."); + console.warn(e); + console.info("Attempting remote parse"); parser.remote(toLoad, function(err, result) { - if (err) return; // TODO: Display error to user + if (err) { // TODO: Display error to user + console.error(err); + return; + } parsed = result; display(); }); @@ -109,6 +132,7 @@ function display() { files.innerHTML = "Files information isn't included in the URL/File provided"; } + copyURL.setAttribute('data-clipboard-text', window.location.origin + "#" + parser.toMagnetURI(parsed)); copyMagnet.setAttribute('data-clipboard-text', parser.toMagnetURI(parsed)); }