Files
WingetRepoServer/public/script.js
2024-06-23 12:20:50 +03:00

158 lines
5.4 KiB
JavaScript

function copyValue(elementId) {
/* Get the text field */
var copyText = document.getElementById(elementId).innerText;
/* Create a temporary input field */
var tempInput = document.createElement("input");
tempInput.value = copyText;
document.body.appendChild(tempInput);
/* Select the text field */
tempInput.select();
tempInput.setSelectionRange(0, 99999); /* For mobile devices */
console.log(copyText);
/* Copy the text inside the text field */
navigator.clipboard.writeText(copyText);
/* Remove the temporary input field */
document.body.removeChild(tempInput);
/* Show a toast message */
var toast = document.createElement("div");
toast.innerText = "Copied to clipboard!";
toast.style.position = "fixed";
toast.style.bottom = "20px";
toast.style.left = "50%";
toast.style.transform = "translateX(-50%)";
toast.style.background = "#673AB7";
toast.style.color = "#ffffff";
toast.style.padding = "10px";
toast.style.borderRadius = "5px";
document.body.appendChild(toast);
/* Remove the toast message after 3 seconds */
setTimeout(function () {
document.body.removeChild(toast);
}, 3000);
}
function showAndHide(elementId,liId){
let element = document.getElementById(elementId);
let li = document.getElementById(liId);
element.classList.contains('hiddencopy')? element.classList.remove('hiddencopy'):element.classList.add('hiddencopy');
element.classList.contains('hiddencopy')? li.classList.remove('clicked'):li.classList.add('clicked');
}
function replaceHebrew(elementId, stff){
let element = document.getElementById(elementId);
if (stff == 'Administrative staff'){
element.innerText = "מותר לשימוש בידי צוות מנהלי";
}
else if(stff == 'Students')
{
element.innerText = "מותר לשימוש בידי סטודנטים";
}
}
function insertWarning(elementId, before, lang="en"){
if (elementId == true){
if(lang == "he"){
console.log('fuck');
let elem = document.createElement("div");
elem.id = "התראה";
elem.innerText = "הבהרה: המסך החכם של מיקרוסופט ימנע את ריצת התוכנה. יש ללחוץ על פרטים נוספים -> אפשר";
elem.style.color="#ffffff";
let nodebefore = document.getElementById(before);
nodebefore.insertBefore(elem, nodebefore.children[7])
}
else{
console.log('fuck');
let elem = document.createElement("div");
elem.id = "Warning";
elem.innerText = "Warning: Has Microsoft SmartScreen blue window of block from running. Press more details -> Allow Running";
elem.style.color="#ffffff";
let nodebefore = document.getElementById(before);
nodebefore.insertBefore(elem, nodebefore.children[7])
}
}
}
function downloadValue(elementId, filename){
let text = document.getElementById(elementId).innerText;
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function scriptPackage(rowid, extracommand, line){
let text = `winget install ${rowid} -s huji`;
console.log(extracommand)
let fub = extracommand.match(/\s?&&/)
fub = fub==null?-1:fub.index
console.log(`fub in row: ${rowid}, is ${fub}`)
console.log(`extra command in line ${rowid}, has more than 2 lenght? ${extracommand.length < 2}. lenght${extracommand.length}`)
try{
console.log(text)
if(fub == 0){
text += extracommand;
}
else if((extracommand.length > 2) && !(extracommand.match(/nil/))){
text = extracommand + " && " + text;
}
else if ((fub == -1))
{
text = text;
}
}
catch{
text = text;
}
document.getElementById(`id-${line}`).innerHTML = text;
}
function convertHtml(dt){
return dt.replace("")
}
function showContainer(className){
classShow = document.getElementsByClassName(className)[0];
classShow.style.display = classShow.style.display=="flex"?"none":"flex";
}
function runme(data){
alert(data)
}
function fetchContent(uri) {
return fetch(uri)
.then(response => response.json())
.catch(error => console.error('Error:', error));
}
function updateForm(uri, eid){
fetchContent(uri).then(content => {
switch(eid){
case "PackageIdentifier":{
document.getElementById("PackageIdentifier").value=content.Identifier
break
}
case "PackageVersion":{
document.getElementById("PackageVersion").value=content.Version
break
}
case "InstallerType":{
document.getElementById("InstallerType").value=content.Type
break
}
case "InstallerUrl":{
document.getElementById("InstallerUrl").value=content.Url
break
}
case "InstallerSha256":{
document.getElementById("InstallerSha256").value=content.Checksum
break
}
}
console.log(content)
})
}