SHARE
TWEET

Steemit Random

a guest Aug 12th, 2016 280 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript:(function(){var WebSocketWrapper; WebSocketWrapper = function() { var ws = WebSocketWrapper.prototype; function WebSocketWrapper(server) { this.server = server; this.connection = {}; this.callbacks = []; } ws.connect = function() { var _this = this; return new Promise(function(resolve, reject) { if('WebSocket' in window) { _this.connection = new WebSocket(_this.server); _this.connection.onopen = function() { resolve(_this.connection); }; _this.connection.onerror = function(error) { reject(Error('Error connecting to server, please reload the page!' + error)); }; _this.connection.onmessage = function(data) { var sdata = JSON.parse(data['data']); _this.callbacks[sdata['id']](sdata['result']); }; } else { reject(Error('Your browser is too old, please get a recent one!')); } }); }; ws.send = function(data, callback) { this.callbacks[data['id']] = callback; var json = JSON.stringify(data); this.connection.send(json); }; return WebSocketWrapper; }(); var SteemWrapper; SteemWrapper = function() { var steem = SteemWrapper.prototype; function SteemWrapper(ws) { this.ws = ws; this.id = 0; } steem.send = function(method, params, callback) { ++this.id; var data = { "id": this.id, "method": method, "params": params }; this.ws.send(data, callback); }; return SteemWrapper; }(); var server = 'wss://steemit.com/wspa'; var ws = new WebSocketWrapper(server); ws.connect().then(function(response) { steem = new SteemWrapper(ws); var saved = 'created'; try { if(localStorage.getItem('random_input') != null) saved = localStorage.getItem('random_input'); } catch(e) {} var input = prompt('Steemit Random\n\nEnter a category (with optional tag):\n\n', saved); if(input == null) return; document.body.innerHTML = '<div style="text-align:center; line-height:5em;">Fetching random article from <em>' + input + '</em>..</div>'; steem.send('get_state', ['/' + input], function(json) { var content = json['content']; var keys = []; for(var prop in content) if(content.hasOwnProperty(prop)) keys.push(prop); if(keys.length == 0) alert('No results found!'); else { try { localStorage.setItem('random_input', input); } catch(e) {} location.assign("http://steemit.com" + content[keys[keys.length * Math.random() << 0]]['url']); } });}); })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top