forked from elendirx/web2web
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
93 lines (72 loc) · 2.53 KB
/
index.html
File metadata and controls
93 lines (72 loc) · 2.53 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html>
<head>
<title>Web2Web Bootstrap</title>
<meta charset="utf-8">
</head>
<body>
<h1>Loading ...</h1>
<p>This may take a minute or two.</p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/webtorrent/0.96.4/webtorrent.min.js"></script>
<script>
var hex2Bin = function(hex) {
var bytes = [],
str
for(var i=0; i < hex.length-1; i+=2) {
bytes.push(parseInt(hex.substr(i, 2), 16))
}
return String.fromCharCode.apply(String, bytes)
}
var CONFIG = {
btcAddress: '1DTZQVtnUm1dVmpDg8eWgXUqQe3hhYgDry',
magnetBase: 'magnet:?dn=index.html&tr=udp%3A%2F%2Fexodus.desync.com%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&xt=urn:btih:'
}
$(document).ready(function() {
// debug
// find the latest transaction with OP_RETURN for given bitcoin address
$.get('https://blockexplorer.com/api/txs/?address=' + CONFIG.btcAddress)
.then(function(data) {
var deferred = $.Deferred();
// deferred.resolve("23bbffb6cb148f1aa54aa8a7eac381075f297ff3")
for (var i = 0; i < data.txs.length; i++) {
for (var j = 0; j < data.txs[i].vout.length; j++) {
var scriptPubKey = data.txs[i].vout[j].scriptPubKey.asm
if (scriptPubKey.indexOf('OP_RETURN') !== -1) {
// get webpage torrent info hash
var torrentHash = scriptPubKey.split(' ').slice(-1)[0]
torrentHash = hex2Bin(torrentHash)
// console.log(torrentHash)
deferred.resolve(torrentHash)
}
}
}
return deferred.promise()
})
// download webpage HTML via torrents
.then(function(torrentHash) {
console.log('using hash', torrentHash)
var magnet = CONFIG.magnetBase + torrentHash
var client = new WebTorrent()
client.add(magnet, function(torrent) {
var file = torrent.files[0]
// read new HTML into string
var str = ''
file
.createReadStream({ start: 0, end: 1000 * 10 * 10 * 10 })
.setEncoding('utf8')
.on('data', function(chunk) {
str += chunk
})
.on('end', function() {
// overwrite current page with new HTML
document.open()
document.write(str)
document.close()
})
})
})
})
</script>
</body>
</html>