Created
August 26, 2015 02:10
-
-
Save rlemon/b0043858671bbd74f655 to your computer and use it in GitHub Desktop.
user stars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let io = undefined, found = []; | |
const addScript = url => { | |
return new Promise((resolve, reject) => { | |
let script = document.createElement('script'); | |
script.onload = resolve; | |
script.onerror = reject; | |
script.src = url; | |
document.body.appendChild(script); | |
}); | |
}; | |
const sniff = () => { | |
console.log('sniffing'); | |
io = io.connect('http://rlemon.ca:8888'); | |
io.on('star', gotStar); | |
let ids = $.makeArray($('.flash .stars.always,.sidebar-vote.stars').parents('li,.message').map((i,el) => { | |
return el.id.split(/-|_/g)[1]; | |
})); | |
io.emit('init', ids); | |
new MutationObserver(aparser).observe(chat, { | |
attributes: true, | |
subtree: true | |
}); | |
new MutationObserver(records => records.forEach(record => [].forEach.call(record.addedNodes, nparser))).observe(chat, { | |
childList: true, | |
subtree: true | |
}); | |
}; | |
const aparser = obj => { | |
obj = Array.isArray(obj) ? obj.shift() : obj; | |
if (obj.attributeName === 'class' && obj.target.classList && obj.target.classList.contains('always')) { | |
console.log('attr found'); | |
var id = $(obj.target).parents('.message').prop('id').split('-')[1]; | |
if( id ) io.emit('getStar', id); | |
} | |
}; | |
const nparser = obj => { | |
if( obj.classList && obj.classList.contains('always') ) { | |
console.log('node found'); | |
var id = $(obj).parents('.message').prop('id').split('-')[1]; | |
if( id ) io.emit('getStar', id); | |
} | |
}; | |
const gotStar = data => { | |
data.rows.forEach(row=> { | |
$('#message-' + row.message_id + ',#summary_' + row.message_id).each((i,el) => { | |
if( !el.dataset.written ) { | |
el.title = ''; | |
el.dataset.written = true; | |
} | |
el.title += row.username.replace(/ /g,'') + ' '; | |
$(el).find('span').prop('title', el.title); | |
}); | |
}); | |
}; | |
addScript('http://rlemon.ca:8888/socket.io/socket.io.js').then(sniff); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var io = undefined, | |
found = []; | |
var addScript = function addScript(url) { | |
return new Promise(function (resolve, reject) { | |
var script = document.createElement('script'); | |
script.onload = resolve; | |
script.onerror = reject; | |
script.src = url; | |
document.body.appendChild(script); | |
}); | |
}; | |
var sniff = function sniff() { | |
console.log('sniffing'); | |
io = io.connect('http://rlemon.ca:8888'); | |
io.on('star', gotStar); | |
var ids = $.makeArray($('.flash .stars.always,.sidebar-vote.stars').parents('li,.message').map(function (i, el) { | |
return el.id.split(/-|_/g)[1]; | |
})); | |
io.emit('init', ids); | |
new MutationObserver(aparser).observe(chat, { | |
attributes: true, | |
subtree: true | |
}); | |
new MutationObserver(function (records) { | |
return records.forEach(function (record) { | |
return [].forEach.call(record.addedNodes, nparser); | |
}); | |
}).observe(chat, { | |
childList: true, | |
subtree: true | |
}); | |
}; | |
var aparser = function aparser(obj) { | |
obj = Array.isArray(obj) ? obj.shift() : obj; | |
if (obj.attributeName === 'class' && obj.target.classList && obj.target.classList.contains('always')) { | |
console.log('attr found'); | |
var id = $(obj.target).parents('.message').prop('id').split('-')[1]; | |
if (id) io.emit('getStar', id); | |
} | |
}; | |
var nparser = function nparser(obj) { | |
if (obj.classList && obj.classList.contains('always')) { | |
console.log('node found'); | |
var id = $(obj).parents('.message').prop('id').split('-')[1]; | |
if (id) io.emit('getStar', id); | |
} | |
}; | |
var gotStar = function gotStar(data) { | |
data.rows.forEach(function (row) { | |
$('#message-' + row.message_id + ',#summary_' + row.message_id).each(function (i, el) { | |
if (!el.dataset.written) { | |
el.title = ''; | |
el.dataset.written = true; | |
} | |
el.title += row.username.replace(/ /g, '') + ' '; | |
$(el).find('span').prop('title', el.title); | |
}); | |
}); | |
}; | |
addScript('http://rlemon.ca:8888/socket.io/socket.io.js').then(sniff); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment