Compare commits

...

2 Commits

Author SHA1 Message Date
gamerdonkey 1e4de11f4c Improving display name of the game. 2022-08-19 05:28:26 +00:00
gamerdonkey 2b68db2401 Cleaning up the javascript a bit. 2022-08-19 05:27:05 +00:00
2 changed files with 10 additions and 24 deletions

View File

@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<title>WAD-LIBS</title> <title>WAKI-LIBS</title>
<style> <style>
#inputs { #inputs {
@ -60,9 +60,9 @@ button {
</style> </style>
</head> </head>
<body> <body>
<h1>WAD-LIBS: Wikipedia Ad-Libbed</h1> <h1>WAKI-LIBS: Wikipedia Ad-Libbed</h1>
<div id="inputs"></div> <div id="inputs"></div>
<p><button id="show-article">WAD-LIB!</button> <p><button id="show-article">WAKI-LIB!</button>
<div id="article"> <div id="article">
<div id="header"> <div id="header">
<span id="title"></span> <span id="title"></span>

View File

@ -1,19 +1,3 @@
function parseArticleJSON_old() {
fetch('tokens.json')
.then((article) => article.json())
.then((article_json) => {
let output = ''
article_json.forEach(function(token) {
output += `${token.token} `
})
document.getElementById('article').innerHTML = output
})
.catch((error) => {
console.log(`Error fetching article: ${error}`)
document.getELementById('article').innerHTML = 'Error'
})
}
function createInputs(article) { function createInputs(article) {
inputs = '' inputs = ''
article.tokens.forEach(function(token) { article.tokens.forEach(function(token) {
@ -30,16 +14,17 @@ function createInputs(article) {
} }
function showArticle(article) { function showArticle(article) {
document.getElementById('title').innerHTML = article.title
document.getElementById('link').innerHTML = `[ <a href='${article.url}'>Original Article</a> ]`
let output = ''
let spaceBefore = false
const noSpaceBeforeTags = new Set(['.', ',', ')', ';', ':', '!', '?', "''", 'POS']) const noSpaceBeforeTags = new Set(['.', ',', ')', ';', ':', '!', '?', "''", 'POS'])
const noSpaceBeforeTokens = new Set(["n't", ']']) const noSpaceBeforeTokens = new Set(["n't", ']'])
const noSpaceAfterTags = new Set(['(', '``']) const noSpaceAfterTags = new Set(['(', '``'])
const noSpaceAfterTokens = new Set(['[']) const noSpaceAfterTokens = new Set(['['])
article.tokens.forEach(function(token) {
document.getElementById('title').innerHTML = article.title
document.getElementById('link').innerHTML = `[ <a href='${article.url}'>Original Article</a> ]`
let output = ''
let spaceBefore = false
article.tokens.forEach(function(token) {
if(spaceBefore && !noSpaceBeforeTags.has(token.tag) && !noSpaceBeforeTokens.has(token.token)) { if(spaceBefore && !noSpaceBeforeTags.has(token.tag) && !noSpaceBeforeTokens.has(token.token)) {
output += ' ' output += ' '
} }
@ -57,6 +42,7 @@ function showArticle(article) {
spaceBefore = false spaceBefore = false
} }
}) })
document.getElementById('summary').innerHTML = output document.getElementById('summary').innerHTML = output
document.getElementById('article').classList.add('visible') document.getElementById('article').classList.add('visible')