Skip to content

Commit

Permalink
lint and regex logic updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kameshsampath committed Aug 3, 2020
1 parent 03d58a4 commit bbbc254
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/css/vars.css
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,5 @@
--z-index-page-version-menu: 3;
--z-index-navbar: 4;
/* tabs */
--color-brand-black: #000000;
--color-brand-black: var(--color-black);
}
21 changes: 15 additions & 6 deletions src/js/07-userparams-behaviour.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
document.addEventListener('DOMContentLoaded', function () {
var queryString = window.location.search
var urlParams = new URLSearchParams(queryString)
var username = urlParams.get('USER')
var password = urlParams.get('PASSWORD')
var queryString = window.location.href

function getParameterByName (name, url) {
if (!url) url = queryString
name = name.replace(/[[\]]/g, '\\$&')
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)')
var results = regex.exec(url)
if (!results) return null
if (!results[2]) return ''
var val = decodeURIComponent(results[2].replace(/\+/g, ' '))
console.log(name + '=' + val)
return val
}

function walkText (node, pattern, value) {
if (node.nodeType === 3) {
Expand All @@ -21,8 +30,8 @@ document.addEventListener('DOMContentLoaded', function () {
}
}

walkText(document.body, '(%USER%|\\$USERNAME)', username)
walkText(document.body, '(%PASSWORD%|\\$PASSWORD)', password)
walkText(document.body, '(%USER%|\\$USERNAME)', getParameterByName('USER'))
walkText(document.body, '(%PASSWORD%|\\$PASSWORD)', getParameterByName('PASSWORD'))

document.querySelectorAll('.userfied-link').forEach(function (el) {
el.href += queryString
Expand Down

0 comments on commit bbbc254

Please sign in to comment.