aboutsummaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-03-15 21:11:29 -0400
committerBobby <[email protected]>2022-03-15 21:11:29 -0400
commit1ff9e1bda92ba4e568962bde517a489d3ffd9254 (patch)
treec2b708be7bee80d245e13412c46844d862cb3aa5 /static
parenta4c3fd260d8cdcfd459e9a83db367ed5faea2ca1 (diff)
downloadluciferreeves.github.io-1ff9e1bda92ba4e568962bde517a489d3ffd9254.tar.xz
luciferreeves.github.io-1ff9e1bda92ba4e568962bde517a489d3ffd9254.zip
move js code to separate files, update links
Diffstat (limited to 'static')
-rw-r--r--static/assets/js/pages/about.js42
-rw-r--r--static/assets/js/pages/admin.js28
-rw-r--r--static/assets/js/pages/repositories.js147
3 files changed, 217 insertions, 0 deletions
diff --git a/static/assets/js/pages/about.js b/static/assets/js/pages/about.js
new file mode 100644
index 0000000..a40fe09
--- /dev/null
+++ b/static/assets/js/pages/about.js
@@ -0,0 +1,42 @@
+let c = document.createElement("canvas");
+ctx = c.getContext("2d");
+let img1 = new Image();
+
+img1.onload = function () {
+ document.getElementById("imageAvatar").remove();
+
+ w = img1.width;
+ h = img1.height;
+
+ c.width = w;
+ c.height = h;
+ ctx.drawImage(img1, 0, 0);
+
+ var pixelArr = ctx.getImageData(0, 0, w, h).data;
+ sample_size = 8;
+
+ for (let y = 0; y < h; y += sample_size) {
+ for (let x = 0; x < w; x += sample_size) {
+ let p = (x + y * w) * 4;
+ ctx.fillStyle =
+ "rgba(" +
+ pixelArr[p] +
+ "," +
+ pixelArr[p + 1] +
+ "," +
+ pixelArr[p + 2] +
+ "," +
+ pixelArr[p + 3] +
+ ")";
+ ctx.fillRect(x, y, sample_size, sample_size);
+ }
+ }
+
+ let img2 = new Image();
+ img2.src = c.toDataURL("image/jpeg");
+ img2.width = 192;
+ img2.height = 192;
+ document.getElementById("avatar").appendChild(img2);
+};
+
+img1.src = document.getElementById("imageAvatar").src;
diff --git a/static/assets/js/pages/admin.js b/static/assets/js/pages/admin.js
new file mode 100644
index 0000000..5f88cfc
--- /dev/null
+++ b/static/assets/js/pages/admin.js
@@ -0,0 +1,28 @@
+window.addEventListener("DOMContentLoaded", () => {
+ const firebaseConfig = {
+ apiKey: "AIzaSyBCmKUnEmm8hLR9ZcFWPYbYiplbP6yUzfU",
+ authDomain: "thatcomputerscientist-e9cf2.firebaseapp.com",
+ projectId: "thatcomputerscientist-e9cf2",
+ storageBucket: "thatcomputerscientist-e9cf2.appspot.com",
+ messagingSenderId: "178402875544",
+ appId: "1:178402875544:web:8c9d8880d3ef495a5658ed",
+ measurementId: "G-JECWWZG5J6",
+ };
+ firebase.initializeApp(firebaseConfig);
+ const signInButton = document.getElementById("signInButton");
+ signInButton.addEventListener("click", () => {
+ const email = document.getElementById("inputEmail").value;
+ const password = document.getElementById("inputPassword").value;
+ firebase
+ .auth()
+ .signInWithEmailAndPassword(email, password)
+ .then((user) => {
+ window.location.assign("/admin/dashboard");
+ });
+ });
+ firebase.auth().onAuthStateChanged((user) => {
+ if (user) {
+ window.location.assign("/admin/dashboard");
+ }
+ });
+});
diff --git a/static/assets/js/pages/repositories.js b/static/assets/js/pages/repositories.js
new file mode 100644
index 0000000..66fd80c
--- /dev/null
+++ b/static/assets/js/pages/repositories.js
@@ -0,0 +1,147 @@
+const repos = document.getElementById("repos");
+const page = window.location.search.split("page=")[1] || 1;
+
+function nextPage() {
+ window.location.href = `?page=${parseInt(page) + 1}`;
+}
+
+function prevPage() {
+ window.location.href = `?page=${parseInt(page) - 1}`;
+}
+
+// Get the repositories from 'api/repos'
+$.getJSON(`api/repos?page=${page}`, function (data) {
+ if (page == 1) {
+ document.getElementById("olderTop").classList.add("disabled");
+ document.getElementById("olderBottom").classList.add("disabled");
+ } else {
+ document.getElementById("olderTop").classList.remove("disabled");
+ document.getElementById("olderBottom").classList.remove("disabled");
+ document.getElementById("olderTop").addEventListener("click", prevPage);
+ document.getElementById("olderBottom").addEventListener("click", prevPage);
+ }
+ console.log(data);
+ if (data.countNext == 0) {
+ document.getElementById("newerTop").classList.add("disabled");
+ document.getElementById("newerBottom").classList.add("disabled");
+ } else {
+ document.getElementById("newerTop").classList.remove("disabled");
+ document.getElementById("newerBottom").classList.remove("disabled");
+ document.getElementById("newerTop").addEventListener("click", nextPage);
+ document.getElementById("newerBottom").addEventListener("click", nextPage);
+ }
+ const repositories = data.repositories;
+ repositories.forEach((repo) => {
+ const leadParagraphCotainer = document.createElement("p");
+ leadParagraphCotainer.className = "lead";
+ const repoName = repo.name;
+ const repoLink = repo.html_url;
+ const repoDescription = repo.description;
+ const repoLanguage = repo.language || "No language";
+ const repoStars = repo.stars;
+ const repoForks = repo.forks;
+ const license = repo.license;
+
+ const nameContainer = document.createElement("h3");
+ nameContainer.innerHTML = repoName;
+ const descriptionContainer = document.createElement("p");
+ descriptionContainer.innerHTML = repoDescription;
+ const languageAndLicenseContainer = document.createElement("div");
+ const languageBadgeContainer = document.createElement("span");
+ languageBadgeContainer.className = "badge badge-warning";
+ languageBadgeContainer.innerHTML = repoLanguage;
+ const licenseBadgeContainer = document.createElement("span");
+ licenseBadgeContainer.className = "badge badge-info";
+ licenseBadgeContainer.style.marginLeft = "10px";
+ licenseBadgeContainer.innerHTML = license;
+ languageAndLicenseContainer.appendChild(languageBadgeContainer);
+ languageAndLicenseContainer.appendChild(licenseBadgeContainer);
+ languageAndLicenseContainer.style.marginBottom = "10px";
+ const starsAndForksContainer = document.createElement("div");
+ const starsContainer = document.createElement("span");
+ const starIcon = document.createElement("i");
+ starIcon.classList.add("tcs-icon", "star", "is-small");
+ starsContainer.appendChild(starIcon);
+ starsContainer.innerHTML += " " + repoStars + " Stars";
+ const forksContainer = document.createElement("span");
+ forksContainer.innerHTML += " " + repoForks + " Forks";
+ starsAndForksContainer.appendChild(starsContainer);
+ starsAndForksContainer.appendChild(forksContainer);
+ starsAndForksContainer.style.marginBottom = "10px";
+ const repoLinkContainer = document.createElement("p");
+ const repoLinkAnchor = document.createElement("a");
+ repoLinkAnchor.href = repoLink;
+ repoLinkAnchor.innerHTML = "View on Github";
+ repoLinkContainer.appendChild(repoLinkAnchor);
+ leadParagraphCotainer.appendChild(nameContainer);
+ leadParagraphCotainer.appendChild(descriptionContainer);
+ leadParagraphCotainer.appendChild(languageAndLicenseContainer);
+ leadParagraphCotainer.appendChild(starsAndForksContainer);
+ leadParagraphCotainer.appendChild(repoLinkContainer);
+ repos.appendChild(leadParagraphCotainer);
+ });
+});
+const userData = document.getElementById("userData");
+// Get the user data from 'api/user'
+$.getJSON("api/user", function (data) {
+ const userAvatar = document.createElement("img");
+ userAvatar.src = data.user.avatar;
+ userAvatar.className = "img-polaroid";
+ userAvatar.style.width = "100%";
+ userData.appendChild(userAvatar);
+ const strong = document.createElement("strong");
+ const userName = document.createElement("h2");
+ userName.innerHTML = data.user.name;
+ userName.style.color = "#000";
+ strong.appendChild(userName);
+ userData.appendChild(strong);
+ const userBio = document.createElement("p");
+ userBio.innerHTML = data.user.bio;
+ userBio.style.color = "#000";
+ userData.appendChild(userBio);
+ const followerContainer = document.createElement("p");
+ followerContainer.style.color = "#000";
+ const followerIcon = document.createElement("i");
+ followerIcon.classList.add("tcs-icon", "trophy", "is-small");
+ followerContainer.appendChild(followerIcon);
+ const followerText = document.createElement("span");
+ followerText.innerHTML = "&emsp;" + data.user.followers + " Followers";
+ followerContainer.appendChild(followerText);
+ userData.appendChild(followerContainer);
+ const twParagraph = document.createElement("p");
+ twParagraph.style.color = "#000";
+ const twitterIcon = document.createElement("i");
+ twitterIcon.classList.add("tcs-icon", "twitter", "is-small");
+ twParagraph.appendChild(twitterIcon);
+ const twitterText = document.createElement("span");
+ const ts2 = document.createElement("span");
+ ts2.innerHTML = "&emsp;";
+ twitterText.appendChild(ts2);
+ const twitterContainer = document.createElement("a");
+ twitterContainer.style.color = "#db4437";
+ twitterContainer.classList.add("a-hvr");
+ twitterContainer.href = "https://twitter.com/" + data.user.twitter;
+ twitterContainer.target = "_blank";
+ twitterContainer.innerHTML = data.user.twitter;
+ twitterText.appendChild(twitterContainer);
+ twParagraph.appendChild(twitterText);
+ userData.appendChild(twParagraph);
+ const ghParagraph = document.createElement("p");
+ ghParagraph.style.color = "#000";
+ const githubIcon = document.createElement("i");
+ githubIcon.classList.add("tcs-icon", "github", "is-small");
+ ghParagraph.appendChild(githubIcon);
+ const githubText = document.createElement("span");
+ const ts3 = document.createElement("span");
+ ts3.innerHTML = "&emsp;";
+ githubText.appendChild(ts3);
+ const githubContainer = document.createElement("a");
+ githubContainer.style.color = "#db4437";
+ githubContainer.classList.add("a-hvr");
+ githubContainer.href = data.user.url;
+ githubContainer.target = "_blank";
+ githubContainer.innerHTML = data.user.login;
+ githubText.appendChild(githubContainer);
+ ghParagraph.appendChild(githubText);
+ userData.appendChild(ghParagraph);
+});