css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <html>

<head>
  <link href="https://fonts.googleapis.com/css?family=Roboto+Condensed:300,400" rel="stylesheet">
</head>

<body>
  <div class="container">
    <div class="logo">Protobar</div>
    <input type="text" class="text-input" placeholder="Enter the first 2 chars of your heart's desire..." onkeyup="sortResults(this)" />
    <div class="list-container"></div>
  </div>
</body>

</html>
            
          
!
            
              body {
  color: white;
  background-color: #263238;
  font-size: 24px;
  font-family: "Roboto Condensed", sans-serif;
}

a {
  color: #ddd;
  font-weight: 300;
  text-decoration: none;
}

a:hover {
  color: white;
  text-decoration: underline;
}

.container {
  margin: 0 auto;
  width: 960px;
}

.list-container {
  align-items: left;
  display: inline-flex;
  flex-direction: column;
  padding-top: 2rem;
  width: 100%;
}

.list-container a {
  padding: 0.25rem;
  flex-grow: 1;
  width: 100%;
}

.logo {
  margin: 2rem auto;
  font-size: 100px;
}

.text-input {
  background-color: #37474f;
  border: solid 1px #90a4ae;
  clear: both;
  color: white;
  display: block;
  font-size: 24px;
  padding: 1rem;
  width: 100%;
}

            
          
!
            
              var configuration = [
  {
    title: "Star Wars: A New Hope",
    url: "http://www.imdb.com/title/tt0076759/",
    tags: ["IMDB"]
  },
  {
    title: "Star Wars: The Empire Strikes Back",
    url: "http://www.imdb.com/title/tt0080684/",
    tags: ["IMDB"]
  },
  {
    title: "Star Wars: Return of the Jedi",
    url: "http://www.imdb.com/title/tt0086190/",
    tags: ["IMDB"]
  },
  {
    title: "Star Wars: The Phantom Menace",
    url: "http://www.imdb.com/title/tt0120915/",
    tags: ["IMDB"]
  },
  {
    title: "Star Wars: Attack of the Clones",
    url: "http://www.imdb.com/title/tt0121765/",
    tags: ["IMDB"]
  },
  {
    title: "Star Wars: Revenge of the Sith",
    url: "http://www.imdb.com/title/tt0121766/",
    tags: ["IMDB"]
  },
  {
    title: "Stargate: SG-1",
    url: "http://www.imdb.com/title/tt0118480/",
    tags: ["IMDB"]
  },
  {
    title: "Stargate: Atlantis",
    url: "http://www.imdb.com/title/tt0374455",
    tags: ["IMDB"]
  },
  {
    title: "Stargate: Universe",
    url: "http://www.imdb.com/title/tt1286039",
    tags: ["IMDB"]
  },
  {
    title: "Star Trek: The Original Series",
    url: "https://www.netflix.com/title/70136140",
    tags: ["Netflix"]
  },
  {
    title: "Star Trek: The Next Generation",
    url: "https://www.netflix.com/title/70158329",
    tags: ["Netflix"]
  },
  {
    title: "Star Trek: Discovery",
    url: "https://www.netflix.com/nz/title/80126024",
    tags: ["Netflix"]
  },
  {
    title: "Star Trek: Deep Space Nine",
    url: "https://www.netflix.com/title/70158330",
    tags: ["Netflix"]
  },
  {
    title: "Star Trek: Voyager",
    url: "https://www.netflix.com/title/70158331",
    tags: ["Netflix"]
  },
  {
    title: "Star Trek: Enterprise",
    url: "https://www.netflix.com/title/70158332",
    tags: ["Netflix"]
  }
];

function render(config) {
  var container = document.querySelector(".list-container");
  // Clear Old Links
  Array.from(container.childNodes).forEach(child =>
    container.removeChild(child)
  );

  // Add New Links
  var total = config.length;
  config.forEach((element, index) => {
    // Build Styled Bookmark Title
    var linkText = document.createElement("span");
    linkText.innerText = element.title;
    linkText.style.transform = "scale(" + (1 - 0.5 * (index + 1) / total) + ")";

    // Build Styled Link URL
    var linkUrl = document.createElement("span");
    linkUrl.innerText = "(" + element.url + ")";
    linkUrl.style.transform = "scale(" + (1 - 0.5 * (index + 2) / total) + ")";
    linkUrl.style.opacity = 0.7;

    // Build Clickable Styled Link Element with Title and URL
    var link = document.createElement("a");
    link.href = element.url;
    link.target = "_blank";
    link.style.opacity = 1 - 0.5 * (index + 1) / total;
    link.appendChild(linkText);
    link.appendChild(linkUrl);

    // Add it to the document to make it visible
    container.appendChild(link);
  });
}

function sortResults(input) {
  var newConfig = configuration.map(item => {
    item.score = compareTwoStrings(
      (input.value || "").toLowerCase(),
      (item.title || "").toLowerCase()
    );
    return item;
  });
  newConfig.sort((a, b) => b.score - a.score);
  render(newConfig);
}

window.onload = () =>
  render(configuration.sort((a, b) => a.title.localeCompare(b.title)));

function compareTwoStrings(string1, string2) {
  // Algorithm from: https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Dice%27s_coefficient#Javascript
  var intersection = 0;
  var length1 = string1.length - 1;
  var length2 = string2.length - 1;
  if (length1 < 1 || length2 < 1) return 0;
  var bigrams2 = [];
  for (var i = 0; i < length2; i++) {
    bigrams2.push(string2.substr(i, 2));
  }
  for (var i = 0; i < length1; i++) {
    var bigram1 = string1.substr(i, 2);
    for (var j = 0; j < length2; j++) {
      if (bigram1 == bigrams2[j]) {
        intersection++;
        bigrams2[j] = null;
        break;
      }
    }
  }
  return 2.0 * intersection / (length1 + length2);
}

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console