musealpha / src-tauri /resources /scriptlets /muse_ubo_compatible_scriptlets.js
asdf98's picture
Upload 112 files
3d7d9b5 verified
/// json-prune.js
(function() {
'use strict';
const args = Array.from(arguments);
const prunePaths = (args[0] || '').split(/\s+/).filter(Boolean);
if (prunePaths.length === 0) return;
function prune(obj, path) {
if (!obj || typeof obj !== 'object') return;
const parts = path.split('.');
let target = obj;
for (let i = 0; i < parts.length - 1; i++) {
const part = parts[i];
if (part.endsWith('[]')) {
const key = part.slice(0, -2);
if (Array.isArray(target[key])) {
target[key].forEach(item => prune(item, parts.slice(i + 1).join('.')));
}
return;
}
if (!target[part]) return;
target = target[part];
}
delete target[parts[parts.length - 1]];
}
function pruneAll(obj) { for (const p of prunePaths) prune(obj, p); return obj; }
const jp = JSON.parse;
JSON.parse = function() { return pruneAll(jp.apply(this, arguments)); };
const rj = Response.prototype.json;
Response.prototype.json = function() { return rj.apply(this, arguments).then(pruneAll); };
})();
/// set-constant.js
(function() {
'use strict';
const prop = arguments[0];
const raw = arguments[1];
if (!prop) return;
let value;
if (raw === 'undefined') value = undefined;
else if (raw === 'false') value = false;
else if (raw === 'true') value = true;
else if (raw === 'null') value = null;
else value = raw;
const parts = prop.split('.');
let obj = window;
for (let i = 0; i < parts.length - 1; i++) {
obj = obj[parts[i]] = obj[parts[i]] || {};
}
try {
Object.defineProperty(obj, parts[parts.length - 1], { get: () => value, set: () => {}, configurable: true });
} catch {}
})();
/// abort-current-script.js
(function() {
'use strict';
const needle = arguments[0] || '';
const prop = arguments[1] || '';
if (!needle && !prop) return;
const re = new RegExp(needle);
const oe = document.createElement.bind(document);
document.createElement = function(tag) {
const el = oe(tag);
if (String(tag).toLowerCase() === 'script') {
const set = el.setAttribute.bind(el);
el.setAttribute = function(name, value) {
if (name === 'src' && re.test(String(value))) return;
return set(name, value);
};
}
return el;
};
})();
/// prevent-fetch.js
(function() {
'use strict';
const needle = arguments[0] || '';
if (!needle) return;
const re = new RegExp(needle);
const of = window.fetch;
window.fetch = function(input, init) {
const url = typeof input === 'string' ? input : input && input.url || '';
if (re.test(url)) return Promise.resolve(new Response('', { status: 204 }));
return of.apply(this, arguments);
};
})();
/// m3u8-prune.js
(function() {
'use strict';
const needle = arguments[0] || 'stitched-ad|advertisement|DATERANGE';
const re = new RegExp(needle);
const of = window.fetch;
window.fetch = function(input, init) {
const url = typeof input === 'string' ? input : input && input.url || '';
return of.apply(this, arguments).then(resp => {
if (!String(url).includes('.m3u8')) return resp;
return resp.clone().text().then(text => {
const out = text.split('\n').filter(line => !re.test(line)).join('\n');
return new Response(out, { status: resp.status, headers: resp.headers });
}).catch(() => resp);
});
};
})();