Skip to content

Commit

Permalink
clean up getUrlQueryParam
Browse files Browse the repository at this point in the history
Remove dead getUrlQueryParam in SDK code, and also improve
implementation in example project
  • Loading branch information
jkasten2 committed Oct 25, 2023
1 parent 3a17aaa commit 688c255
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 31 deletions.
12 changes: 2 additions & 10 deletions express_webpack/amp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@
const SERVICE_WORKER_PATH = "push/onesignal/";

function getUrlQueryParam(name) {
var url = window.location.href;
// This is just to avoid case sensitiveness
url = url.toLowerCase();
// This is just to avoid case sensitiveness for query parameter name
name = name.replace(/[\[\]]/g, "\\$&").toLowerCase();
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}

const appId = getUrlQueryParam('app_id');
Expand Down
12 changes: 2 additions & 10 deletions express_webpack/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,8 @@
let showEventAlertToggleSetting = false;

function getUrlQueryParam(name) {
var url = window.location.href;
// This is just to avoid case sensitiveness
url = url.toLowerCase();
// This is just to avoid case sensitiveness for query parameter name
name = name.replace(/[\[\]]/g, "\\$&").toLowerCase();
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}

const appId = getUrlQueryParam('app_id');
Expand Down
11 changes: 0 additions & 11 deletions src/shared/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,6 @@ export function isValidUuid(uuid: string) {
return OneSignalUtils.isValidUuid(uuid);
}

export function getUrlQueryParam(name: string) {
let url = window.location.href;
url = url.toLowerCase(); // This is just to avoid case sensitiveness
name = name.replace(/[[\]]/g, '\\$&').toLowerCase(); // This is just to avoid case sensitiveness for query parameter name
const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

/**
* Wipe OneSignal-related IndexedDB data on the "correct" computed origin, but OneSignal must be initialized first to use.
*/
Expand Down

0 comments on commit 688c255

Please sign in to comment.