From 50f0e14a9cf737aac64d43330278cbf42a3edf29 Mon Sep 17 00:00:00 2001 From: Prakhar Gurunani Date: Sun, 23 Jan 2022 20:44:57 +0530 Subject: [PATCH] fix: invalid URL pattern when https/http is not included --- Chrome/js/background.js | 13 +++++++++---- Firefox/js/background.js | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Chrome/js/background.js b/Chrome/js/background.js index 2ed79be..212e1e4 100644 --- a/Chrome/js/background.js +++ b/Chrome/js/background.js @@ -3,13 +3,18 @@ chrome.alarms.onAlarm.addListener(function(alarm) { if (alarmName.slice(0, 6) !== 'Delete' && ((new Date().getTime() - alarm.scheduledTime) < 200 )) { var url = `${alarmName.split('-')[3]}-${alarmName.split('-')[4]}-${alarmName.split('-')[5]}`; chrome.tabs.query({ - url: url + url: (url.includes('https') || url.includes('http')) ? url : `https://${url}` }, function(tabs) { if (tabs.length === 0) { - chrome.tabs.create({ url:url, active: true }); + if (url.includes('https') || url.includes('http')){ + chrome.tabs.create({ url:url, active: true }); + } + else { + chrome.tabs.create({url:`https://${url}`, active: true}) + } chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { if (changeInfo.status === 'complete') { - chrome.tabs.query({url: `${url}*`}, function(tabs) { + chrome.tabs.query({url: (url.includes('https') || url.includes('http')) ? `${url}` : `https://${url}`}, function(tabs) { try { chrome.scripting.executeScript({ target: { tabId: tabs[0].id }, @@ -37,7 +42,7 @@ chrome.alarms.onAlarm.addListener(function(alarm) { else if (alarmName.slice(0, 6) === 'Delete' && (new Date().getTime() - alarm.scheduledTime) < 200 ) { var url = `${alarmName.split('-')[4]}-${alarmName.split('-')[5]}-${alarmName.split('-')[6]}`; try { - chrome.tabs.query({url: `${url}*`}, function(tabs) { + chrome.tabs.query({url: (url.includes('https') || url.includes('http')) ? url : `https://${url}`}, function(tabs) { try { chrome.scripting.executeScript({ target: { tabId: tabs[0].id }, diff --git a/Firefox/js/background.js b/Firefox/js/background.js index db6fa7f..5b26d40 100644 --- a/Firefox/js/background.js +++ b/Firefox/js/background.js @@ -3,13 +3,18 @@ browser.alarms.onAlarm.addListener(function(alarm) { if (alarmName.slice(0, 6) !== 'Delete' && ((new Date().getTime() - alarm.scheduledTime) < 200 )) { var url = `${alarmName.split('-')[3]}-${alarmName.split('-')[4]}-${alarmName.split('-')[5]}`; browser.tabs.query({ - url: url + url: (url.includes('https') || url.includes('http')) ? url : `https://${url}` }, function(tabs) { if (tabs.length === 0) { - browser.tabs.create({ url:url, active: true }); + if (url.includes('https') || url.includes('http')){ + browser.tabs.create({ url:url, active: true }); + } + else { + browser.tabs.create({url:`https://${url}`, active: true}) + } browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { if (changeInfo.status === 'complete') { - browser.tabs.query({url: `${url}*`}, function(tabs) { + browser.tabs.query({url: (url.includes('https') || url.includes('http')) ? `${url}` : `https://${url}`}, function(tabs) { try { browser.tabs.executeScript( tabs.id, { @@ -37,7 +42,7 @@ browser.alarms.onAlarm.addListener(function(alarm) { else if (alarmName.slice(0, 6) === 'Delete' && (new Date().getTime() - alarm.scheduledTime) < 200 ) { var url = `${alarmName.split('-')[4]}-${alarmName.split('-')[5]}-${alarmName.split('-')[6]}`; try { - browser.tabs.query({url: `${url}*`}, function(tabs) { + browser.tabs.query({url: (url.includes('https') || url.includes('http')) ? url : `https://${url}`}, function(tabs) { try { browser.tabs.executeScript( tabs.id, {