mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-14 12:20:02 -04:00
Heroku/Repl.it fix?
This commit is contained in:
parent
73cdcb3186
commit
2cbcaebca8
44 changed files with 1097 additions and 35748 deletions
|
@ -1,4 +1,4 @@
|
|||
/*const route = [
|
||||
const route = [
|
||||
{
|
||||
types: ['text/html'],
|
||||
handler: 'html',
|
||||
|
@ -22,61 +22,15 @@ function rewriteBody(ctx) {
|
|||
|
||||
switch(data.handler) {
|
||||
case 'html':
|
||||
ctx.body = ctx.rewrite.html.process.bind(ctx.rewrite.html)(ctx.body.toString(), { meta, document: true });
|
||||
ctx.body = ctx.rewrite.html.process(ctx.body.toString(), { ...meta, document: true });
|
||||
break;
|
||||
case 'css':
|
||||
ctx.body = ctx.rewrite.css.process(ctx.body.toString(), { meta });
|
||||
ctx.body = ctx.rewrite.css.process(ctx.body.toString(), meta);
|
||||
break;
|
||||
case 'js':
|
||||
ctx.body = ctx.rewrite.js.process(ctx.body.toString(), ctx.url);
|
||||
break;
|
||||
};
|
||||
};
|
||||
*/
|
||||
|
||||
const map = [
|
||||
{
|
||||
condition: ctx => {
|
||||
if (!ctx.contentType && !ctx.extension) return false;
|
||||
if (ctx.contentType && !['application/javascript', 'application/x-javascript', 'text/javascript', 'text/x-javascript'].includes(ctx.contentType)) return false;
|
||||
if (ctx.extension != 'js') return false;
|
||||
return true;
|
||||
},
|
||||
run: (ctx) => ctx.rewrite.js.process(ctx.body.toString()),
|
||||
},
|
||||
{
|
||||
condition: ctx => {
|
||||
if (!ctx.contentType && !ctx.extension) return false;
|
||||
if (ctx.contentType && ctx.contentType != 'text/css') return false;
|
||||
if (ctx.extension != 'css') return false;
|
||||
return true;
|
||||
},
|
||||
run: (ctx, meta) => ctx.rewrite.css.process(ctx.body.toString(), { meta, }),
|
||||
},
|
||||
{
|
||||
condition: ctx => {
|
||||
if (ctx.contentType && ctx.contentType != 'text/html') return false;
|
||||
if (ctx.extension && !['html', 'htm'].includes(ctx.extension)) return false;
|
||||
return true;
|
||||
},
|
||||
run: (ctx, meta) => ctx.rewrite.html.process.bind(ctx.rewrite.html)(ctx.body.toString(), { meta, document: true })
|
||||
},
|
||||
];
|
||||
|
||||
function rewriteBody(ctx) {
|
||||
if (!ctx.body || !ctx.remoteResponse || ctx.flags.includes('xhr')) return;
|
||||
const meta = {
|
||||
base: ctx.url,
|
||||
origin: ctx.origin,
|
||||
};
|
||||
ctx.contentType = (ctx.headers['content-type'] || '').split(';')[0];
|
||||
ctx.extension = ctx.url.pathname.includes('.') ? ctx.url.pathname.split('.').slice(-1)[0] : '';
|
||||
for (const entry of map) {
|
||||
if (entry.condition(ctx, meta)) {
|
||||
ctx.body = entry.run(ctx, meta);
|
||||
break;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = rewriteBody;
|
Loading…
Add table
Add a link
Reference in a new issue