Created
June 26, 2015 20:00
-
-
Save eeejay/c6324d842001469cc0d9 to your computer and use it in GitHub Desktop.
sillystuff
This file contains 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
// DOMContentLoaded is fired once the document has been loaded and parsed, | |
// but without waiting for other external resources to load (css/images/etc) | |
// That makes the app more responsive and perceived as faster. | |
// https://developer.mozilla.org/Web/Reference/Events/DOMContentLoaded | |
function getMessages() { | |
return new Promise((resolve, reject) => { | |
var x = new XMLHttpRequest(); | |
var params = "m5_csrf_tkn=" + document.querySelector("meta[name=csrf_id]").content; | |
console.log(params); | |
x.onload = () => { | |
console.log('got!'); | |
resolve(JSON.parse(x.response)); | |
}; | |
x.open('post', 'https://mobile.twitter.com/api/messages', true); | |
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | |
x.setRequestHeader("Content-length", params.length); | |
x.setRequestHeader("Connection", "close"); | |
x.send(params); | |
}); | |
} | |
console.log('inited script!!'); | |
window.addEventListener('DOMContentLoaded', function() { | |
'use strict'; | |
var seenMessages = new Set(); | |
//Notification.requestPermission(); | |
setTimeout(() => { | |
console.log('getting..'); | |
getMessages().then(r => { | |
var firstrun = seenMessages.length == 0; | |
for (var msg of r) { | |
if (!seenMessages.has(msg.id) && !firstrun) { | |
console.log('new message!', msg); | |
try { | |
//var notif = new Notification("Direct message from " + msg.screen_name); | |
//notif.addEventListener('click', () => console.log('clicked!!')); | |
} catch (e) { | |
console.log(e); | |
} | |
} | |
seenMessages.add(msg.id); | |
} | |
}); | |
}, 5000); | |
console.log('window???', window, navigator.mozApps.mgmt); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment