Skip to content

Commit

Permalink
Add a tag link logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dohyeon5626 committed Aug 18, 2024
1 parent 420cf01 commit abcdde7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ if (location.search != '') {
let url = data[0].replace("?", "");
let token = data[1];

while(document.body == null) {
console.log("document body load fail");
}

if (token) showPageWithToken(url, token);
else showPage(url);
} else {
Expand Down
29 changes: 21 additions & 8 deletions show-page-with-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,47 @@ let showPageWithToken = async (githubUrl, token) => {
document.write(
(await getContentWithToken(rawUrl, githubUrl)).replace(/<head([^>]*)>/i, `<head$1><base href="${rawUrl}">`)
);
document.close();


// CSS
while(document.querySelector("link[rel=stylesheet]:not([status=clear])")) {
let element = document.querySelector("link[rel=stylesheet]");
let element = document.querySelector("link[rel=stylesheet]:not([status=clear])");
let href = element.getAttribute("href")
if (!isPublicUrl(href)) element.outerHTML = '<style status="clear">' + await getContentWithToken(href, githubUrl) + "</style>";
else element.setAttribute("status", "clear");
}

// JS
while(document.querySelector("script[src]")) {
let element = document.querySelector("script[src]");
while(document.querySelector("script[src]:not([status=clear])")) {
let element = document.querySelector("script[src]:not([status=clear])");

let script = document.createElement('script');
let src = element.getAttribute("src")
if (!isPublicUrl(src)) {
script.innerHTML = await getContentWithToken(src, githubUrl);
script.innerHTML = "(function () {" + await getContentWithToken(src, githubUrl) + "})();";
console.log(document.body);
document.body.appendChild(script);
script.setAttribute("status", "clear");
element.remove();
window.dispatchEvent(new Event('load'));
} else element.setAttribute("status", "clear");
}
window.dispatchEvent(new Event('load'));

// <a> link
while(document.querySelector("a[href]:not([status=clear])")) {
let element = document.querySelector("a[href]:not([status=clear])");
let href = element.href;
element.setAttribute(
"href",
href.replace(
"https://gfqbuhjryx.us14.qoddiapp.com/github-content/" + token,
location.origin + location.pathname + "?https://github.com/"
) + "&" + token
);
element.setAttribute("status", "clear");
}

// TODO
// Frame
// <a> link
// @import
// loadScript()
}
Expand Down
24 changes: 18 additions & 6 deletions show-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,46 @@ let showPage = async (githubUrl) => {
document.write(
(await getContent(rawUrl)).replace(/<head([^>]*)>/i, `<head$1><base href="${rawUrl}">`)
);
document.close();

// CSS
while(document.querySelector("link[rel=stylesheet]:not([status=clear])")) {
let element = document.querySelector("link[rel=stylesheet]");
let element = document.querySelector("link[rel=stylesheet]:not([status=clear])");
let href = element.getAttribute("href")
if (!isPublicUrl(href)) element.outerHTML = '<style status="clear">' + await getContent(href) + "</style>";
else element.setAttribute("status", "clear");
}

// JS
while(document.querySelector("script[src]:not([status=clear])")) {
let element = document.querySelector("script[src]");
let element = document.querySelector("script[src]:not([status=clear])");

let script = document.createElement('script');
let src = element.getAttribute("src")
if (!isPublicUrl(src)) {
script.innerHTML = await getContent(src);
script.innerHTML = "(function () {" + await getContent(src) + "})();";
document.body.appendChild(script);
script.setAttribute("status", "clear");
element.remove();
window.dispatchEvent(new Event('load'));
} else element.setAttribute("status", "clear");
}
window.dispatchEvent(new Event('load'));

// <a> link
while(document.querySelector("a[href]:not([status=clear])")) {
let element = document.querySelector("a[href]:not([status=clear])");
let href = element.href;
element.setAttribute(
"href",
href.replace(
"https://raw.githubusercontent.com/",
location.origin + location.pathname + "?https://github.com/"
)
);
element.setAttribute("status", "clear");
}

// TODO
// Frame
// <a> link
// @import
// loadScript()
}
Expand Down

0 comments on commit abcdde7

Please sign in to comment.