Fix URLs without query strings

This commit is contained in:
Les De Ridder 2016-01-18 17:30:29 +01:00
parent ba079c730b
commit e669726ed3
1 changed files with 10 additions and 3 deletions

View File

@ -33,7 +33,7 @@ chrome.pageAction.onClicked.addListener(function(tab) {
getCurrentTabUrl(function(url) { getCurrentTabUrl(function(url) {
var betterUrl = getBetterUrl(url); var betterUrl = getBetterUrl(url);
var filename = betterUrl.substr(betterUrl.lastIndexOf("/")); var filename = betterUrl.substr(betterUrl.lastIndexOf("/"));
filename = filename.substr(0, filename.indexOf('?')); filename = removeQueryString(filename);
chrome.storage.sync.get({url: '', tabbehaviour: '', copytoclipboard: false, replacebookmark: false}, function(config) { chrome.storage.sync.get({url: '', tabbehaviour: '', copytoclipboard: false, replacebookmark: false}, function(config) {
if(config.url == '') { if(config.url == '') {
@ -82,12 +82,19 @@ function getBetterUrl(url) {
return url; return url;
} }
function removeQueryString(url) {
if(url.indexOf('?') != -1) {
return url.substr(0, url.indexOf('?'));
} else {
return url;
}
}
function isCoolUrl(url) { function isCoolUrl(url) {
url = url.toLowerCase(); url = url.toLowerCase();
var extensionIndex = url.lastIndexOf('.'); var extensionIndex = url.lastIndexOf('.');
var extension = url.substr(extensionIndex + 1); var extension = removeQueryString(url.substr(extensionIndex + 1));
extension = extension.substr(0, extension.indexOf('?'));
var validExtensions = ["jpg", "jpeg", "png", "gif", "webm", "gifv", "mp4", "mp3", "ogg", "opus"]; var validExtensions = ["jpg", "jpeg", "png", "gif", "webm", "gifv", "mp4", "mp3", "ogg", "opus"];