Skip to content

Instantly share code, notes, and snippets.

@michel47

michel47/README.md

Last active Mar 31, 2021
Embed
What would you like to do?
web page integrity check using SHA256
const botname = 'Erica M. Malichi'
console.log('why, hello world!');
let html = document.getElementsByTagName('html')[0];
var code = document.getElementsByTagName('code')[0]
var templ = document.getElementById('container').innerHTML;
code.innerText = templ
// see also https://www.jsdelivr.com/package/gh/willforge/fairjs
var script = document.createElement('script')
script.setAttribute('type','text/javascript')
script.src = 'https://cdn.jsdelivr.net/gh/willforge/fairjs@master/sha256.js'
script.onload = function () {
let container = document.getElementById('container');
//let sha = sha256(container.innerHTML);
let sha = sha256(templ);
let sig = shortqm(sha)
console.info('sha:',sha);
buf = templ.replace(/:name/g,botname).
replace(/:sha/,sha).
replace(/:sig/,sig).
replace(/:seed/g,slugify(botname))
container.innerHTML = buf;
document.getElementById('bot').src = 'https://robohash.org/'+slugify(botname)+'-'+sha;
let code = document.getElementsByTagName('code')[0]
code.innerText = buf;
};
document.getElementsByTagName('head')[0].appendChild(script)
function slugify(s) { return s.toLowerCase().replace(/[^a-z0-9]+/g,'-'); }
function shortqm(h) { return (typeof(h) != 'undefined') ? h.substr(0,6)+'...'+h.substr(-3) : undefined; }
true;
<!DOCTYPE html>
<meta charset=utf8>
<link rel=stylesheet href=style.css>
<link rel=icon href=img/favicon.png>
<!script src="https://cdn.jsdelivr.net/gh/iglake/js@latest/dist/favicon.js" crossorigin="anonymous"></script>
<body style="background-image:URL(https://source.unsplash.com/daily?technology,abstract,robot)">
<div id=container><p>Hello World
<img id=bot title=":seed" align=right>
<p>I am :name,
<br>
<br>--&nbsp;<br>+<span title=":sha">:sig</span>
<span class=spacer-4em><pre class=border><code></code></pre>
</div>
<script src=app.js></script>
body {
background-image: URL();
background-size: cover;
background-attachment: fixed
}
.border { border: 1px solid grey; }
.rounded { border-radius: 16px; }
.shadow {
box-shadow: 5px 5px 15px 2px rgba(4,3,5,0.9);
}
#container {
max-width: 720px;
min-height: 40px;
margin: auto;
margin-top: 10vh;
padding: 1.4rem;
color: #200122;
background-color: white;
opacity: .92;
}
.spacer-4em {
display: block;
margin-top: 4em;
}
.spacer-4em:before {
content: '§' /* &#167; */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment