Skip to content

Instantly share code, notes, and snippets.

@nosoop
Created January 26, 2019 14:51
Show Gist options
  • Save nosoop/37dce69e919235628b0724d51922b522 to your computer and use it in GitHub Desktop.
Save nosoop/37dce69e919235628b0724d51922b522 to your computer and use it in GitHub Desktop.
Temporary fix for Steam's UGC servers serving WebP images to Firefox users.
// ==UserScript==
// @name Steam Image Fixer
// @description Forces Steam to regenerate image files because their cache is serving WebP to Firefox users.
// @namespace steam-image-webp-cache-busting
// @match https://steamcommunity.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
let rewrite_image_url = (image) => {
if (image.src.includes("/ugc/")) {
let url = new URL(image.src);
if (!url.searchParams.get('shame_valve_for_serving_webp_to_unsupported_browsers')) {
url.searchParams.set('shame_valve_for_serving_webp_to_unsupported_browsers', '1');
image.src = url.href;
}
}
};
let observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.target.querySelectorAll('img').forEach(rewrite_image_url);
});
});
observer.observe(document, {
childList: true,
subtree : true,
attributes: true,
attributeFilter : ['img'],
attributeOldValue : true
});
document.addEventListener("DOMContentLoaded", (e) => {
/* fix existing images */
document.querySelectorAll("img").forEach(rewrite_image_url);
/* fix thumbnail viewer and prevent extra load because mutation handles this too late */
if (typeof rgScreenshotURLs !== 'undefined') {
Object.keys(rgScreenshotURLs).map((key, index) => {
if (!rgScreenshotURLs[key]) {
return rgScreenshotURLs[key];
}
let url = new URL(rgScreenshotURLs[key]);
if (!url.searchParams.get('shame_valve_for_serving_webp_to_unsupported_browsers')) {
url.searchParams.set('shame_valve_for_serving_webp_to_unsupported_browsers', '1');
rgScreenshotURLs[key] = url.href;
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment