Created
March 23, 2016 16:28
-
-
Save ststeiger/5038a51b739bcff9abde to your computer and use it in GitHub Desktop.
Modify a HTTP/HTTPS-Link
This file contains hidden or 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
| class LinkModifier { | |
| m_originalLink: string; | |
| m_baseUrl:string; | |
| m_vars: string[]; | |
| constructor(link: string) { | |
| this.m_originalLink = link; | |
| this.getUrlVars(this.m_originalLink); | |
| console.log(this.m_vars); | |
| } | |
| // Read a page's GET URL variables and return them as an associative array. | |
| private getUrlVars = (urlHref:string) => | |
| { | |
| var posParam:number= urlHref.indexOf('?') | |
| ,hash:string[] | |
| ,hashes:string[] | |
| ,i:number | |
| ; | |
| this.m_vars = []; | |
| posParam = urlHref.indexOf('?'); | |
| this.m_baseUrl = urlHref.substr(0, posParam); | |
| hashes = urlHref.slice(posParam + 1).split('&'); | |
| for (i = 0; i < hashes.length; i++) | |
| { | |
| hash = hashes[i].split('='); | |
| this.m_vars.push(hash[0]); | |
| this.m_vars[hash[0]] = hash[1]; | |
| } // Next i | |
| return this.m_vars; | |
| } // End Function getUrlVars | |
| public setKey = (key:string, value:string) => | |
| { | |
| if(typeof(this.m_vars[key]) === "undefined") | |
| this.m_vars.push(key); | |
| this.m_vars[key] = value; | |
| } | |
| public zeroApertureLink = () => | |
| { | |
| this.setKey("dx", "0") | |
| this.setKey("dy", "0") | |
| this.setKey("xlr", "0") | |
| this.setKey("ylr", "0") | |
| this.setKey("xul", "0") | |
| this.setKey("yul", "0") | |
| return this; | |
| } | |
| public reassemble = () => | |
| { | |
| var newUrl:string = this.m_baseUrl; | |
| for (var i = 0; i < this.m_vars.length; ++i) | |
| { | |
| if (i == 0) | |
| newUrl += "?" + this.m_vars[i] + "=" + this.m_vars[this.m_vars[i]]; | |
| else | |
| newUrl += "&" + this.m_vars[i] + "=" + this.m_vars[this.m_vars[i]]; | |
| } // Next i | |
| return newUrl; | |
| } | |
| } | |
| // Begin TESTING | |
| function WriteLine(text:string) | |
| { | |
| document.body.appendChild(document.createTextNode(text)); | |
| document.body.appendChild(document.createElement("br")); | |
| } | |
| var s:string="http://VMJuliusBaer/ApWebServices/ApDrawingPDFs.aspx?p=JuliusBaer_Portal_DE&d=6612_GB01_OG02_0000&L=RaumNutzung&S=Nutzungsart&SEL=0000000002P2000URG&F=PDF"; | |
| s = "http://vmjuliusbaer/ApWebServices/ApDrawingPDFs.aspx?p=JuliusBaer_Portal_DE&d=6612_GB01_OG02_0000&xlr=59.886098762886604&ylr=15.116451999999999&yul=-24.363888&xul=-7.393284762886594&dx=1653&dy=970&L=RaumNutzung&S=Nutzungsart&SEL=0000000002P2000URG&F=PDF"; | |
| WriteLine((new LinkModifier(s)).zeroApertureLink().reassemble()); | |
| var x = (new LinkModifier( (<HTMLLinkElement>document.getElementById('pdffile')).href)).zeroApertureLink().reassemble(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment