From 9e198c18cf52b328d4bb78dc1fac0911d8f53b25 Mon Sep 17 00:00:00 2001 From: River Jiang <2126+river@users.noreply.github.com> Date: Wed, 2 Aug 2023 15:42:30 -0700 Subject: [PATCH 1/2] Update 404.html --- 404.html | 101 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/404.html b/404.html index fcfb04ba..75082295 100644 --- a/404.html +++ b/404.html @@ -15,64 +15,69 @@ /** * 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

+ From bf724ad6ed7fae3ac91ea6fa507a26fb0265b278 Mon Sep 17 00:00:00 2001 From: River Jiang <2126+river@users.noreply.github.com> Date: Wed, 2 Aug 2023 15:43:31 -0700 Subject: [PATCH 2/2] Update 404.html --- 404.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/404.html b/404.html index 75082295..d114f5f1 100644 --- a/404.html +++ b/404.html @@ -11,6 +11,8 @@ 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