Last active
August 14, 2018 09:35
-
-
Save and3rson/fcc1d901e00ecab4865f84e646edc232 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getParamElements = () => Array.prototype.slice.call(document.querySelectorAll('.parameters div[name="parameter"]')); | |
var populateArgs = () => { | |
if (getParamElements().length) { | |
var match, | |
pl = /\+/g, // Regex for replacing addition symbol with a space | |
search = /([^&=]+)=?([^&]*)/g, | |
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }, | |
query = window.location.search.substring(1); | |
urlParams = {}; | |
while (match = search.exec(query)) | |
urlParams[decode(match[1])] = decode(match[2]); | |
getParamElements().forEach(el => { | |
var nameEl = el.querySelector('[name="name"]'); | |
var valueEl = el.querySelector('[name="value"]'); | |
if (urlParams.hasOwnProperty(nameEl.value)) { | |
valueEl.value = urlParams[nameEl.value]; | |
} | |
}); | |
} else { | |
setTimeout(populateArgs, 250); | |
} | |
}; | |
window.addEventListener('ready', populateArgs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment