Skip to content

Edit current URL parameters (GET arguments)

vvch edited this page Jan 11, 2020 · 2 revisions

From issue #4, this custom action will create a pop-up with the current URL's page arguments and allow you to edit them before posting the edited query off.

E.g., of the form http://www.example.com/some.cgi?arg1=value1&arg2=value2&arg3=value3

TBD addition and removal of args, renaming of arg. names.

Code

url = window.location.href.split("?")
args = url[1].split("&")

div = document.createElement("div")
div.id = "__div_"
document.getElementsByTagName("body")[0].appendChild(div)

div.style = "position:fixed;width:75%;height:75%;border:2px solid;border-radius:8px;top:12.5%;left:12.5%;z-index:1000000;background:#fff;padding:1em"

inner = `<p><span>Host</span><br><input style="width:95%" id="__srv_" type="text" value="${url[0]}">`
for (let idx in Object.keys(args))
{
    let pair = args[idx].split("=")
    inner += `<p><span id="__key_${idx}_">${pair[0]}</span><br><input style="width:95%" id="__val_${idx}_" type="text" value="${pair[1]}">`
}

apply = "let div=document.getElementById(\'__div_\'),targ=document.getElementById(\'__srv_\').value+\'?\',idx=-1;for(;;){let a=document.getElementById(`__key_${++idx}_`);if(!a)break;0<idx&&(targ+=\'&\'),targ+=a.innerText+\'=\'+document.getElementById(`__val_${idx}_`).value}window.location.href=targ"
inner += `<p><input type="button" value="Go" onclick="${apply}">`

// function __apply__()
// {
//     let div = document.getElementById("__div_")
//     let targ = document.getElementById("__srv_").value + "?"
//     let idx = -1
//     while (1)
//     {
//         let key = document.getElementById(`__key_${++idx}_`)
//         if (!key)
//             break
//         if (idx > 0)
//             targ += "&"
//         targ += key.innerText + "=" + document.getElementById(`__val_${idx}_`).value
//     }
//     alert(targ)
//     //window.location.href = targ
// }

div.innerHTML = inner

Minified version

javascript:for(let a in url=window.location.href.split("?"),args=url[1].split("&"),div=document.createElement("div"),div.id="__div_",document.getElementsByTagName("body")[0].appendChild(div),div.style="position:fixed;width:75%;height:75%;border:2px solid;border-radius:8px;top:12.5%;left:12.5%;z-index:1000000;background:#fff;padding:1em",inner=`<p><span>Host</span><br><input style="width:95%" id="__srv_" type="text" value="${url[0]}">`,Object.keys(args)){let b=args[a].split("=");inner+=`<p><span id="__key_${a}_">${b[0]}</span><br><input style="width:95%" id="__val_${a}_" type="text" value="${b[1]}">`}apply="let div=document.getElementById('__div_'),targ=document.getElementById('__srv_').value+'?',idx=-1;for(;;){let a=document.getElementById(`__key_${++idx}_`);if(!a)break;0<idx&&(targ+='&'),targ+=a.innerText+'='+document.getElementById(`__val_${idx}_`).value}window.location.href=targ",inner+=`<p><input type="button" value="Go" onclick="${apply}">`,div.innerHTML=inner

Problems

  • No scrolling when too many parameters
  • No option to escape from the parameters dialog and return to the already opened page
Clone this wiki locally