There are 73 previous versions of this script.
Add Syntax Highlighting (this will take a few seconds, probably freezing your browser while it works)
// ==UserScript==
// @name Facebook | Add Status
// @namespace http://userscripts.org/scripts/source/46217.user.js
// @author Ron Troyer
// @authorWebsite http://www.ronaldtroyer.com
// @description Adds your status to the homepage
// @version 2.43
// @include http*://*facebook.com/*
// ==/UserScript==
GM_registerMenuCommand('FB Status: SWITCH APPEARANCE', toggleAppearance);
GM_registerMenuCommand('FB Status: SWITCH ATTACHMENT POSITIONING', togglePositioning);
GM_registerMenuCommand('FB Status: TOGGLE CHARACTER COUNT DISPLAY', toggleCharacter);
if (GM_getValue('moveAttachments') == undefined) {moveAttachments = 'true'; GM_setValue('moveAttachments', 'true');} else {moveAttachments = GM_getValue('moveAttachments');}
if (GM_getValue('commentBoxAppearance') == undefined) {commentBoxAppearance = 'true'; GM_setValue('commentBoxAppearance', 'true');} else {commentBoxAppearance = GM_getValue('commentBoxAppearance');}
if (GM_getValue('displayCharacter') == undefined) {displayCharacter = 'true'; GM_setValue('displayCharacter', 'true');} else {displayCharacter = GM_getValue('displayCharacter');}
if (GM_getValue('commentCount') == undefined) {commentCount = ''; GM_setValue('commentCount', '');} else {commentCount = GM_getValue('commentCount');}
if (GM_getValue('likeCount') == undefined) {likeCount = ''; GM_setValue('likeCount', '');} else {likeCount = GM_getValue('likeCount');}
var loggedI = 0;
function toggleAppearance() {
if (commentBoxAppearance == 'true') {
commentBoxAppearance = 'false';
GM_setValue('commentBoxAppearance', 'false');
} else {
commentBoxAppearance = 'true';
GM_setValue('commentBoxAppearance', 'true');
}
basic();
toggleStatusLocation();
}
function togglePositioning() {
if (moveAttachments == 'true') {
moveAttachments = 'false';
GM_setValue('moveAttachments', 'false');
} else {
moveAttachments = 'true';
GM_setValue('moveAttachments', 'true');
}
basic();
}
function toggleCharacter() {
if ($('greasedCounter').style.display == 'none') {
$('greasedCounter').style.display = 'inherit';
GM_setValue('displayCharacter', 'true');
} else {
$('greasedCounter').style.display = 'none';
GM_setValue('displayCharacter', 'false');
}
}
window.toggleStatusLocation = function() {
myStatus = $('greaseStatusText').innerHTML;
myTime = $('greaseStatusTime').innerHTML;
$('greaseStatus').parentNode.removeChild($('greaseStatus'));
window.prepareDropArea();
displayStatus(myStatus,myTime);
}
window.$ = function (element) { return document.getElementById(element); } // Get element by id
window.$c = function (element) { return document.getElementsByClassName(element); } // Get elements by class
window.$t = function (element) { return document.getElementsByTagName(element); } // Get element by tag
var errLog = '';
window.basic = function () {
if ($('greasedCounter')) {
myCounter = $('greasedCounter');
if (moveAttachments == 'true') {
myCounter.style.cssFloat = 'left';
//myCounter.style.marginRight = '0px';
} else {
myCounter.style.cssFloat = 'right';
//myCounter.style.marginRight = ($c('UIComposer_Buttons')[0].offsetWidth + 5) + 'px';
}
}
if (myAttachments = $c('UIComposer_Attachments')[0]) {
if(moveAttachments == 'true') {
myAttachments.style.cssFloat = 'right';
if (myPrivacy = $c('UIComposer_PrivacyEtc')[0]) {
myPrivacy.style.width = 'auto';
}
//myAttachments.style.marginRight = $c('UIComposer_Buttons')[0].offsetWidth + 'px';
} else {
myAttachments.style.cssFloat = 'left';
//myAttachments.style.marginRight = '0px';
}
myAttachments.firstChild.style.fontWeight = "normal";
}
if ((commentBox = $c('UIComposer_UIContentBox')[0]) && (inputBox = $c('UIComposer_InputArea')[0])) {
if (commentBoxAppearance == 'true') {
commentBox.style.backgroundColor = "#ECEFF5";
commentBox.style.border = "0 none";
inputBox.style.border = "1px solid #BDC7D8";
} else {
commentBox.style.backgroundColor = "#F2F2F2";
commentBox.style.border = "1px solid #CCCCCC";
commentBox.style.borderColor = "#919191 #B5B5B5 #CBCBCB";
commentBox.style.borderTop = "2px solid #919191";
inputBox.style.borderColor = "#AEAEAE #BBBBBB #BBBBBB";
inputBox.style.borderStyle = "solid";
inputBox.style.borderWidth = "1px";
}
}
}
window.prepareDropArea = function () {
myProfile = false;
if (myPage.match('profile')) {
$c('profile_name_and_status')[0].style.display = 'none';
if ($('profile_action_send_message')) {
myProfile = false;
} else {
myProfile = true;
}
}
//PREPARE THE DROPZONE STYLE
if ($('greaseStatus')) {$('greaseStatus').parentNode.removeChild($('greaseStatus'));}
var greaseStatus = document.createElement('div');
greaseStatus.id = 'greaseStatus';
if ((commentBoxAppearance == 'true') && (!myPage.match('profile'))) {greaseStatus.style.marginLeft = '60px';}
else if ((!myPage.match('profile')) || (commentBoxAppearance == 'false')) {greaseStatus.style.paddingBottom = greaseStatus.style.paddingLeft = '8px';}
greaseStatus.style.display = 'none';
greaseInner = '';
//PREPARE DROPZONE HTML
if (commentBoxAppearance != 'true') {
greaseInner += '<div id="greaseStatusCancel" style="display: none; font-size: 11px;">';
greaseInner += '<a id="greaseStatusControlsCancel">Cancel</a>';
greaseInner += '</div>';
greaseInner += '<div id="greaseStatusContent" style="display: inline-block; margin-bottom: -5px;">';
} else {
greaseInner += '<div id="greaseStatusContent" style="margin-bottom: -5px;">';
}
greaseInner += '<span id="greaseStatusSection" style="margin-bottom: 5px; float: left; width: 100%;">';
greaseInner += '<span id="greaseStatusName" style="font-size:1.1em; font-weight:bold;"> </span>';
greaseInner += '<span id="greaseStatusText"> </span>';
greaseInner += '<span id="greaseStatusTime" style="font-size:11px; color: #777;"> </span>';
greaseInner += '<span id="greaseStatusExtras" style="font-size: 11px; color: #333;"> </span>';
if (commentBoxAppearance != 'true') {
greaseInner += '<span id="greaseStatusControls" style="color: #777; font-size:11px;">';
greaseInner += '<span style="color: #999;">· </span>';
greaseInner += '<a id="greaseStatusControlsEdit">Edit</a><span style="color: #999;"> · </span>';
greaseInner += '<a id="greaseStatusControlsClear">Clear</a>';
greaseInner += '</span>';
}
greaseInner += '</span>';
greaseInner += '</div>';
//CONTROLS COMMENTBOX
if (commentBoxAppearance == 'true') {
greaseInner += '<div id="greaseNub" style="background:transparent url(/rsrc.php/z9KI5/hash/94qxapy3.png) no-repeat scroll -930px -69px; clear:left; height:5px; margin:5px 0 0 17px; overflow:hidden; width:9px;"></div>';
greaseInner += '<a style="background: transparent url(/rsrc.php/z3NZ7/hash/2fpiuayh.gif) no-repeat scroll left center; margin-left: 5px; display: none; width: 16px; height: 16px; padding: 2px 0 2px 12px;" id="greaseStatusControlsCancel"> Cancel</a>';
greaseInner += '<span id="greaseStatusControls" style="float: right; margin-top: -22px; width: 44px; display: none;">';
greaseInner += '<a title="Edit" style="display: inline-block; background-color: #FFF; width; 16px; height: 16px; padding: 3px;" id="greaseStatusControlsEdit">';
greaseInner += '<span style="background:transparent url(/rsrc.php/z8X8P/hash/1b4f0vx0.gif) no-repeat scroll center 0px; display: block; width: 16px; height: 16px;"></span> ';
greaseInner += '</a>';
greaseInner += '<a title="Clear" style="display: inline-block; background-color: #FFF; width; 16px; height: 16px; padding: 3px;" id="greaseStatusControlsClear">';
greaseInner += '<span style="background:transparent url(/rsrc.php/z8X8P/hash/1b4f0vx0.gif) no-repeat scroll center -64px; display: block; width: 16px; height: 16px;"></span> ';
greaseInner += '</a>';
greaseInner += '</span>';
}
greaseStatus.innerHTML = greaseInner;
//INSERT THE DROPZONE
if (insertPoint = $c('UIComposer_UIContentBox')[0]) {
if (commentBoxAppearance == 'true') {insertPoint.parentNode.insertBefore(greaseStatus, insertPoint);}
else {insertPoint.insertBefore(greaseStatus, insertPoint.firstChild);}
//PREPARE THE COUNTER
if ($('greasedCounter')) {$('greasedCounter').parentNode.removeChild($('greasedCounter'));}
var greasedCounter = document.createElement('div');
greasedCounter.id = 'greasedCounter';
greasedCounter.innerHTML = '0 characters';
greasedCounter.style.paddingTop = '6px';
greasedCounter.style.color = '#AAA';
if(moveAttachments == 'true') {
greasedCounter.style.cssFloat = 'left';
//greasedCounter.style.marginRight = '0px';
} else {
greasedCounter.style.cssFloat = 'right';
//greasedCounter.style.marginRight = ($c('UIComposer_Buttons')[0].offsetWidth + 5) + 'px';
}
if (displayCharacter == 'false') {
greasedCounter.style.display = 'none';
}
if (textBox = $c('UIComposer_InputShadow')[0].firstChild) {
//INSERT THE COUNTER
var insertPoint = $c('UIComposer_Attachments')[0];
insertPoint.parentNode.insertBefore(greasedCounter, insertPoint);
textBox.parentNode.addEventListener('keyup',function () {
getNumber();
},false);
}
if ((myProfile) || (myPage.match('home'))) {
if (commentBoxAppearance == 'true') {
//ADD HOVER VISIBILITY TOGGLE
$c('UIComposer')[0].addEventListener('mouseover',function () {
$('greaseStatusControls').style.removeProperty('display');
},false);
$c('UIComposer')[0].addEventListener('mouseout',function () {
$('greaseStatusControls').style.display = 'none';
},false);
//Hovers for controls (on: 6B86B5; off: FFF;)
$('greaseStatusControlsEdit').addEventListener('mouseover',function () {
$('greaseStatusControlsEdit').firstChild.style.backgroundPosition = 'center -16px';
$('greaseStatusControlsEdit').style.backgroundColor = '#6B86B5';
},false);
$('greaseStatusControlsEdit').addEventListener('mouseout',function () {
$('greaseStatusControlsEdit').firstChild.style.backgroundPosition = 'center top';
$('greaseStatusControlsEdit').style.backgroundColor = '#FFF';
},false);
$('greaseStatusControlsClear').addEventListener('mouseover',function () {
$('greaseStatusControlsClear').firstChild.style.backgroundPosition = 'center -80px';
$('greaseStatusControlsClear').style.backgroundColor = '#6B86B5';
},false);
$('greaseStatusControlsClear').addEventListener('mouseout',function () {
$('greaseStatusControlsClear').firstChild.style.backgroundPosition = 'center -64px';
$('greaseStatusControlsClear').style.backgroundColor = '#FFF';
},false);
}
//ADD LISTENERS FOR CONTROLS
$('greaseStatusControlsEdit').addEventListener('click',function () { // Set a function for the edit status button
//PUT THE STATUS IN THE TEXT BOX
statusText = $('greaseStatusText').innerHTML; // Get the status text
statusText = statusText.replace(/ /g, ''); // Get rid of some HTML
textBox.className = 'Mentions_Input';
textBox.focus();
//This is delayed just so FB code runs first then mine.
window.setTimeout(function () {
textBox = $c('UIComposer_InputShadow')[0].firstChild;
textBox.focus();
textBox.innerHTML = statusText;
getNumber();
}, 1);
//CHANGE VISIBILITIES
if (commentBoxAppearance != 'true') {
$('greaseStatusControls').style.display = "none"; // hide controls
}
$('greaseNub').style.display = "none"; // hide nub
$('greaseStatusContent').style.display = "none"; // hide the content
$('greaseStatusControlsCancel').style.display = "block"; // show 'cancel'
},false);
$('greaseStatusControlsClear').addEventListener('click',function () { // Set a function for the clear status button
fbAjax('http://www.facebook.com/ajax/updatestatus.php', 'clear=1&profile_id='+$('user').value, true);
$('greaseStatus').style.display = "none";
$('greasedCounter').innerHTML = '0 characters';
},false);
$('greaseStatusControlsCancel').addEventListener('click',function () { // Set a function for the cancel button
//PUT THE STATUS IN THE TEXT BOX
textBox.innerHTML = "What's on your mind?"; // Set the text box contents to the status
textBox.className = 'UIComposer_TextArea DOMControl_autogrow DOMControl_placeholder';
textBox.style.height = '21px';
if (myPage.match('home')) {
$c('UIComposer')[0].className = 'UIComposer clearfix UIComposer_STATE_PIC_OUTSIDE';
} else if (myPage.match('profile')){
$c('UIComposer')[0].className = 'UIComposer clearfix UIComposer_STATE_PIC_NONE';
}
textBox.style.removeProperty("height");
$('greasedCounter').innerHTML = '0 characters';
//CHANGE VISIBILITIES
if (commentBoxAppearance != 'true') {
$('greaseStatusControls').style.removeProperty("display"); // show controls
$('greaseStatusContent').style.display = 'inline-block'; // show the content
} else {
$('greaseStatusContent').style.removeProperty("display"); // show the content
}
$('greaseNub').style.removeProperty("display"); // show nub
$('greaseStatusControlsCancel').style.display = "none"; // hide 'cancel'
},false);
//THE SHARE BUTTON
$c('UIButton_Text')[0].addEventListener('click',function () {
$('greasedCounter').innerHTML = '0 characters';
//CHECK IF A STATUS UPDATE
if ($c('UIComposer_AttachmentArea')[0].offsetHeight == 0) {
myStatus = $c('UIComposer_InputShadow')[0].firstChild.innerHTML;
myStatus = myStatus.replace('<br>','');
displayStatus(myStatus,'a moment ago');
displayExtra('','','');
GM_setValue('prevStatus', myStatus);
GM_setValue('prevTime', 'a moment ago');
}
},false);
} else {
$('greaseStatusControls').style.display = 'none';
}
}
}
window.getNumber = function () {
myStatus = $c('UIComposer_InputShadow')[0].firstChild.innerHTML.replace('<br>','');
if (myStatus == "What's on your mind?") {
$('greasedCounter').innerHTML = '0 characters';
} else {
myCounterText = myStatus.length;
if (myCounterText == 1) {
myCounterText += ' character';
} else {
myCounterText += ' characters';
}
$('greasedCounter').innerHTML = myCounterText;
}
}
window.getStatus = function () {
//If we're on the home page
if (myPage.match('home')) {
//PRELOAD
if (GM_getValue('prevStatus') != undefined) {
prevStatus = GM_getValue('prevStatus');
prevTime = GM_getValue('prevTime');
commentCount = GM_getValue('commentCount');
likeCount = GM_getValue('likeCount');
window.prepareDropArea();
displayStatus(prevStatus,prevTime);
displayExtra(commentCount,likeCount,'undefined');
}
//--- THANKS TO sizzlemctwizzle for this XTTP SECTION
if (typeof GM_xmlhttpRequest !== 'undefined')
GM_xmlhttpRequest({ // Faster fetching using mobile facebook, but requires cross-domain
method: 'GET',
overrideMimeType: 'text/html; charset=x-user-defined',
url: 'http://m.facebook.com/home.php',
onload: function(res) {
if (res.status == 200) {
form = res.responseText.match(new RegExp(/<form.*?method.*?post.*?<\/form>/gi));
for (i=0; i < form.length; i++) {
if (form[i].match('anchor_fbid')) {
form = form[i];
i = 999;
}
}
myFirstName = $('fb_menu_account').firstChild.innerHTML.match(/.*? /)[0];
status = form.match(/fbid.*? /)[0];
status = status.match(/>.*? /)[0].substring(1);
status = status.replace(myFirstName,'');
time = form.match(/<small>.*?<\/small>/)[0];
time = time.match(/\(.*?\)/)[0].substring(1);
time = time.substring(0,time.length-1);
window.basic();
window.prepareDropArea();
window.displayStatus(status, time);
GM_setValue('prevStatus',status);
GM_setValue('prevTime',time);
storyID = form.match(new RegExp(/fbid_[0-9]*/))[0].substring(5);
commentNum = likeNum = '';
//GET COMMENTS NUMBER --- WTF FB? Can you not count?
if (comments=res.responseText.match(new RegExp('<a href="/story.+?' + storyID + '.+?</a>','i'))) {
comments = comments[0].match(new RegExp('>.*<','i'))[0].replace(/\>/i,'');
commentNum = comments.match(/.+? /i)[0].replace(/ /i,'');
}
//GET PEOPLE WHO LIKE
if (likes=res.responseText.match(new RegExp(/\<img alt="like".+?like.gif.+?\<\/small>.+?\<textarea/i))) {
if (likes = likes[0].match(new RegExp(/ and \<.+?\>[0-9]+/i))) {
likeNum = likes[0].match(new RegExp(/\>[0-9]+/i));
likeNum = likeNum[0].replace(/\>/i,'');
likeNum = parseFloat(likeNum) + 1;
} else if (likes = likes[0].match(new RegExp(/\>[0-9]+/i))) {
likeNum = likes[0].replace(/\>/i,'');
} else {
likeNum=1;
}
}
displayExtra(commentNum,likeNum,storyID);
GM_setValue('commentCount',commentNum);
GM_setValue('likeCount',likeNum);
} else {
alert('Error loading status. \r\n\r\nres.status = ' + res.status);
}
}
});
else {
var xmlhttp = new XMLHttpRequest(); // Fetching from profile if cross-domain unavailable
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
if ((stat=xmlhttp.responseText.match(/<span id="status_text">(.+?)<\/span>/i))&&(time=xmlhttp.responseText.match(/<span id="status_time_inner">(.+?)<\/span>/i))&&(stat[1]!=' ')) {
window.prepareDropArea();
GM_setValue('prevStatus', stat[1]);
GM_setValue('prevTime', time[1]);
displayStatus(stat[1], time[1]);
} else {
window.prepareDropArea();
GM_setValue('prevStatus', '');
GM_setValue('prevTime', '');
displayStatus('','');
}
}
}
xmlhttp.open("GET", $('fb_menu_account').firstChild.href, true);
xmlhttp.overrideMimeType("text/html; charset=x-user-defined"); // this fixes the content type glitch...
xmlhttp.send(null);
}
} else if (myPage.match('profile')) {
if (myProfile) {
myStatus = $('status_text').innerHTML;
myTime = $('status_time_inner').innerHTML;
} else {
if ($('profile_status')) {
myStatus = $('profile_status').innerHTML
myStatus = myStatus.substring(0,myStatus.indexOf('<small>'));
myTime = $('status_time').innerHTML;
} else {
myStatus = '';
myTime = '';
}
}
window.prepareDropArea();
displayStatus(myStatus,myTime);
}
}
window.displayExtra = function (funcComm, funcLike, funcID) {
myString = '';
if (funcID != 'undefined') {
myLink = '<a href="http://www.facebook.com/profile.php?v=feed&story_fbid=' + funcID + '" style="display: inline-block;">';
} else {
myLink = '';
}
commImage = '<img class="spritemap_icons sx_icons_mini_comment" src="http://static.ak.fbcdn.net/rsrc.php/z12E0/hash/8q2anwu7.gif" alt="Comment"/>';
likeImage = '<img class="spritemap_icons sx_icons_mini_thumb" src="http://static.ak.fbcdn.net/rsrc.php/z12E0/hash/8q2anwu7.gif" alt="Like"/>'
if (funcComm != '') {
myString += myLink + commImage + ' ' + funcComm + '</a> ';
}
if (funcLike != '') {
myString += myLink + likeImage + ' ' + funcLike + '</a> ';
}
if (myString != '') { myString = ' ' + myString;}
if ($('greaseStatusExtras')) {
$('greaseStatusExtras').innerHTML = myString;
} else {
window.addEventListener('load',
function () {
displayExtra(funcComm, funcLike, funcID);
},true);
}
}
window.displayStatus = function (funcStatus, funcTime) {
if ($('greaseStatus')) {
if (funcStatus == '') {
/*****************CLEARING THE STATUS***************/
$('greaseStatus').style.display = "none"; //Hide the status area
} else {
/*****************UPDATING THE STATUS***************/
$('greaseStatus').style.removeProperty("display"); // Make sure the status area is visible
if ((myProfile) || (myPage.match('home'))) {
$('greaseStatusExtras').style.removeProperty("display"); // Show the extras
$('greaseStatusControlsCancel').style.display = "none"; // Hide the 'cancel'
if (commentBoxAppearance != 'true') {
$('greaseStatusControls').style.removeProperty("display"); // show controls
$('greaseStatusContent').style.display = "inline-block"; // Show the content
} else {
$('greaseStatusContent').style.removeProperty("display"); // Show the content
}
}
//Information
if (myPage.match('home')) {
$('greaseStatusName').innerHTML = myName + ' '; //display the name
} else if (myPage.match('profile')) {
$('greaseStatusName').innerHTML = '<a href="' + myLink + '">' + myName + '</a>';
}
funcTime = ' ' + funcTime.replace(/ /g,' ');
$('greaseStatusText').innerHTML = funcStatus + ' '; //display the status
$('greaseStatusTime').innerHTML = funcTime + ' '; //display the time
}
} else {
window.addEventListener('load',
function () {
basic();
displayStatus(funcStatus, funcTime);
},true);
}
}
// Simulate Facebook's Ajax calls --- THANKS TO sizzlemctwizzle
function fbAjax(url, params) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", url, true);
params += "&post_form_id="+unsafeWindow.Env["post_form_id"]+"&__a=1&post_form_id_source=AsyncRequest&nctr[nid]="+unsafeWindow.Env["nctrlid"]+'&nctr[id]='+unsafeWindow.env_get("nctrlid")+'&fb_dtsg='+unsafeWindow.Env["fb_dtsg"]+'&nctr[ct]='+unsafeWindow.presence.pageLoadTime;
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
}
}
xmlhttp.send(params);
}
function prep() {
//SET NAME AND LINK
if (myPage.match('home')) {
myName = $('fb_menu_account').innerHTML;
} else if (myPage.match('profile')) {
if ($('profile_action_send_message')) {
myProfile = false;
} else {
myProfile = true;
}
myName = $('profile_name').innerHTML + " ";
if (myProfile) {
myLink = $('fb_menu_profile').href;
} else { //NEED TO FIX (Don't know why it doesn't work)
myLink = $('profile_action_send_message').href;
myLink = 'http://www.facebook.com/profile.php?id=' + (myLink.substring(myLink.indexOf('=')+1));
}
}
if ((myPage.match('home'))||(myPage.match('profile'))) {
basic();
window.getStatus();
}
}
if (myPage = document.getElementsByTagName('body')[0].className) {
prep();
} else {
window.addEventListener('load',
function () {
prep();
},true);
}
