Skip to content

Commit

Permalink
to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
taisukef committed Jul 11, 2024
1 parent 23fa737 commit ff9c73a
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 135 deletions.
226 changes: 226 additions & 0 deletions data/197_sabakan.csv

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions fukuno.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Array.prototype.remove = function(o) {
}
};

var get = function(id) {
export var get = function(id) {
return document.getElementById(id);
};
var create = function(tag, cls) {
export var create = function(tag, cls) {
var res = document.createElement(tag);
if (cls != null)
res.className = cls;
Expand All @@ -41,7 +41,7 @@ var removeAllChild = function(div) {
div.removeChild(div.lastChild);
}
};
var rnd = function(n) {
export var rnd = function(n) {
return Math.floor(Math.random() * n);
};
var shuffle = function(array) {
Expand Down Expand Up @@ -191,7 +191,7 @@ var ajax = function(url, callback) {
xhr.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
xhr.send(data);
};
var xml2json = function(xml) { // attribute無視、名前重なったら配列化
var xml2json = function(xml) { // attribute�����A���O�d�Ȃ�����z��
var f = function(xml) {
var json = {};
var text = [];
Expand Down
111 changes: 0 additions & 111 deletions help2.js

This file was deleted.

19 changes: 10 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<link rel="apple-touch-icon" href="muno.jpg"/>
<title>muno3</title>
<meta property="og:image" content="http://fukuno.jig.jp/2013/muno3.jpg"/>
<script src="fukuno.js"></script><script src="help2.js"></script>
<script src="waka100.js"></script>
<script src="muno.js"></script>
<script>"use strict";
<script type="module">
import { Muno } from "./muno.js";
import { get, create } from "./fukuno.js";

window.onload = function() {
var setWindow = function() {
var p = get("log");
Expand All @@ -36,18 +36,19 @@
var muno = new Muno(function(s) {
println("ムノー>" + s);
});
get("form").onsubmit = function() {
try {
get("form").onsubmit = function(e) {
e.preventDefault();
//try {
var s = get("in").value;
var maxlen = 1000;
if (s.length > maxlen)
s = s.substring(0, maxlen);
println("あなた>" + s);
muno.input(s);
get("in").value = "";
} catch (e) {
alert(e);
}
//} catch (e) {
//alert(e);
//}
return false;
};
muno.output("ぼくは人工無脳のムノーです。");
Expand Down
39 changes: 30 additions & 9 deletions muno.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// ムノーくん

var Muno = function(outputcallback) {
import { CSV } from "https://code4fukui.github.io/CSV/CSV.js";
import { getWaka, getWakas } from "./waka100.js";
import { rnd } from "./fukuno.js";

export var Muno = function(outputcallback) {
this.outputcb = outputcallback;
var said = [];
var muno = this;
Expand All @@ -21,7 +25,7 @@ var Muno = function(outputcallback) {
};
this.greeting();
this.log = function(s, b) {
jsonp("/2013/muno-log.js?s=" + encodeURIComponent(s) + "-" + b);
//jsonp("/2013/muno-log.js?s=" + encodeURIComponent(s) + "-" + b);
};
this.normalize = function(s) {
var s2 = "";
Expand Down Expand Up @@ -245,7 +249,7 @@ var Muno = function(outputcallback) {
];
// 今年30歳の人の干支は?
this.when = function(s) {
if (s.startsWith("今何時") || s.startsWith("いまなんじ")) {
if (s.startsWith("今何時") || s.startsWith("いまなんじ") || s.startsWith("何時")) {
var d = new Date();
this.output("今は" + d.getHours() + "時" + d.getMinutes() + "分です");
return true;
Expand Down Expand Up @@ -499,12 +503,19 @@ var Muno = function(outputcallback) {
}
};
this.sabakan = function(s) {
if (s.indexOf("鯖江") === -1)
return false;
if (!this.sabakanmode) {
if (s.indexOf("鯖江") === -1)
return false;
s = undefined;
this.sabakanmode = true;
} else {
const saba = muno.data[rnd(muno.data.length)];
this.output("鯖江で" + saba.カテゴリ + "といえば、" + saba.名称 + "!");
setTimeout(() => {
this.output(saba["説明(日本語)"]);
}, 1000);
return true;

var cf1 = getTypesInArray(muno.data, "cf1");
if (s === undefined || s.indexOf("鯖江") !== -1 || s === "?") {
this.output("鯖江で何する?" + cf1.join("?") + "?");
Expand Down Expand Up @@ -566,6 +577,11 @@ var Muno = function(outputcallback) {
};
};
var getTypesInArray = function(ar, name, opt) {
console.log(name);
name = {
cf1: "カテゴリ",
cf2: "カテゴリ補足",
}[name];
var s = {};
if (opt === undefined) {
for (var i = 0; i < ar.length; i++) {
Expand All @@ -586,14 +602,19 @@ var getTypesInArray = function(ar, name, opt) {
return res;
};
var getSabakan = function(callback) {
var url = "http://www3.city.sabae.fukui.jp/xml/sabakan/sabakan.xml";
//var url = "http://www3.city.sabae.fukui.jp/xml/sabakan/sabakan.xml";
//const url = "https://data.odp.jig.jp/viewcsv/jp/fukui/sabae/197.csv";
const url = "https://code4fukui.github.io/muno3/data/197_sabakan.csv";
CSV.fetchJSON(url).then(res => {
console.log(res);
callback(res);
});
/*
ajax(proxyXML(url), function(data) {
data = xml2json(data);
// dump(data);
var sabadata = data.dataroot.sabakan;
callback(sabadata);
});
};
var proxyXML = function(url) {
return "/proxy/ITqT5WkhCf2yn1s9?cnv=xml&" + "cache=no&url=" + encodeURIComponent(url);
*/
};
4 changes: 2 additions & 2 deletions waka100.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ff9c73a

Please sign in to comment.