Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>
  <section>
    <form method="#" action="#" id="name-wrapper">
      <input type="text" class="name-input" placeholder="Roger Delgado" id="name" minlength="1" maxlength="50">
      <button class="button_action" id="name-submit">Let's go!</button>
      <br />
      <label class="name-input_label" for="name">
        Enter your name
      </label>
    </form>
  </section>

  <section id="result" />
</body>
              
            
!

CSS

              
                $graphic_font: "'GraphikLC', Arial, sans-serif";
$color_ascent: "#6b00fa";
$font_roboto-md: "15px/30px -apple-system,system-ui,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif";

body {
  max-width: 70vw;
  margin: 2rem auto;
  color: black;
}

#name-wrapper {
  margin: auto;
  width: fit-content;
  label {
    font: #{$font_roboto-md}
  }
  button {
    background: #22201F;
    color: #FFFFFF;
    &:hover {
      background: #6C2EBE;
    }
    &:active {
      background: #{$color_ascent};
    }
  }
}

.name-input {
  width: 474px;
  height: 52px;
  padding: 11px;
  box-sizing: border-box;
  border-radius: 4px;
  font: #{$font_roboto-md};
  &:focus {
    outline: none;
  }
}

.book,
.soundcloud {
  &::before {
    content: "";
    height: 2px;
    display: block;
    width: 90px;
    margin: {
      top: 38px;
      bottom: 0px;
    }
    background: #030303;
  }
  margin-bottom: 36px;
  clear: both;
  width: 800px;
  text-decoration: none;
  .book-wrapper {
    display: grid;
    justify-items: center;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: 1fr;
    grid-gap: 44px;
  }
  a {
    text-decoration: none;
    color: black;
  }
  .idesc {
    display: block;
    width: 272px;
    margin-top: 17px;
    font: 20px/26px "GraphikLCRegular", -apple-technique, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
    &:empty::before {
      content: "";
      height: 20px;
      background: white;
      display: block;
      z-index: 1;
      margin-top: -30px;
    }
  }
  img {
    height: 240px;
    box-shadow: 0px 0px 16px rgba(0, 0, 0, 0.16);
    border-radius: 2px;
  }
  .babout-wrapper {
    width: 272px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
  }
  .babout {
    display: flex;
    flex-direction: column;
  }
  .btn {
    color: #4264fd;
    font: 21px/28px #{$graphic_font};
    text-decoration: none;
    transition: all 300ms ease;
    border: none;
    outline: none;
    margin: {
      top: 16px;
    }
    &:hover {
      color: black;
    }
    &::after {
      content: "";
      height: 2px;
      display: block;
      width: 52px;
      background: #3456F3;
    }
    &:hover::after {
      background: black;
    }
  }
}

.btn-audiobook::after {
  width: 86px!important;
}

.soundcloud {
  iframe {
    width: 100%;
    padding-top: 20px;
    padding-bottom: 9px;
  }
}

.group {
  margin: auto;
}

.group:before,
.group:after {
  content: "";
  display: table;
}

.group:after {
  clear: both;
}

span.ba {
  font: 20px/26px "GraphikLCRegular", -apple-technique, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
}

span.bt {
  font: bold 20px/26px #{$graphic_font};
}

@media only screen and (max-width: 900px) {
  .book,
  .soundcloud {
    width: 100%;
    margin: 0 auto 16px;
    &::before {
      display: none;
    }
    margin-bottom: 16px;
    .book-wrapper {
      grid-template-columns: 1fr;
      grid-template-rows: auto;
      grid-gap: 26px;
    }
    .idesc {
      font: 16px/24px "GraphikLCRegular", -apple-technique, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
      text-align: center;
      &:empty::before {
        display: none;
      }
    }
    .ba,
    .bt {
      display: none;
    }
    .btn {
      margin: {
        top: 0px;
        left: 39.5%;
        bottom: 26px;
      }
      font: bold 18px/28px #{$graphic_font};
      &::after {
        width: 60px!important;
        margin-left: 2px;
      }
    }
    .btn.btn-audiobook {
      margin-left: 36.5%;
      &::after {
        width: 74px!important;
      }
    }
  }
}
.book-first::before {
  content: "";
  height: 2px;
  display: block;
  background: #030303;
  width: 60px;
  margin: {
    top: 26px;
    left: 46vw;
    bottom: 10px;
  }
}

@media only screen and (max-width: 430px) {
  .book::before,
  .soundcloud::before {
    margin-left: 43vw;
  }
}

@media only screen and (max-width: 375px) {
  .book::before,
  .soundcloud::before {
    margin-left: 40vw;
  }
}

