Skip to content

Instantly share code, notes, and snippets.

@TylerTemp
Created July 16, 2026 13:59
Show Gist options
  • Select an option

  • Save TylerTemp/d191ab25450ca45e10d2e3a2ef7ec48f to your computer and use it in GitHub Desktop.

Select an option

Save TylerTemp/d191ab25450ca45e10d2e3a2ef7ec48f to your computer and use it in GitHub Desktop.
Unity Asset Store CDN Fix
// ==UserScript==
// @name Unity Asset Store CDN Fix
// @namespace local.assetstore.cdnfix
// @version 1.0.1
// @description Rewrite Unity Asset Store China CDN URLs to global CDN
// @match https://assetstore.unity.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function () {
'use strict';
function fixUrl(value) {
if (!value || typeof value !== 'string') return value;
return value
.replace(/https?:\/\/assetstore-cdn-china\.unitychina\.cn\/cdn-origin/gi,
'https://unity-assetstorev2-prd.storage.googleapis.com/cdn-origin')
.replace(/\/\/assetstore-cdn-china\.unitychina\.cn\/cdn-origin/gi,
'https://unity-assetstorev2-prd.storage.googleapis.com/cdn-origin')
.replace(/https?:\/\/assetstore-cdn-china-v1\.unitychina\.cn/gi,
'https://assetstorev1-prd-cdn.unity3d.com')
.replace(/\/\/assetstore-cdn-china-v1\.unitychina\.cn/gi,
'https://assetstorev1-prd-cdn.unity3d.com');
}
function fixElement(el) {
if (!el || el.nodeType !== 1 || !el.getAttribute) return;
// Rewrite every attribute, including data-src, data-srcset, style, poster, etc.
for (var i = 0; i < el.attributes.length; i++) {
var attr = el.attributes[i];
var oldValue = attr.value;
var newValue = fixUrl(oldValue);
if (newValue && newValue !== oldValue) {
el.setAttribute(attr.name, newValue);
}
}
// Rewrite inline scripts/styles/text carriers.
if (
(el.tagName === 'SCRIPT' || el.tagName === 'STYLE' || el.tagName === 'NOSCRIPT') &&
el.textContent &&
el.textContent.indexOf('unitychina.cn') !== -1
) {
el.textContent = fixUrl(el.textContent);
}
}
function fixTree(root) {
fixElement(root);
if (!root || !root.querySelectorAll) return;
var nodes = root.querySelectorAll('*');
for (var i = 0; i < nodes.length; i++) {
fixElement(nodes[i]);
}
}
var rawSetAttribute = Element.prototype.setAttribute;
Element.prototype.setAttribute = function (name, value) {
return rawSetAttribute.call(this, name, fixUrl(value));
};
try {
Object.defineProperty(window, 'webpack_public_path', {
configurable: true,
get: function () {
return window.__fixed_webpack_public_path;
},
set: function (value) {
window.__fixed_webpack_public_path = fixUrl(value);
}
});
} catch (e) {}
var observer = new MutationObserver(function (records) {
records.forEach(function (record) {
if (record.type === 'attributes') {
fixElement(record.target);
}
for (var i = 0; i < record.addedNodes.length; i++) {
fixTree(record.addedNodes[i]);
}
});
});
observer.observe(document.documentElement, {
childList: true,
subtree: true,
attributes: true
});
fixTree(document.documentElement);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment