Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
unwriter committed Apr 30, 2019
1 parent cb88ed4 commit f64cab9
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 308 deletions.
15 changes: 1 addition & 14 deletions bitcom.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
padding: 5px;
}
h1 {
font-size: 80px;
font-size: 50px;
margin: 0;
max-width: 800px;
word-wrap: break-word;
Expand Down Expand Up @@ -334,19 +334,7 @@ <h2>endpoints</h2>
image: (meta.image ? meta.image : null)
})
console.log("logs = ", logs)
/*
let lstr = templates.log({
items: logs.map(function(l) {
return {
content: JSON.stringify(l, null, 2)
}
})
})
console.log("str = ", str)
console.log("lstr = ", lstr)
*/
document.querySelector(".slot").innerHTML = str;
//document.querySelector(".logs").innerHTML = lstr;
}
document.addEventListener("DOMContentLoaded", async function(e) {
console.log("Load")
Expand All @@ -360,7 +348,6 @@ <h2>endpoints</h2>
console.log("Meta = ", JSON.stringify(meta, null, 2));
await route.enable(address)
await route.add(address)
//await log(address)
render();

document.querySelectorAll("button").forEach(function(el) {
Expand Down
15 changes: 8 additions & 7 deletions events.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ module.exports = {
let tab = Nav.newTab(url, { icon: "bottle://assets/cap.png" })
}
});
ipcRenderer.on('resolve-error', (event, address) => {
let url = document.querySelector("#nav-ctrls-url").value;
console.log("url = ", url);
if (/^bit:.+/.test(url)) {
let html = "<div><i class='fas fa-exclamation-circle'></i> Connection required</div><div class='flexible'></div><a href='bottle://bitcom?address=" + address + "' target='_blank' class='btn'>Connect to " + address + "</a>";;
document.querySelector("#nav-footer .sub").innerHTML = html;
}
});
document.querySelector("#nav-body-shortcuts").addEventListener("dragleave", function(ev) {
ev.preventDefault();
document.querySelector("#nav-body-shortcuts").style.backgroundColor = "whitesmoke";
Expand All @@ -105,13 +113,6 @@ module.exports = {
}
}
})
// document.querySelector("#nav-ctrls-url").addEventListener("click", function(e) {
// console.log("e.target.value = ", e.target.value);
// if (/^bottle:.*/i.test(e.target.value)) {
// e.preventDefault();
// let source = Nav.newTab("about:blank", {})
// }
// })
document.addEventListener("dragstart", ondragstart);
document.addEventListener("drop", ondrop);
document.addEventListener("keydown", onkeydown);
Expand Down
241 changes: 0 additions & 241 deletions home.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,254 +152,13 @@
}
</style>
<link href="bottle://fa/css/all.css" rel="stylesheet">
<!--
<script>
const {remote} = require('electron');
const req = require('./req.js');
const dirname = remote.app.getAppPath();
var header = { headers: { key: "16JaLJ8b5UvQp355Gva2qhuTS65NkowhPr" } };
var timeago = require('timeago.js');
var protocols = {}
var current_skip = 0;
var current_query;
var loading;
var dir = function(cb) {
var dirquery = {
"v": 3,
"q": {
"find": {
"out.b0": { "op": 106 },
"out.s1": "$",
"out.s2": {
"$in": ["useradd", "echo", "cat"]
}
}
},
"r": {
"f": "[.[] | {sender: .in[0].e.a, out: .out } ]"
}
};
var dirb64 = btoa(JSON.stringify(dirquery));
var dirurl = "https://babel.bitdb.network/q/1DHDifPvtPgKFPZMRSxmVHhiPvFmxZwbfh/" + dirb64
fetch(dirurl, header).then(function(r) {
return r.json();
}).then(function(r) {
let items = [].concat(r.u).concat(r.c);
items.forEach(function(item) {
item.out = item.out.filter(function(o) {
return o;
})[0];
})
items.filter(function(k) {
console.log(JSON.stringify(k, null, 2))
return k.out.s2 === 'useradd' && k.sender === k.out.s3
}).forEach(function(k) {
protocols[k.sender] = {}
})
items.filter(function(k) {
return ['echo', 'cat'].includes(k.out.s2) && ['to', '>'].includes(k.out.s4)
}).forEach(function(k) {
if (!protocols[k.sender]) {
protocols[k.sender] = {}
}
if (k.out.s5 && k.out.s3) {
protocols[k.sender][k.out.s5] = k.out.s3;
}
})
console.log("Protocols = ", protocols);
})
}
var get = function(qu) {
loading = true;
let f
document.querySelector(".loading").classList.remove("hidden");
if (qu) {
current_query = qu;
let n = document.querySelector("#detail .list");
while (n.firstChild) {
n.removeChild(n.firstChild);
}
}
if (current_query.type) {
if (current_query.type === 'all') {
f = {
"out.b0": { "op": 106 },
"out.s1": {
"$in": Object.keys(protocols)
}
};
} else {
f = { "out.s3": { "$regex": current_query.type, "$options": "i" } };
}
} else if (current_query.search) {
f = { "$text": { "$search": current_query.search } };
} else if (current_query.q) {
f = current_query.q;
}
var query = {
"v": 3,
"q": {
"find": f,
// "project": { "c": 1, "tx": 1, "in.e": 1, "out.s3": 1, "out.s4": 1, "out.s5": 1, "blk": 1 },
"skip": current_skip,
"limit": 50
},
"r": {
"f": "[ .[] | { blk: .blk, b: .tx.h, out: .out }]"
}
};
console.log("query = ", JSON.stringify(query, null, 2));
var b64 = btoa(JSON.stringify(query));
//var url = "https://data.bitdb.network/q/1KuUr2pSJDao97XM8Jsq8zwLS6W1WtFfLg/" + b64;
var url = "https://babel.bitdb.network/q/1DHDifPvtPgKFPZMRSxmVHhiPvFmxZwbfh/" + b64
fetch(url, header).then(function(r) {
return r.json();
}).then(function(r) {
console.log("RR = ", r)
let items = r.u.concat(r.c);
let html = items.map(function(item) {
let name;
let prefixes = [];
console.log("Item = ", item)
let out = item.out.filter(function(k) {
return k;
})[0];
prefixes.push(out.s1)
Object.keys(out).forEach(function(key) {
if(out[key] === '|') {
if (key[0] === 's') {
let index = parseInt(key.slice(1))
let nextPrefix = out["s" + (index+1)];
if (nextPrefix) {
prefixes.push(nextPrefix);
}
}
}
})
console.log("PREFIXES = ", prefixes)
if (out.s5 && out.s5 !== "|") {
name = out.s5.slice(0,200);
} else {
name = "b://" + item.b
}
let resolvedName;
if (protocols[out.s1] && protocols[out.s1].name) {
resolvedName = protocols[out.s1].name;
} else {
resolvedName = out.s1;
}
return "<div class='item' data-state='" + (item.blk ? "confirmed" : "unconfirmed") + "' data-url='c://" + item.c + "'>" +
"<div class='name'>" + name + "</div>" +
"<div class='meta'>" + out.s3 + " - " + (item.blk ? "block " + item.blk.i + " (" + timeago.format(item.blk.t * 1000) + ")" : "unconfirmed") + "</div>" +
`<a target='_blank' class='button' href='bit://19HxigV4QyBv3tHpQVcUEQyq1pzZVdoAut/${item.b}'>${resolvedName}</a>` +
// `<a target='_blank' class='button' href='bit://1KCm9cgDdT7r88WRQmm6gynFNmTrskdygn/${item.c}'>C:</a>` +
prefixes.map(function(p) {
return `<a target='_blank' class='button' href='bit://${p}/${item.b}'>${p}</a>`
}).join("") +
"</div>";
}).join("");
var page = document.createElement("div")
page.className = "page";
page.innerHTML = html;
document.querySelector("#detail .list").appendChild(page);
document.querySelector("#frame").classList.add("hidden");
document.querySelector("#detail").classList.remove("hidden");
loading = false;
console.log("Loaded");
document.querySelector(".loading").classList.add("hidden");
})
}
document.addEventListener("DOMContentLoaded", function(e) {
var types = ["all", "image", "video", "audio", "text", "html", "markdown", "json", "xml", "javascript", "css", "pdf", "mp4", "mp3"];
var sidebar_content = types.map(function(type) {
return "<a class='row' id='" + type + "'>" + type + "</a>"
}).join("");
document.querySelector("#frame").setAttribute("src", "https://bottle.bitdb.network/0.0.4/index.html?" + Date.now());
document.querySelector("#sidebar .container").innerHTML = sidebar_content;
document.querySelector("#sidebar .container").addEventListener("click", function(e) {
document.querySelectorAll("#sidebar .row").forEach(function(el) {
el.classList.remove("selected");
})
if (e.target.className === 'row') {
e.target.classList.add("selected");
current_skip = 0;
get({type: e.target.id});
} else {
var p = e.target.closest(".row");
if (p) {
p.classList.add("selected");
current_skip = 0;
get({type: p.id});
}
}
})
document.querySelector("form").addEventListener("submit", function(e) {
let val = e.target.querySelector("input[type=text]").value;
e.stopPropagation();
e.preventDefault();
current_skip = 0;
if (/^filename:/.test(val)) {
get({ q: { "out.s5": { "$regex": val.replace(/filename:/,'').trim(), "$options": "i" } } });
} else if (/^filetype:/.test(val)) {
get({ q: { "out.s3": { "$regex": val.replace(/filetype:/,'').trim(), "$options": "i" } } });
} else {
get({search: val});
}
})
document.querySelector("#detail .list").addEventListener("click", function(e) {
document.querySelectorAll("#detail .row").forEach(function(el) {
el.classList.remove("selected");
});
if (e.target.className === 'row') {
e.target.classList.add("selected");
var url = e.target.dataset.url;
} else {
var p = e.target.closest(".row");
if (p) {
var url = p.dataset.url;
p.classList.add("selected");
}
}
})
let detail = document.querySelector("#detail")
detail.addEventListener("scroll", function(ev) {
if (!loading && detail.scrollHeight - detail.offsetHeight <= detail.scrollTop + 50) {
console.log("Bottom")
current_skip += 50;
get();
}
})
dir()
})
</script>
-->
<script>
document.addEventListener("DOMContentLoaded", function(e) {
document.querySelector("#frame").setAttribute("src", "https://bottle.bitdb.network/0.0.4/index2.html?" + Date.now());
})
</script>
</head>
<body>
<iframe name='frame' id='frame'></iframe>
<!--
<div class='content'>
<div id='sidebar'>
<form><input type='text' placeholder="Search"></form>
<a id='home' href='bottle://home'><i class='fas fa-home'></i> Home</a>
<a id='bookmark' href='bottle://bookmark'><i class='far fa-bookmark'></i> Bookmark</a>
<a id='write' href='bottle://write'><i class='far fa-edit'></i> Write</a>
<div class='container'></div>
</div>
<div id='subbar'>
</div>
<div id='detail' class='hidden'>
<div class='list'></div>
<div class='loading hidden'>Loading</div>
</div>
<iframe name='frame' id='frame'></iframe>
</div>
-->
</body>
</html>
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
<div id="nav-body-shortcuts"></div>
<div id="nav-body-tabs"></div>
<div id="nav-body-views"></div>
<div id="nav-footer"></div>
<div id="nav-footer">
<div class='main'></div>
<div class='sub'></div>
</div>
<script>
const fs = require('fs');
const path = require('path');
Expand Down
Loading

0 comments on commit f64cab9

Please sign in to comment.