[Userscript] Microsoft Remote Desktop Web Access for all
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
// ==UserScript== | |
// @name Microsoft Remote Desktop Web Access for all | |
// @namespace memmie.lenglet.name | |
// @author mems <memmie@lenglet.name> | |
// @homepageURL https://gist.github.com/mems/e7277c1118e1d876dd7333bb8c2bb49b | |
// @description Allow to use RD Web Access on browser that don't support RD ActiveX | |
// @match *://*/RDWeb/Pages/* | |
// @updateURL https://gist.github.com/mems/e7277c1118e1d876dd7333bb8c2bb49b/raw/msrdwa-for-all.user.js | |
// @version 1.0.0 | |
// ==/UserScript== | |
// Fix CSS included by JS | |
CSSStyleSheet.prototype.addRule === undefined && Array.from(document.scripts).forEach(s => {let r = /document\.styleSheets\[\d+\]\.addRule\('((?:\\'|[^'])+)',\s'((?:\\'|[^'])+)'/g; for(let m; (m = r.exec(s.text)) !== null;) document.styleSheets[0].insertRule(m[1]+"{"+m[2])+"}"}); | |
// Show the appboard and public mode checkbox | |
Array.from(document.querySelectorAll(".tswa_appboard, .tswa_PublicCheckboxLess")).forEach(el => el.style.display = !el.classList.contains("tswa_appboard") || el.id.endsWith("AppDisplay") ? "block" : "none"); | |
// Inject RDP object proxy (available only in IE with RD ActiveX) | |
const script = document.createElement('script'); | |
script.appendChild(document.createTextNode(` | |
window.MsRdpClientShell = window.MsRdpClientShell || { | |
PublicMode: true, | |
RdpFileContents: "", | |
Launch(){ | |
const settings = this.RdpFileContents.split("\\r\\n").reduce((settings, line) => { | |
if(line.trim()){ | |
const [type, ...value] = line.split(":"); | |
settings.set(type, value.join(":")); | |
} | |
return settings; | |
}, new Map()); | |
settings.set("public mode", this.PublicMode ? "i:1" : "i:0"); | |
const a = document.createElement("a"); | |
const raw = Array.from(settings).map(([key, value]) => key + ":" + value).join("\\r\\n"); | |
const url = a.href = URL.createObjectURL(new Blob([raw], {type: "application/x-rdp"})); | |
const appname = (settings.get("remoteapplicationprogram") || "").startsWith("s:||") ? settings.get("remoteapplicationprogram").substr(4) : (settings.get("remoteapplicationname") || "s:remoteapp").substr(2); | |
const wksp = (settings.get("Workspace Id") || "s:").substr(2); | |
const title = [appname, wksp].filter(v => v).join(" - "); | |
a.download = title.replace(/[\\\\\\/:\\*\\?"<>\\|]/g, "-") + ".rdp";// valid Windows filename | |
document.body.appendChild(a); | |
a.click(); | |
a.remove(); | |
this.releaseURL(url);// no retains | |
}, | |
releaseURL(url){ | |
setTimeout(() => URL.revokeObjectURL(url), 10000);// just in case | |
} | |
} | |
`)); | |
document.head.appendChild(script); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mstsc /v:12.34.45.789 /public
public mode, passwords and bitmaps are not cached%WINDIR%\system32\mstsc.exe