-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind47images.js
69 lines (65 loc) · 1.96 KB
/
find47images.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { sleep } from "https://js.sabae.cc/sleep.js";
import { CSV } from "https://js.sabae.cc/CSV.js";
/*
const cls = async (color) => {
document.body.style.backgroundColor = color || "black";
await sleep(100);
};
*/
const waitImageLoad = async (img) => {
return new Promise((resolve) => {
img.onload = () => {
resolve(img);
};
});
};
let imglist = null;
const bg = async (no, nowait) => {
if (!imglist) {
imglist = CSV.toJSON(await CSV.fetch("https://code4fukui.github.io/find47/find47images.csv"));
//console.log(imglist);
}
const data = imglist.find(i => i.id == no);
if (!data) {
return;
}
const img = new Image();
const url_image = "https://code4fukui.github.io/find47/photo/" + data.id + ".jpg";
//img.src = url_image;
await waitImageLoad(img);
//document.body.style.backgroundImage = `url('${url}'), url("./man.png")`;
document.body.style.backgroundColor = "black";
//document.body.style.backgroundImage = `url('${data.url_image}')`;
document.body.style.backgroundImage = `url('${url_image}')`;
document.body.style.backgroundRepeat = "no-repeat";
document.body.style.backgroundSize = "100% auto";
const get = (id) => {
const c = document.getElementById(id);
if (c) {
return c;
}
const c2 = document.createElement("a");
c2.id = id;
document.body.appendChild(c2);
return c2;
};
const div = get("find47_bg_credit");
div.style.position = "absolute";
div.style.right = ".2em";
div.style.bottom = ".2em";
div.href = data.url;
div.style.textDecoration = "none";
div.textContent = data.title + " © " + data.author + " クリエイティブ・コモンズ・ライセンス(表示4.0 国際)";
div.style.color = "white";
div.style.fontSize = "70%";
if (!nowait) {
await sleep(1000);
}
/*
document.body.style.backgroundImage = `url("./man.png")`;
document.body.style.backgroundImage = `url("./man.png")`;
document.body.style.backgroundSize = "auto 50%";
document.body.style.backgroundPosition = "20% 100%";
*/
};
export { bg };