javascript短篇小说在线生成工具

所属分类: 网页特效-实用工具    2023-12-20 10:38:22

javascript短篇小说在线生成工具 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

javascript短篇小说在线生成工具(共3个文件)

    • index.html

使用方法

let customName = document.getElementById("customname");
let randomize = document.querySelector(".randomize");
let story = document.querySelector(".story");

let storyText =
  "It was 94 farenheit outside, so :insertx: went for a walk. When they got to :inserty:, they stared in horror for a few moments, then :insertz:. Bob saw the whole thing, but he was not surprised — :insertx: weighs 300 pounds, and it was a hot day.";
let insertX = ["Willy the Goblin", "Big Daddy", "Father Christmas"];

let insertY = ["the soup kitchen", "Disneyland", "the White House"];

let insertZ = [
  "spontaneously combusted",
  "melted into a puddle on the sidewalk",
  "turned into a slug and crawled away"
];

randomize.addEventListener("click", result);

function result() {
  let newStory = storyText;
  let xItem = randomValueFromArray(insertX);
  let yItem = randomValueFromArray(insertY);
  let zItem = randomValueFromArray(insertZ);

  newStory = newStory.replace(/:insertx:/gi, xItem);
  newStory = newStory.replace(":inserty:", yItem);
  newStory = newStory.replace(":insertz:", zItem);

  if (customName.value != "") {
    var name = customName.value;
    newStory = newStory.replace("Bob", name);
  }

  if (document.getElementById("uk").checked) {
    var weight = Math.round(300 * 0.0714);
    newStory = newStory.replace("300 pounds", weight + " stone");
    
    var temperature = Math.round((94 - 32) * 0.5556);
    newStory = newStory.replace("94 farenheit", temperature + " celcius");
  }

  story.textContent = newStory;
  story.style.visibility = "visible";
}

function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}

function randomValueFromArray(stringsCollection) {
  const randomIndex = getRandomInt(2);

  return stringsCollection[randomIndex];
}

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 实用工具

基于Vue.js科学型计算器实用工具

一款基于Vue.js的计算器插件,这款计算器功能比较强大,支持科学型的计算功能,两种模式切换:高级科学型模式、简单的基本模式。
  实用工具
 3610  0

javascript温度转换器在线工具

一个基于原生js的在线温度转换器工具,可轻松得将华氏温度转换为摄氏温度。你可在select列表中选择摄氏度或华氏度,input文本框中输入温度值,并立即转换。
  实用工具
 9792  0

jquery在线表单输入实现加减乘除运算插件

一款简单的在线表单运算插件,在两个input文本框中输入数字,然后点击任意一个运算按钮:乘法、除法、加法、减法,可实现自动计算,并且显示结果。
  实用工具
 1728  0

jquery在线树结构导航生成器插件

一款树结构导航生成器,支持在线编辑添加,实时的输出显示到页面中。
  实用工具
 3658  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论