tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

file_bug1742865.sjs (2310B)


      1 function handleRequest(request, response) {
      2   if (request.queryString == "reset") {
      3     setState("index", "0");
      4     response.setStatusLine(request.httpVersion, 200, "Ok");
      5     response.write("Reset");
      6     return;
      7   }
      8 
      9   let refresh = "";
     10   let index = Number(getState("index"));
     11   // index == 0 First load, returns first meta refresh
     12   // index == 1 Second load, caused by first meta refresh, returns second meta refresh
     13   // index == 2 Third load, caused by second meta refresh, doesn't return a meta refresh
     14   let query = new URLSearchParams(request.queryString);
     15   if (index < 2) {
     16     refresh = query.get("seconds");
     17     if (query.get("crossOrigin") == "true") {
     18       const hosts = ["example.org", "example.com"];
     19 
     20       let url = `${request.scheme}://${hosts[index]}${request.path}?${request.queryString}`;
     21       refresh += `; url=${url}`;
     22     }
     23     refresh = `<meta http-equiv="Refresh" content="${refresh}">`;
     24   }
     25   // We want to scroll for the first load, and check that the meta refreshes keep the same
     26   // scroll position.
     27   let scroll = index == 0 ? `scrollTo(0, ${query.get("scrollTo")});` : "";
     28 
     29   setState("index", String(index + 1));
     30 
     31   response.write(
     32     `<!DOCTYPE html>
     33 <html>
     34 <head>
     35   <meta charset="utf-8">
     36   <meta http-equiv="Cache-Control" content="no-cache">
     37   ${refresh}
     38   <script>
     39     window.addEventListener("pageshow", () => {
     40       ${scroll}
     41       window.top.opener.postMessage({
     42         commandType: "pageShow",
     43         commandData: {
     44           inputValue: document.getElementById("input").value,
     45           scrollPosition: window.scrollY,
     46         },
     47       }, "*");
     48     });
     49     window.addEventListener("message", ({ data }) => {
     50       if (data == "changeInputValue") {
     51         document.getElementById("input").value = "1234";
     52         window.top.opener.postMessage({
     53           commandType: "onChangedInputValue",
     54           commandData: {
     55             historyLength: history.length,
     56             inputValue: document.getElementById("input").value,
     57           },
     58         }, "*");
     59       } else if (data == "loadNext") {
     60         location.href += "&loadnext=1";
     61       } else if (data == "back") {
     62         history.back();
     63       }
     64     });
     65   </script>
     66 </head>
     67 <body>
     68 <input type="text" id="input" value="initial"></input>
     69 <div style='height: 9000px;'></div>
     70 <p>
     71 </p>
     72 </body>
     73 </html>`
     74   );
     75 }