tor-browser

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

html_curl-utils.html (4016B)


      1 <!-- Any copyright is dedicated to the Public Domain.
      2     http://creativecommons.org/publicdomain/zero/1.0/ -->
      3 <!doctype html>
      4 
      5 <html>
      6  <head>
      7    <meta charset="utf-8"/>
      8    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
      9    <meta http-equiv="Pragma" content="no-cache" />
     10    <meta http-equiv="Expires" content="0" />
     11    <title>Network Monitor test page</title>
     12  </head>
     13 
     14  <body>
     15    <p>Performing requests</p>
     16 
     17    <p>
     18      <canvas width="100" height="100"></canvas>
     19    </p>
     20 
     21    <hr/>
     22 
     23    <form method="post" action="#" enctype="multipart/form-data" target="target" id="post-form">
     24      <input type="text" name="param1" value="value1"/>
     25      <input type="text" name="param2" value="value2"/>
     26      <input type="text" name="param3" value="value3"/>
     27      <input type="submit"/>
     28    </form>
     29    <iframe name="target"></iframe>
     30 
     31    <script type="text/javascript">
     32      /* exported performRequests */
     33      /* eslint-disable max-nested-callbacks */
     34      "use strict";
     35 
     36      function ajaxGet(url, callback) {
     37        const xhr = new XMLHttpRequest();
     38        xhr.open("GET", url + "?param1=value1&param2=value2&param3=value3", true);
     39        xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
     40        xhr.onload = function() {
     41          callback();
     42        };
     43        xhr.send();
     44      }
     45 
     46      function ajaxPost(url, callback) {
     47        const xhr = new XMLHttpRequest();
     48        xhr.open("POST", url, true);
     49        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
     50        xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
     51        xhr.onload = function() {
     52          callback();
     53        };
     54        const params = "param1=value1&param2=value2&param3=value3";
     55        xhr.send(params);
     56      }
     57 
     58      function ajaxPostJson(url, callback) {
     59        const xhr = new XMLHttpRequest();
     60        xhr.open("POST", url, true);
     61        xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
     62        xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
     63        xhr.onload = function() {
     64          callback();
     65        };
     66        const params = {
     67          param1: "value1",
     68          param2: "value2",
     69        };
     70        const jsonParams = JSON.stringify(params);
     71        xhr.send(jsonParams);
     72      }
     73 
     74      function ajaxPatch(url, callback) {
     75        const xhr = new XMLHttpRequest();
     76        xhr.open("PATCH", url, true);
     77        xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
     78        xhr.onload = function() {
     79          callback();
     80        };
     81        const params = "param1=value1&param2=value2&param3=value3";
     82        xhr.send(params);
     83      }
     84 
     85      function ajaxMultipart(url, callback) {
     86        const xhr = new XMLHttpRequest();
     87        xhr.open("POST", url, true);
     88        xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
     89        xhr.onload = function() {
     90          callback();
     91        };
     92 
     93        getCanvasElem().toBlob((blob) => {
     94          const formData = new FormData();
     95          formData.append("param1", "value1");
     96          formData.append("file", blob, "filename.png");
     97          xhr.send(formData);
     98        });
     99      }
    100 
    101      function submitForm() {
    102        const form = document.querySelector("#post-form");
    103        form.submit();
    104      }
    105 
    106      function getCanvasElem() {
    107        return document.querySelector("canvas");
    108      }
    109 
    110      function initCanvas() {
    111        const canvas = getCanvasElem();
    112        const ctx = canvas.getContext("2d");
    113        ctx.fillRect(0, 0, 100, 100);
    114        ctx.clearRect(20, 20, 60, 60);
    115        ctx.strokeRect(25, 25, 50, 50);
    116      }
    117 
    118      function performRequests(url) {
    119        ajaxGet(url, () => {
    120          ajaxPost(url, () => {
    121            ajaxPostJson(url, () => {
    122              ajaxPatch(url, () => {
    123                ajaxMultipart(url, () => {
    124                  submitForm();
    125                });
    126              });
    127            });
    128          });
    129        });
    130      }
    131 
    132      initCanvas();
    133    </script>
    134  </body>
    135 
    136 </html>