Created
December 16, 2011 12:24
-
-
Save rlemon/1485848 to your computer and use it in GitHub Desktop.
quickie copy from home
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
// ==UserScript== | |
// @name Quickie | |
// @author rlemon | |
// @version 0.1 | |
// @namespace rlemon.com | |
// @description Mini-SO bar in any page, anywhere, anytime. | |
// @include * | |
// ==/UserScript== | |
function EmbedCodeOnPage(kode) { | |
var elm = document.createElement('script'); | |
elm.textContent = kode; | |
document.head.appendChild(elm); | |
} | |
function EmbedFunctionOnPageAndExecute(fn) { | |
EmbedCodeOnPage('(' + fn.toString() + ')()'); | |
} | |
EmbedFunctionOnPageAndExecute(function() { | |
var chatter = function() { | |
var chatterWindow = $('<div>'); | |
chatterWindow.css({ | |
'position': 'fixed', | |
'bottom': '20px', | |
'border': '1px solid #777', | |
'right': '-1px', | |
'z-index': '999999', | |
'width': '300px', | |
'background-color': '#fff', | |
'box-shadow': '0px 5px 10px #777', | |
'height': '400px' | |
}); | |
$.ajax({ | |
dataType: 'jsonp', | |
jsonp: 'jsonp', | |
url: 'http://api.stackoverflow.com/1.1/questions/unanswered?pagesize=10', | |
success: function(val) { | |
$.each(val.questions, function() { | |
var question = $("<div>"); | |
question.css({ | |
'padding': '4px', | |
'border-top': '1px solid #000', | |
'border-bottom': '1px solid #000', | |
'text-align': 'left' | |
}); | |
console.log(this); | |
question.text(this.title); | |
chatterWindow.append(question); | |
}); | |
}, | |
error: function(val) { | |
console.log('error'); | |
console.log(arguments); | |
} | |
}); | |
$('body').append(chatterWindow); | |
}; | |
/* Load jQuery - if you don't like it too bad. */ | |
if (!window.jQuery) { | |
var elm = document.createElement('script'); | |
elm.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js'; | |
elm.onreadystatechange = function() { | |
if (this.readyState == 'complete') chatter(); | |
} | |
elm.onload = chatter; | |
document.head.appendChild(elm); | |
} else { | |
chatter(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment