Files: d7221d981ca25931b54c37c514c78e9803027278 / modules_extra / raw.js
1282 bytesRaw
1 | var h = require('hyperscript') |
2 | |
3 | // from ssb-ref |
4 | var refRegex = /((?:@|%|&)[A-Za-z0-9\/+]{43}=\.[\w\d]+)/g |
5 | |
6 | exports.gives = 'message_meta' |
7 | |
8 | function linkify (text) { |
9 | var arr = text.split(refRegex) |
10 | for (var i = 1; i < arr.length; i += 2) { |
11 | arr[i] = h('a', {href: '#' + arr[i]}, arr[i]) |
12 | } |
13 | return arr |
14 | } |
15 | |
16 | exports.create = function (api) { |
17 | return function (msg) { |
18 | var tmp = h('div') |
19 | var el |
20 | var pre |
21 | return h('input', { |
22 | type: 'checkbox', |
23 | title: 'View Data', |
24 | onclick: function () { |
25 | // HACK (mw) yo we need a better way to replace the content |
26 | var msgEl = this.parentNode.parentNode |
27 | var msgContentEl = msgEl.querySelector('.\\.content') |
28 | if (this.checked) { |
29 | // move away the content |
30 | while (el = msgContentEl.firstChild) |
31 | tmp.appendChild(el) |
32 | // show the raw stuff |
33 | if (!pre) pre = h('pre', linkify(JSON.stringify({ |
34 | key: msg.key, |
35 | value: msg.value |
36 | }, 0, 2))) |
37 | msgContentEl.appendChild(pre) |
38 | } else { |
39 | // hide the raw stuff |
40 | msgContentEl.removeChild(pre) |
41 | // put back the content |
42 | while (el = tmp.firstChild) |
43 | msgContentEl.appendChild(el) |
44 | } |
45 | } |
46 | }) |
47 | } |
48 | } |
49 | |
50 |
Built with git-ssb-web