---
sitemap: false
---

<!DOCTYPE html>
<html>
  <head>
    <title>Add filtering cookie</title>
    <script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
  </head>
  <body>
    <h1>User Category</h1>
    <p>
      This browser's user category is <span id="userCategory">unknown</span>.
    </p>
    <p>
      <button onclick="setUserCategory('Anonymous')">Set to Anonymous</button>
      <button onclick="setUserCategory('Administrator')">
        Set to Administrator
      </button>
    </p>
    <script>
      function getUserCategory() {
        const userCategory = Cookies.get("UserCategory")
        if (userCategory == null) {
          return "Anonymous"
        }
        return userCategory
      }

      function setUserCategory(userCategory) {
        if (userCategory === "Anonymous") {
          Cookies.remove("UserCategory")
          return
        }
        Cookies.set("UserCategory", userCategory, { expires: 10 * 365 })

        window.location.reload(true)
      }

      function updateDisplayedCategory() {
        document.getElementById("userCategory").innerText = getUserCategory()
      }

      updateDisplayedCategory()
    </script>
  </body>
</html>

---
sitemap: false
---

<!DOCTYPE html>
<html>
  <head>
    <title>Add filtering cookie</title>
    <link rel="icon" type="image/png" href="/images/jan-aagaard.png" />
    <link
      rel="stylesheet"
      href="/css/main.css?{{ site.time | date: '%s%N' }}"
    />
    <script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
  </head>
  <body>
    <h1>User Category</h1>
    <p>
      This browser's user category is <span id="userCategory">unknown</span>.
    </p>
    <p>
      <button onclick="setUserCategory('Anonymous')">Set to Anonymous</button>
      <button onclick="setUserCategory('Administrator')">
        Set to Administrator
      </button>
    </p>
    <script>
      function getUserCategory() {
        const userCategory = Cookies.get("UserCategory")
        if (userCategory == null) {
          return "Anonymous"
        }
        return userCategory
      }

      function setUserCategory(userCategory) {
        if (userCategory === "Anonymous") {
          Cookies.remove("UserCategory")
          return
        }
        Cookies.set("UserCategory", userCategory, { expires: 10 * 365 })

        window.location.reload(true)
      }

      function updateDisplayedCategory() {
        document.getElementById("userCategory").innerText = getUserCategory()
      }

      updateDisplayedCategory()
    </script>
  </body>
</html>

Add style sheet and favicon
Add style sheet and favicon
