diff --git a/404.html b/404.html index fcfb04ba..d114f5f1 100644 --- a/404.html +++ b/404.html @@ -11,68 +11,75 @@ var GITHUB_ISSUES_LINK = "https://api.github.com/repos/nelsontky/gh-pages-url-shortener-db/issues/"; var PATH_SEGMENTS_TO_SKIP = 0; + // Github username (will only redirect for issues by this user) + var ME = ""; /** * DO NOT TOUCH ANYTHING BELOW THIS COMMENT UNLESS YOU KNOW WHAT YOU ARE DOING */ + + function isNumeric(num){ return !isNaN(num) } function isUrl(url) { // Regex from https://stackoverflow.com/a/3809435, with a modification to allow for TLDs of up to 24 characters - return /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,24}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)+$/.test( - url - ); + return /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,24}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)+$/.test(url); } - function redirect() { - var location = window.location; - var issueNumber = location.pathname.split("/")[ - PATH_SEGMENTS_TO_SKIP + 1 - ]; - var homepage = - location.protocol + - "//" + - location.hostname + - (location.port ? ":" + location.port : "") + - "/" + - location.pathname.split("/")[PATH_SEGMENTS_TO_SKIP]; - - var xhr = new XMLHttpRequest(); - - xhr.onload = function () { - try { - var payload = JSON.parse(xhr.response); - var message = payload.message; - var title = payload.title; - - // Workaround IE 11 lack of support for new URL() - var url = document.createElement("a"); - url.setAttribute("href", title); + var isQuery = window.location.href.substr(-1) == "?"; + var keyword = window.location.pathname.split("/")[PATH_SEGMENTS_TO_SKIP + 1]; - // Invalid URLs includes invalid issue numbers, issue titles that are not URLs, and recursive destination URLs - var isInvalidUrl = - message === "Not Found" || - !title || - !isUrl(title) || - url.hostname === location.hostname; - - if (isInvalidUrl) { - location.replace(homepage); - } else { - location.replace(title); + var xhr = new XMLHttpRequest(); + xhr.onload = function () { + var payload = JSON.parse(xhr.response); + var issue = ""; + + // keyword is issue number + if (isNumeric(keyword)) { + issue = payload; + // keyword is shortened url name + } else { + for (var i=0; i - + +

404

+