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

Prevent caching for extensions, themes, etc... #112

Merged
merged 1 commit into from
Jan 25, 2022
Merged
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
11 changes: 9 additions & 2 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,17 @@ const getParamsFromGithubRaw = (url) => {
script.defer = true;
script.src = extensionManifest.extensionURL;

const randomString = (Math.random() + 1).toString(36).substring(2);

// If it's a github raw script, use jsdelivr
if (script.src.indexOf("raw.githubusercontent.com") > -1) {
const { user, repo, branch, filePath } = getParamsFromGithubRaw(extensionManifest.extensionURL);
if (!user || !repo || !branch || !filePath) return;
script.src = `https://cdn.jsdelivr.net/gh/${user}/${repo}@${branch}/${filePath}`;
}

script.src = `${script.src}?dummy=${randomString}`

document.body.appendChild(script);
};

Expand Down Expand Up @@ -207,7 +211,8 @@ const getParamsFromGithubRaw = (url) => {
const assetsUrl = userCssUrl.replace("/user.css", "/assets/");

console.log("Parsing CSS: ", userCssUrl);
let css = await fetch(userCssUrl).then(res => res.text());
const randomString = (Math.random() + 1).toString(36).substring(2);
let css = await fetch(`${userCssUrl}?dummy=${randomString}`).then(res => res.text());
// console.log("Parsed CSS: ", css);

let urls = css.matchAll(/url\(['|"](?<path>.+?)['|"]\)/gm) || [];
Expand Down Expand Up @@ -266,16 +271,18 @@ const getParamsFromGithubRaw = (url) => {
if (themeManifest.include && themeManifest.include.length) {
// console.log("Including js", installedThemeData.include);

const randomString = (Math.random() + 1).toString(36).substring(2);
themeManifest.include.forEach((script) => {
const newScript = document.createElement("script");
let src = script;

// If it's a github raw script, use jsdelivr
if (script.indexOf("raw.githubusercontent.com") > -1) {
const { user, repo, branch, filePath } = getParamsFromGithubRaw(script);
src = `https://cdn.jsdelivr.net/gh/${user}/${repo}@${branch}/${filePath}`;
}
// console.log({src});
newScript.src = src;
newScript.src = `${src}?dummy=${randomString}`;
newScript.classList.add("marketplaceScript");
document.body.appendChild(newScript);
});
Expand Down