debug.html 3.53 KB
Newer Older
1 2
<html>
    <head>
3
        <title>Samizdat</title>
4 5 6 7 8 9 10 11 12
        <script src="ipsg.js"></script>
    </head>
    <body>
        <script src="https://cdn.jsdelivr.net/npm/gun/examples/jquery.js"></script>
        <script src="./lib/gun.js"></script>
        <script src="./lib/sea.js"></script>
        <script src="./lib/webrtc.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/gun/lib/unset.js"></script>

13
        <h1>Samizdat</h1>
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
        <p>Censorship-resistant, browser-based content delivery <a href="https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps">Progressive Web App</a>, using <a href="https://gun.eco/">Gun</a>, and <a href="https://github.com/ipfs/js-ipfs">JS-IPFS</a>.</p>
        <p>This is a proof of concept.</p>
        <div>
            <!--p>Gun user is: <strong id="gun-user"></strong></p-->
            <p>Gun user said:</p>
            <ul id="gun-said"></ul>
            <p>Gun user published:</p>
            <ul id="gun-published"></ul>
        </div>
        <hr/>
        <h2>Manual Labour</h2>
        <p>This section is lifted straight from the Gun tutorial and is here for debugging while we're trying to find our feet around this.</p>
        <form id="sign">
            <input id="alias" placeholder="username">
            <input id="pass" type="password" placeholder="passphrase">
            <input id="in" type="submit" value="sign in">
            <input id="up" type="button" value="sign up">
        </form>

        <ul id="tutorial"></ul>

        <form id="said">
            <input id="say">
            <input id="speak" type="submit" value="speak">
        </form>
        <script>
            var gun = Gun([/*'http://localhost:8765/gun', */'https://gunjs.herokuapp.com/gun']);
            /**
             * just to prove Gun is active and getting content
             */
            var testUser = gun.user('sdgZ46jw7TQNAqvkcB3ktVPiEE6zzpBuzEmAVS2bxgE.dZtlJTKg1osTUmLUkOzFU7XThGLm1Tyz8KJVGvRyrDs')
            testUser.get('said').map().once(function(say, id){
                var li = $('#' + id).get(0) || $('<li>').attr('id', id).appendTo('ul#gun-said');
		        $(li).text(say);
            })
            testUser.get(window.location.hostname).map().once(function(data, id){
                if (typeof data === 'string') {
                    var li = $('#' + id.replace(/\//g, '_')).get(0) || $('<li>').attr('id', id.replace(/\//g, '_')).appendTo('ul#gun-published');
                    $(li).text(id + " :: " + data);
                }
            })

            /**
             * legacy code, straight outta Compt^Wtutorial
             * 
             * actual code that handles actual things is in service-worker.js
             */
            var user = gun.user();
	        $('#up').on('click', function(e){
                user.create($('#alias').val(), $('#pass').val());
            });

            $('#sign').on('submit', function(e){
               e.preventDefault();
               user.auth($('#alias').val(), $('#pass').val());
            });

            $('#said').on('submit', function(e){
	            e.preventDefault();
		        if(!user.is){ return }
                user.get('said').set($('#say').val());
                $('#say').val("");
            });

            function UI(say, id){
	            var li = $('#' + id).get(0) || $('<li>').attr('id', id).appendTo('ul#tutorial');
		        $(li).text(say);
            };

            gun.on('auth', function(){
	            $('#sign').hide();
                user.get('said').map().once(UI);
            });
        </script>
    </body>
</html>