2024-04-05 17:00:13 +02:00
|
|
|
function escapeHTML(source) {
|
|
|
|
return source.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/[\r\n]/g, "<br/>");
|
|
|
|
}
|
|
|
|
|
|
|
|
function decodeHTML(html) {
|
|
|
|
var txt = document.createElement("textarea");
|
|
|
|
txt.innerHTML = html;
|
|
|
|
return txt.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
var tabs = [
|
|
|
|
{
|
|
|
|
name: "GNU/Linux",
|
2024-04-07 05:39:57 +02:00
|
|
|
command: "curl -fsSL https://downloads.svrjs.org/installer/svr.js.installer.linux.20240405.sh > /tmp/installer.sh && sudo bash /tmp/installer.sh",
|
2024-04-05 17:00:13 +02:00
|
|
|
uaRegex: /\b(?:GNU\/)?Linux\b/gi
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
if (tabs.length > 0) {
|
|
|
|
var otherTab = document.getElementById("command-tab-other");
|
|
|
|
var otherTabOuterHTML = otherTab.outerHTML;
|
|
|
|
var tabsHTML = "";
|
|
|
|
var tabToClick = tabs.length;
|
|
|
|
for (var i = 0; i <= tabs.length; i++) {
|
|
|
|
tabsHTML += "<span class=\"command-tab\" id=\"command-tab-" + i + "\">";
|
|
|
|
if (i == tabs.length) {
|
|
|
|
tabsHTML += "Manually";
|
|
|
|
} else {
|
|
|
|
tabsHTML += escapeHTML(tabs[i].name);
|
|
|
|
}
|
|
|
|
tabsHTML += "</span>";
|
|
|
|
if (tabToClick == tabs.length && i != tabs.length && navigator.userAgent.match(tabs[i].uaRegex)) tabToClick = i;
|
|
|
|
}
|
|
|
|
otherTab.outerHTML = "<div id=\"command-tab-tabcontainer\">" + tabsHTML + "</div><div id=\"command-tab-container\"></div>";
|
|
|
|
var tabContainer = document.getElementById("command-tab-container");
|
|
|
|
for (var i = 0; i <= tabs.length; i++) {
|
|
|
|
document.getElementById("command-tab-" + i).onclick = createTabClickHandler(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyHandler() {
|
|
|
|
if (navigator.clipboard) {
|
|
|
|
navigator.clipboard.writeText(decodeHTML(document.getElementById("command-tab-command").innerHTML));
|
|
|
|
} else {
|
|
|
|
if (document.selection) {
|
|
|
|
var range = document.body.createTextRange();
|
|
|
|
range.moveToElementText(document.getElementById("command-tab-command"));
|
|
|
|
range.select();
|
|
|
|
} else if (window.getSelection) {
|
|
|
|
var range = document.createRange();
|
|
|
|
range.selectNode(document.getElementById("command-tab-command"));
|
|
|
|
window.getSelection().removeAllRanges();
|
|
|
|
window.getSelection().addRange(range);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.execCommand("copy");
|
|
|
|
|
|
|
|
if (document.selection) {
|
|
|
|
document.selection.empty();
|
|
|
|
} else if (window.getSelection) {
|
|
|
|
window.getSelection().removeAllRanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
document.getElementById("command-tab-copy").innerHTML = "Copied!";
|
|
|
|
}
|
|
|
|
|
|
|
|
function createTabClickHandler(i) {
|
|
|
|
return function () {
|
|
|
|
for (var j = 0; j <= tabs.length; j++) {
|
|
|
|
document.getElementById("command-tab-" + j).className = "command-tab";
|
|
|
|
}
|
|
|
|
document.getElementById("command-tab-" + i).className = "command-tab command-tab-selected";
|
|
|
|
var container = document.getElementById("command-tab-container");
|
|
|
|
if (i == tabs.length) {
|
|
|
|
container.innerHTML = otherTabOuterHTML;
|
|
|
|
} else {
|
2024-04-06 14:18:38 +02:00
|
|
|
container.innerHTML = "<div id=\"command-tab-h\">Install SVR.JS</div><div id=\"command-tab-copy\">Copy</div><code id=\"command-tab-command\" translate=\"no\">" + escapeHTML(tabs[i].command) + "</code><div class=\"command-tab-clearfix\"></div>";
|
2024-04-05 17:00:13 +02:00
|
|
|
document.getElementById("command-tab-copy").onclick = copyHandler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
document.getElementById("command-tab-" + tabToClick).click();
|
|
|
|
}
|