commit 491b68c3c382e83071fae5b40102ce1c69e13ad2 Author: Alec Hoefler Date: Sat Apr 10 01:56:56 2021 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3eb8912 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.idea +.vs +.vscode + +css/ +node_modules +tmp/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f2f44b0 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Jensmemes +The new jensmem.es Website! \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..10a817c --- /dev/null +++ b/index.html @@ -0,0 +1,80 @@ + + + + + Jensmemes + + + + + + +
+ +
+ + + + + + + + \ No newline at end of file diff --git a/js/libs/md5.min.js b/js/libs/md5.min.js new file mode 100644 index 0000000..1456fcc --- /dev/null +++ b/js/libs/md5.min.js @@ -0,0 +1,2 @@ +!function(n){"use strict";function d(n,t){var r=(65535&n)+(65535&t);return(n>>16)+(t>>16)+(r>>16)<<16|65535&r}function f(n,t,r,e,o,u){return d((c=d(d(t,n),d(e,u)))<<(f=o)|c>>>32-f,r);var c,f}function l(n,t,r,e,o,u,c){return f(t&r|~t&e,n,t,o,u,c)}function v(n,t,r,e,o,u,c){return f(t&e|r&~e,n,t,o,u,c)}function g(n,t,r,e,o,u,c){return f(t^r^e,n,t,o,u,c)}function m(n,t,r,e,o,u,c){return f(r^(t|~e),n,t,o,u,c)}function i(n,t){var r,e,o,u;n[t>>5]|=128<>>9<<4)]=t;for(var c=1732584193,f=-271733879,i=-1732584194,a=271733878,h=0;h>5]>>>e%32&255);return t}function h(n){var t=[];for(t[(n.length>>2)-1]=void 0,e=0;e>5]|=(255&n.charCodeAt(e/8))<>>4&15)+r.charAt(15&t);return e}function r(n){return unescape(encodeURIComponent(n))}function o(n){return a(i(h(t=r(n)),8*t.length));var t}function u(n,t){return function(n,t){var r,e,o=h(n),u=[],c=[];for(u[15]=c[15]=void 0,16"; + document.getElementById("logout-btn").src = "https://cdn.a-hoefler.eu/apps/ebstgymidx/logout.png"; + } + }); + } + else{ + console.log("API fetch for users failed"); + } + }, + }); +} + +//Login Modal +var loginModal = document.getElementById("loginmodal"); + +// Get the button that opens the modal +var openLogin = document.getElementById("btn-logout"); + +// Get the element that closes the modal +var closeLogin = document.getElementsByClassName("loginclose")[0]; + +// When the user clicks on (x), close the modal +closeLogin.onclick = function() { + loginModal.style.display = "none"; +} + +// When the user clicks anywhere outside of the modal, close it +window.onclick = function(event) { + if (event.target == loginModal) { + loginModal.style.display = "none"; + } +} + +function logout(){ + if(!getCookie("jmtoken")){ + loginModal.style.display = "block"; + } else{ + //User is logged in + document.cookie = "jmtoken=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; + location.reload(); + } +} + + + +function login(){ + setCookie("jmtoken",document.getElementById("jmlogintoken").value,30); + location.reload(); +} + + + + + + +function setCookie(cname, cvalue, exdays) { + var d = new Date(); + d.setTime(d.getTime() + (exdays*24*60*60*1000)); + var expires = "expires="+ d.toUTCString(); + document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; + } + function getCookie(cname) { + var name = cname + "="; + var decodedCookie = decodeURIComponent(document.cookie); + var ca = decodedCookie.split(';'); + for(var i = 0; i { + addCategory(element); + }); + } +} + +xhr.open("GET", "https://api.tilera.xyz/jensmemes/v1/categories"); +xhr.send(); + +function addCategory(category){ + let optionItem = document.createElement("option"); + optionItem.setAttribute("value", category["id"]); + optionItem.innerText = category["name"]; + categorySelect.appendChild(optionItem); +} + +function updateImages(clear = false){ + if(clear){ + imagesDiv.innerHTML = ""; + offset = 0; + } + + let category = categorySelect.value + console.log("showing all elements of category " + category); + let count = 0; + console.log("offset: " + offset + " meme length: " + memes.length) + for(let i = offset; i < memes.length; i++){ + let meme = memes[i]; + if(category === meme["category"] || category === "all" && count < maxView){ + count++; + let container = document.createElement("div") + container.className = "imgContainer"; + + if(endsWithArray(meme["link"], [".mp4", ".3gp"])){ + let video = document.createElement("video") + video.setAttribute("src", meme["link"]); + video.setAttribute("controls", ""); + video.setAttribute("onerror", "imageNotFound();"); + video.setAttribute("onclick", "openImgInNewTab(this);"); + container.appendChild(video); + } else { + let image = document.createElement("img") + image.setAttribute("src", meme["link"]); + image.setAttribute("onerror", "imageNotFound(this);"); + image.setAttribute("onclick", "openImgInNewTab(this);"); + container.appendChild(image); + } + imagesDiv.appendChild(container); + + } else if(count >= maxView){ + offset = i; + return; + } + } + offset = memes.length; +} + +function endsWithArray(text = "", array = []){ + for(let i = 0; i < array.length; i++){ + if(text.endsWith(array[i])){ + return true; + } + } + return false; +} + +document.addEventListener('scroll', (event) => { + let scrollTop = (docBody.scrollTop || docElem.scrollTop); + let height = docElem.scrollHeight - docElem.clientHeight; + if(scrollTop + offsetLoadNext > height){ + updateImages(); + } +}); + +categorySelect.onchange = () => { + updateImages(true); +} + +function imageNotFound(element) { + console.log("deleting " + element.getAttribute("src") + ", because not found"); + element.parentNode.remove(); +} + +function openImgInNewTab(element){ + window.open(element.src); +} \ No newline at end of file diff --git a/js/modal.js b/js/modal.js new file mode 100644 index 0000000..231a4fb --- /dev/null +++ b/js/modal.js @@ -0,0 +1,24 @@ +var modal = document.getElementById("info"); + +// Get the button that opens the modal +var btn = document.getElementById("openInfo"); + +// Get the element that closes the modal +var span = document.getElementsByClassName("close")[0]; + +// When the user clicks the button, open the modal +btn.onclick = function() { + modal.style.display = "block"; +} + +// When the user clicks on (x), close the modal +span.onclick = function() { + modal.style.display = "none"; +} + +// When the user clicks anywhere outside of the modal, close it +window.onclick = function(event) { + if (event.target == modal) { + modal.style.display = "none"; + } +} \ No newline at end of file diff --git a/js/upload.js b/js/upload.js new file mode 100644 index 0000000..5c745bd --- /dev/null +++ b/js/upload.js @@ -0,0 +1,62 @@ +function uploadFile(){ + var fd = new FormData(); + + var ins = document.getElementById('fileToUpload').files.length; + for (var x = 0; x < ins; x++) { + fd.append("file[]", document.getElementById('fileToUpload').files[x]); + } + + fd.append('category', document.getElementById("jmcat").value) + + if(!getCookie("jmtoken")){ + fd.append('token', document.getElementById("jmtoken").value) + } else{ + //User is logged in + fd.append('token',getCookie("jmtoken")) + } + + $.ajax({ + url: 'https://data.tilera.xyz/api/jensmemes/upload', + type: 'post', + data: fd, + contentType: false, + processData: false, + success: function(response){ + if(response != 0){ + console.log("Upload Successfull") + console.log(response); + let output = document.getElementById("output"); + output.innerHTML="Upload Erfolgreich. Meme hier" + output.style.display="unset"; + + setCookie("jmtoken",response.token,30); + } + else{ + console.log("Upload Failed") + } + }, + }); + +} + +function setCookie(cname, cvalue, exdays) { + var d = new Date(); + d.setTime(d.getTime() + (exdays*24*60*60*1000)); + var expires = "expires="+ d.toUTCString(); + document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; + } + function getCookie(cname) { + var name = cname + "="; + var decodedCookie = decodeURIComponent(document.cookie); + var ca = decodedCookie.split(';'); + for(var i = 0; i