diff --git a/show-page-with-token.js b/show-page-with-token.js
index eedb0a3..c04c024 100644
--- a/show-page-with-token.js
+++ b/show-page-with-token.js
@@ -3,9 +3,13 @@ let showPageWithToken = async (githubUrl, token) => {
// HTML
document.open();
- document.write(
- (await getContentWithToken(rawUrl, githubUrl)).replace(/
]*)>/i, ``)
- );
+ document.write(await getDocumentContentWithToken(rawUrl, githubUrl));
+ if(!document.head.querySelector('base')) {
+ let base = document.createElement('base');
+ base.href = rawUrl;
+ document.head.appendChild(base);
+ }
+ document.close();
// CSS
while(document.querySelector("link[rel=stylesheet]:not([status=clear])")) {
@@ -51,7 +55,7 @@ let showPageWithToken = async (githubUrl, token) => {
// loadScript()
}
-let getContentWithToken = (rawUrl, githubUrl) => {
+let getDocumentContentWithToken = (rawUrl, githubUrl) => {
return new Promise((resolve) => {
fetch(rawUrl)
.then(res => {
@@ -61,4 +65,16 @@ let getContentWithToken = (rawUrl, githubUrl) => {
.then(text => resolve(text))
.catch(() => showPage(githubUrl))
});
+}
+
+let getContentWithToken = (rawUrl, githubUrl) => {
+ return new Promise((resolve) => {
+ fetch(rawUrl)
+ .then(res => {
+ if (!res.ok) throw new Error('400 or 500 에러 발생')
+ return res.text()
+ })
+ .then(text => resolve(text))
+ .catch(() => resolve(''))
+ });
}
\ No newline at end of file
diff --git a/show-page.js b/show-page.js
index 98b9965..b74b43f 100644
--- a/show-page.js
+++ b/show-page.js
@@ -1,5 +1,6 @@
let showErrorPage = () => {
- document.body.innerHTML = `
+ document.open();
+ document.write(`
404 Not Found
@@ -14,7 +15,8 @@ let showErrorPage = () => {
- `;
+ `);
+ document.close();
let token = location.href.split("&")[1];
if (token) document.getElementById("token-input").value = token;
@@ -32,9 +34,13 @@ let showPage = async (githubUrl) => {
// HTML
document.open();
- document.write(
- (await getContent(rawUrl)).replace(/]*)>/i, ``)
- );
+ document.write(await getDocumentContent(rawUrl));
+ if(!document.head.querySelector('base')) {
+ let base = document.createElement('base');
+ base.href = rawUrl;
+ document.head.appendChild(base);
+ }
+ document.close();
// CSS
while(document.querySelector("link[rel=stylesheet]:not([status=clear])")) {
@@ -79,7 +85,7 @@ let showPage = async (githubUrl) => {
// loadScript()
}
-let getContent = (rawUrl) => {
+let getDocumentContent = (rawUrl) => {
return new Promise((resolve) => {
fetch(rawUrl)
.then(res => {
@@ -89,4 +95,16 @@ let getContent = (rawUrl) => {
.then(text => resolve(text))
.catch(() => showErrorPage())
});
+}
+
+let getContent = (rawUrl) => {
+ return new Promise((resolve) => {
+ fetch(rawUrl)
+ .then(res => {
+ if (!res.ok) throw new Error('400 or 500 에러 발생')
+ return res.text()
+ })
+ .then(text => resolve(text))
+ .catch(() => resolve(''))
+ });
}
\ No newline at end of file