From 3427034b73f63eec43dd13b8e165508a92eddaf5 Mon Sep 17 00:00:00 2001 From: Martyn Messerli Date: Sat, 14 May 2016 17:01:41 +0200 Subject: [PATCH] If name and password are specified in the query string apply them. --- manifest.json | 2 +- scripts/content/common.js | 28 +++++++++++++++++++++++++--- scripts/content/nzbindex.js | 16 ++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/manifest.json b/manifest.json index 0d91bed..53599ea 100755 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "SABconnect++", - "version": "0.6.20", + "version": "0.6.30", "description": "SABnzbd extension for Google Chrome.", "minimum_chrome_version": "23.0", "background": { diff --git a/scripts/content/common.js b/scripts/content/common.js index c02978a..a1a68bd 100644 --- a/scripts/content/common.js +++ b/scripts/content/common.js @@ -58,9 +58,9 @@ function addToSABnzbd(addLink, nzburl, mode, nice_name, category) { nzburl: nzburl, mode: mode }; - - if (typeof nice_name != 'undefined' && nice_name != null) { - request.nzbname = nice_name; + var info = getNameAndPWFromQuery(nice_name); + if (info.NamePw != 'undefined' && info.NamePw != null) { + request.nzbname = info.NamePw; } GetSetting('config_ignore_categories', function( value ) { @@ -136,4 +136,26 @@ function OnRequest( request, sender, onResponse ) } }; + +function getNameAndPWFromQuery(niceName){ + // get the name and the passwod from the query + var queryString = document.location.search; + var queryInformation = { name: niceName, password: null }; + if(queryString && queryString.length>0){ + queryString = queryString.substr(1); + } + var queries = queryString.split("&"); + queries.forEach(function(query){ + var pair = decodeURIComponent(query).split("="); + queryInformation[pair[0]] = pair[1]; + }); + + queryInformation.NamePw = queryInformation.name; + if(queryInformation.password){ + queryInformation.NamePw += "/" + queryInformation.password; + } + + return queryInformation; +}; + chrome.extension.onMessage.addListener( OnRequest ); diff --git a/scripts/content/nzbindex.js b/scripts/content/nzbindex.js index fd1c922..4d2b199 100644 --- a/scripts/content/nzbindex.js +++ b/scripts/content/nzbindex.js @@ -1,5 +1,21 @@ var use_nice_name_nzbindex; +function getNameAndPW(){ + // get the name and the passwod from the query + var queryString = document.location.search; + var queryInformation = { name: null, password: null }; + if(queryString && queryString.length>0){ + queryString = queryString.substr(1); + } + var queries = queryString.split("&"); + queries.forEach(function(query){ + var pair = query.split("="); + queryInformation[pair[0]] = pair[1]; + }); + + return queryInformation; +} + function addToSABnzbdFromNzbindex() { var addLink = this;