Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use request query parameters instead of hash for getting username #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
// Shows the presentation page if there's no hash
if (location.hash === "#" || location.hash === "") {
var searchParams = new URLSearchParams(location.search);

// Shows the landing page if there's no hash or no "u" query parameter
if ((location.hash === "#" || location.hash === "") && searchParams.get("u") === null){
location.href = "landing";
}


// If there's a hash AND no "u" query parameter
if (location.hash !== "" && location.hash !== "#" && searchParams.get("u") === null) {
// Set the query parameters to have the username as "u"
location.search = "?u=" + location.hash.substr(1, location.hash.length);
// Remove the hash completely (no #)
// From https://stackoverflow.com/a/4508751
history.pushState("", document.title, location.pathname + location.search);
}

// The variables
var oldHash = location.hash;
var avatar = document.getElementById("avatar");
Expand All @@ -11,7 +23,7 @@ var country = document.getElementById("country");
var bio = document.getElementById("bio");
var statusPar = document.getElementById("status");
var viewProfile = document.getElementById("view-profile-link");
var username = location.hash.substr(1, location.hash.length);
var username = searchParams.get("u");
var featuredImg = document.getElementById("featured-img");
var featuredA = document.getElementById("featured-project-a");
var featuredTitle = document.getElementById("featured-project-title");
Expand Down