/* @media rewrites .book-first::before over .book::before even though the screen params width don't fit. Thus, we reset them */
@media only screen and (min-width: 901px) {
  .book-first::before {
    display: none;
  }
  .book,
  .soundcloud {
    &::before {
      content: "";
      height: 2px;
      display: block;
      width: 90px;
      margin: {
        top: 38px;
        bottom: 0px;
        left: 0px;
      }
      background: #030303;
    }
  }
}

.button_action {
  padding: 0px 20px;
  width: 133px;
  height: 52px;
  border: none;
  border-radius: 4px;
  margin: 8px 0px;
  font: #{$font_roboto-md};
  &:hover {
    transition: background-color 0.2s;
    cursor: pointer;
  }
  &:active {
    transition: background-color 0.2s;
  }
  &:focus {
    outline: none;
  }
}
              
            
!

JS

              
                config = {};
config.magicNumber = 666;
config.books = ['cv3DjkYS', 'Bi7lfiCK', 'OhyhN7Ss', 'thr5vySr', 'zBbanTqH', 'iycgkCFE', 'kSVENdpM', 'r8lfAIwG', 'kdv4nuUa', 'MKXv2tni', 'JHEUVw3x', 'PeIROaxq', 'RURNoLO4', 'VCvhugtf', 'hjbFKhsc', 'eZI0bRw7', 'cVku9eiF', 'GM13iw6z', 'c5KGuHWp', 'rXkF4aUM', 'nXLXRIhB', 'gCtxmCdD', 'deCLA4Ud', 'SrUbX2Xn', 'deWYQ9X3', 'C2H5NfRD', 'BjgyWcBh', 'aXvr3Q5O', 'aqSLq8Ze', 'YP82Wkmd', 'dphZVhow', 'fic45jge', 'wAlHIg5X', 'hn8TKmxp', 'X6MeapuO', 'ZaENJpAu', 'WEB8bU0D', 'uGGycx07', 'FdKaAOKZ', 'mavZYpzt', 'OSW37att', 'rGS8CYb4', 'Y1q6glzk', 'h9xtIKrO', 'Rguq7tRK', 'cGGPwrsh', 'TfvQ1i3l', 'xGnndhPp', 'Yzd2SK2U', 'pqFMYYwv', 'N9eChiJN', 'qSN9gc7W', 'NY2LvdIN', 'mdQDrKNe', 'k80eqAqE'];

const RESULT_NODE = document.getElementById("result");
const TITLE_NODE = RESULT_NODE.querySelector(".idesc");
const COVER_NODE = RESULT_NODE.querySelector("img");
const LINK_NODE = RESULT_NODE.querySelector("a");

const getSeed = (seed, max, min) => {
  max = max || 1000000000;
  min = min || 137;
  seed = (seed * 9301 + 49297) % 233280;
  var rnd = seed / 233280; 
  return Math.round(min + rnd * (max - min), 0);
}

const getNameCode = name => {
  let nameCode = [];
  for (let i = 0; i < name.length; i++) {
    nameCode.push(name.charCodeAt(i));
  }
  return nameCode;
}

const isIndexInRange = (index) => index + 1 < config.books.length;

const getBookUuid = (nameCode) => {
  const reducer = (accumulator, currentValue) => Number(accumulator) + Number(currentValue);
  let index = nameCode.reduce(reducer);
      
  if (!isIndexInRange(index)) {
    index = index.toString().split("").reduce(reducer);
  }

   return config.books[index] || config.books[0];
}

const fetchBook = (uuid) => {
  fetch(`https://bookmate.com/p/api/v5/books/${uuid}`)
    .then(response => response.json())
      .then(data => {
        const { uuid, title, cover, annotation, authors_objects } = data.book;
        const filteredAnnotation = annotation.replace(/<[^>]*>?/gm, '').replace(/\n/g, " ");

      RESULT_NODE.innerHTML = `
          <div class="book group">
            <a class="book-wrapper" href=https://ru.bookmate.com/books/${uuid} rel="noopener" target="_blank">
              <span class="idesc">${filteredAnnotation.split(" ").slice(0, 10).join(" ")}...</span>
              <img alt=${title} src=${cover.large} />
              <div class="babout-wrapper">
                <span class="babout">
                    <span class="ba">${authors_objects.map(author => author.name).join(", ")}</span>
                    <span class="bt">${title}</span>
                    <span class="btn btn-book">Read</span>
                </span>
              </div>
            </a>
          </div>`
      });
  }


const nameForm = document.getElementById("name-wrapper");

nameForm.addEventListener("submit", (event) => {
  event.preventDefault();
  const nameString = document.getElementById("name").value || "anonym";
  const nameCode = getNameCode(nameString);
  const nameSeed = getSeed(nameCode);
  const bookUuid = getBookUuid(nameCode);
  fetchBook(bookUuid)
})

              
            
!
999px

Console