Skip to content

Instantly share code, notes, and snippets.

@Stjerneklar
Created May 15, 2016 23:12
Show Gist options
  • Save Stjerneklar/744c3abc3e8db677c6537493772d87f8 to your computer and use it in GitHub Desktop.
Save Stjerneklar/744c3abc3e8db677c6537493772d87f8 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name RLC Portable
// @version 0.1
// @description Portable Live Rooms
// @author Stjerneklar... only stjerneklar !
// @namespace http://tampermonkey.net/
// @include http*
// @require https://code.jquery.com/jquery-2.2.3.min.js
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_listValues
// @run-at document-idle
// @noframes
// ==/UserScript==
+function() {
$("body").prepend("<ol class='rlc-message-listing'></ol>");
$.getJSON("https://www.reddit.com/live/wpytzw1guzg2/about.json", function(data) {
var websocket_url = data.data.websocket_url;
console.log('websocket_url', websocket_url);
var ws = new WebSocket(websocket_url);
ws.onmessage = function (evt) {
var msg = JSON.parse(evt.data);
switch(msg.type) {
case 'update':
var payload = msg.payload.data;
var usr = payload.author;
var msgbody = payload.body;
var msgID = payload.name;
var created = payload.created_utc;
var utcSeconds = created;
var readAbleDate = new Date(0); // The 0 there is the key, which sets the date to the epoch (wat?)
readAbleDate.setUTCSeconds(utcSeconds);
var finaltimestamp = readAbleDate.toTimeString().split("GMT")[0];
var fakeMessage = `
<li class="rlc-message" name="rlc-id-${msgID}">
<div class="body">${msgbody}</div>
<div class="simpletime">${finaltimestamp}</div>
<a href="/user/${usr}" class="author">${usr}</a>
</li>`
$(".rlc-message-listing").prepend(fakeMessage);
break;
}
};
});
}();
GM_addStyle(`
ol.rlc-message-listing {
position: fixed;
bottom: -1px;
overflow: auto;
left: 0px;
width: 100%;
height: 60px;
background: rgba(0, 0, 0, 0.72);
z-index: 10000;
color: white;
}
.rlc-message .body {
float: right;
width: 80%;
}
.simpletime {
float: left;
padding-left: 20px;
}
a.author {
float: left;
padding-left: 20px;
}
li.rlc-message {
padding-top: 5px;
}
`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment