x-undefined-2 commited on
Commit
2d130a8
·
verified ·
1 Parent(s): 6b01135

Update index.ts

Browse files
Files changed (1) hide show
  1. index.ts +16 -16
index.ts CHANGED
@@ -41,14 +41,14 @@ async function handleRequest(event) {
41
  url = url.replace(/https:(\/)*/,'https://').replace(/http:(\/)*/, 'http://')
42
  if (url.indexOf("://") == -1) {
43
  if(refer){
44
- refer = refer.replace("https://x-undefined-2-socks-server.hf.space/", "")
45
  let xref = refer.substr(0, refer.indexOf('/', 10)+1)
46
  url = xref + url;
47
  }
48
  }
49
  let domain = url.substr(0, url.indexOf('/', 10)+1);
50
  if(refer){
51
- refer = refer.replace("https://x-undefined-2-socks-server.hf.space/", "")
52
  domain = refer.substr(0, refer.indexOf('/', 10)+1)
53
  // url = domain + url
54
  }
@@ -92,7 +92,7 @@ async function handleRequest(event) {
92
  let newFr = new HTMLRewriter()
93
  .on("head", {
94
  element(element) {
95
- element.prepend(`<base href="https://x-undefined-2-socks-server.hf.space/${url}" />`, {
96
  html: true
97
  })
98
  },
@@ -102,9 +102,9 @@ async function handleRequest(event) {
102
  let href = element.getAttribute("href")
103
  if(href){
104
  if(href.indexOf("https://") == 0){
105
- element.setAttribute("href", "https://x-undefined-2-socks-server.hf.space/"+href);
106
  } else if(href[0] == '/') {
107
- element.setAttribute("href", "https://x-undefined-2-socks-server.hf.space/"+domain.substr(0, domain.lastIndexOf('/'))+href);
108
  } else {
109
  element.setAttribute("href", request.url+href);
110
  }
@@ -116,9 +116,9 @@ async function handleRequest(event) {
116
  let href = element.getAttribute("src")
117
  if(href){
118
  if(href.indexOf("https://") == 0){
119
- element.setAttribute("src", "https://x-undefined-2-socks-server.hf.space/"+href);
120
  } else if(href[0] == '/') {
121
- element.setAttribute("src", "https://x-undefined-2-socks-server.hf.space/"+domain.substr(0, domain.lastIndexOf('/'))+href);
122
  } else {
123
  element.setAttribute("src", request.url+href);
124
  }
@@ -130,9 +130,9 @@ async function handleRequest(event) {
130
  let href = element.getAttribute("src")
131
  if(href){
132
  if(href.indexOf("https://") == 0){
133
- element.setAttribute("src", "https://x-undefined-2-socks-server.hf.space/"+href);
134
  } else if(href[0] == '/') {
135
- element.setAttribute("src", "https://x-undefined-2-socks-server.hf.space/"+domain.substr(0, domain.lastIndexOf('/'))+href);
136
  } else if(href.indexOf("data:image") == 0){
137
  } else {
138
  element.setAttribute("src", request.url+href);
@@ -145,9 +145,9 @@ async function handleRequest(event) {
145
  let href = element.getAttribute("action")
146
  if(href){
147
  if(href.indexOf("https://") == 0){
148
- element.setAttribute("action", "https://x-undefined-2-socks-server.hf.space/"+href);
149
  } else if(href[0] == '/') {
150
- element.setAttribute("action", "https://x-undefined-2-socks-server.hf.space/"+domain.substr(0, domain.lastIndexOf('/'))+href);
151
  } else {
152
  element.setAttribute("action", request.url+href);
153
  }
@@ -159,9 +159,9 @@ async function handleRequest(event) {
159
  let href = element.getAttribute("href")
160
  if(href){
161
  if(href.indexOf("https://") == 0){
162
- element.setAttribute("href", "https://x-undefined-2-socks-server.hf.space/"+href);
163
  } else if(href[0] == '/') {
164
- element.setAttribute("href", "https://x-undefined-2-socks-server.hf.space/"+domain.substr(0, domain.lastIndexOf('/'))+href);
165
  } else {
166
  element.setAttribute("href", request.url+href);
167
  }
@@ -178,10 +178,10 @@ async function handleRequest(event) {
178
 
179
  for (const [key, value] of fr.headers.entries()) {
180
  if(key =="Content-Security-Policy" || key =="content-security-policy"){
181
- outHeaders.set(key, value.replaceAll("github.githubassets.com", "x-undefined-2-socks-server.hf.space github.githubassets.com").replaceAll("script-src .*?;", "script-src 'self' 'unsafe-inline';"));
182
  }
183
  }
184
- outHeaders.set("Access-Control-Allow-Origin", "x-undefined-2-socks-server.hf.space")
185
  outHeaders.set("Access-Control-Allow-Methods", "*")
186
  outHeaders.set("Access-Control-Allow-Credentials", "true")
187
 
@@ -233,7 +233,7 @@ const injectOutBody = (url, body)=>{
233
  // if(url.includes("huggingface.co") && url.endsWith("index.js")) {
234
  // let domain = url.substr(0, url.indexOf("/", 9))
235
  // console.log(body)
236
- // return body.text();//.replace(/href: \"(.*?)\"/ig, "href:\"https://x-undefined-2-socks-server.hf.space/"+domain+"$1\"")
237
  // }
238
  return body;
239
  }
 
41
  url = url.replace(/https:(\/)*/,'https://').replace(/http:(\/)*/, 'http://')
42
  if (url.indexOf("://") == -1) {
43
  if(refer){
44
+ refer = refer.replace("https://x-undefined-2-proxy-server.hf.space/", "")
45
  let xref = refer.substr(0, refer.indexOf('/', 10)+1)
46
  url = xref + url;
47
  }
48
  }
49
  let domain = url.substr(0, url.indexOf('/', 10)+1);
50
  if(refer){
51
+ refer = refer.replace("https://x-undefined-2-proxy-server.hf.space/", "")
52
  domain = refer.substr(0, refer.indexOf('/', 10)+1)
53
  // url = domain + url
54
  }
 
92
  let newFr = new HTMLRewriter()
93
  .on("head", {
94
  element(element) {
95
+ element.prepend(`<base href="https://x-undefined-2-proxy-server.hf.space/${url}" />`, {
96
  html: true
97
  })
98
  },
 
102
  let href = element.getAttribute("href")
103
  if(href){
104
  if(href.indexOf("https://") == 0){
105
+ element.setAttribute("href", "https://x-undefined-2-proxy-server.hf.space/"+href);
106
  } else if(href[0] == '/') {
107
+ element.setAttribute("href", "https://x-undefined-2-proxy-server.hf.space/"+domain.substr(0, domain.lastIndexOf('/'))+href);
108
  } else {
109
  element.setAttribute("href", request.url+href);
110
  }
 
116
  let href = element.getAttribute("src")
117
  if(href){
118
  if(href.indexOf("https://") == 0){
119
+ element.setAttribute("src", "https://x-undefined-2-proxy-server.hf.space/"+href);
120
  } else if(href[0] == '/') {
121
+ element.setAttribute("src", "https://x-undefined-2-proxy-server.hf.space/"+domain.substr(0, domain.lastIndexOf('/'))+href);
122
  } else {
123
  element.setAttribute("src", request.url+href);
124
  }
 
130
  let href = element.getAttribute("src")
131
  if(href){
132
  if(href.indexOf("https://") == 0){
133
+ element.setAttribute("src", "https://x-undefined-2-proxy-server.hf.space/"+href);
134
  } else if(href[0] == '/') {
135
+ element.setAttribute("src", "https://x-undefined-2-proxy-server.hf.space/"+domain.substr(0, domain.lastIndexOf('/'))+href);
136
  } else if(href.indexOf("data:image") == 0){
137
  } else {
138
  element.setAttribute("src", request.url+href);
 
145
  let href = element.getAttribute("action")
146
  if(href){
147
  if(href.indexOf("https://") == 0){
148
+ element.setAttribute("action", "https://x-undefined-2-proxy-server.hf.space/"+href);
149
  } else if(href[0] == '/') {
150
+ element.setAttribute("action", "https://x-undefined-2-proxy-server.hf.space/"+domain.substr(0, domain.lastIndexOf('/'))+href);
151
  } else {
152
  element.setAttribute("action", request.url+href);
153
  }
 
159
  let href = element.getAttribute("href")
160
  if(href){
161
  if(href.indexOf("https://") == 0){
162
+ element.setAttribute("href", "https://x-undefined-2-proxy-server.hf.space/"+href);
163
  } else if(href[0] == '/') {
164
+ element.setAttribute("href", "https://x-undefined-2-proxy-server.hf.space/"+domain.substr(0, domain.lastIndexOf('/'))+href);
165
  } else {
166
  element.setAttribute("href", request.url+href);
167
  }
 
178
 
179
  for (const [key, value] of fr.headers.entries()) {
180
  if(key =="Content-Security-Policy" || key =="content-security-policy"){
181
+ outHeaders.set(key, value.replaceAll("github.githubassets.com", "x-undefined-2-proxy-server.hf.space github.githubassets.com").replaceAll("script-src .*?;", "script-src 'self' 'unsafe-inline';"));
182
  }
183
  }
184
+ outHeaders.set("Access-Control-Allow-Origin", "x-undefined-2-proxy-server.hf.space")
185
  outHeaders.set("Access-Control-Allow-Methods", "*")
186
  outHeaders.set("Access-Control-Allow-Credentials", "true")
187
 
 
233
  // if(url.includes("huggingface.co") && url.endsWith("index.js")) {
234
  // let domain = url.substr(0, url.indexOf("/", 9))
235
  // console.log(body)
236
+ // return body.text();//.replace(/href: \"(.*?)\"/ig, "href:\"https://x-undefined-2-proxy-server.hf.space/"+domain+"$1\"")
237
  // }
238
  return body;
239
  }