Created
September 1, 2009 20:14
-
-
Save scottferg/179348 to your computer and use it in GitHub Desktop.
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
var settings = {}; | |
/** | |
* Event listener for when a user enters their username within | |
* the extension UI. Currently this only works when you're | |
* viewing forums.somethingawful.com since we don't have any | |
* events that can be fired on a localStorage event that occurs | |
* within the extension. | |
* | |
*/ | |
var port = chrome.extension.connect(); | |
port.onMessage.addListener(function(data) { | |
settings.username = data.username; | |
settings.darkRead = data.darkRead; | |
darkRead = data.darkRead; | |
settings.lightRead = data.lightRead; | |
settings.darkNewReplies = data.darkNewReplies; | |
settings.lightNewReplies = data.lightNewReplies; | |
}); | |
// Request the username from the extension UI | |
port.postMessage({ | |
'message': 'GetPageSettings' | |
}); | |
// If a post has the user quoted, highlight it a pleasant green | |
jQuery('.bbc-block h4').each(function() { | |
var username = settings.username; | |
if (jQuery(this).html() == username + ' posted:') { | |
jQuery(this).parent().css("background-color", "#a2cd5a"); | |
} | |
}); | |
var newPosts = false; | |
var newPostCount = 0; | |
// Iterate over each .thread .seen td element. This is necessary | |
// so we can track each thread's designated color (read/not read) | |
jQuery('tr.thread.seen').each(function() { | |
// Re-style the "mark unread" link | |
jQuery(this).find('a.x').each(function() { | |
// Set the image styles | |
jQuery(this).css("background", "none"); | |
jQuery(this).css("background-image", "url('" + chrome.extension.getURL("images/") + "unvisit.png')"); | |
jQuery(this).css("height", "16px"); | |
jQuery(this).css("width", "14px"); | |
// Remove the 'X' from the anchor tag | |
jQuery(this).html(''); | |
}); | |
// Re-style the new post count link | |
jQuery(this).find('a.count').each(function() { | |
// If we find an a.count, then we have new posts | |
newPosts = true; | |
newPostCount = jQuery(this).html(); | |
// Remove the left split border | |
jQuery(this).css("border-left", "none"); | |
// Resize, shift, and add in the background image | |
jQuery(this).css("width", "7px"); | |
jQuery(this).css("height", "16px"); | |
jQuery(this).css("padding-right", "11px"); | |
jQuery(this).css("background-image", "url('" + chrome.extension.getURL("images/") + "lastpost.png')"); | |
// Remove the count from the element | |
jQuery(this).html(''); | |
}); | |
// If the thread has new posts, display the green shade, | |
// otherwise show the blue shade | |
var darkShade = (newPosts) ? settings.darkNewReplies : settings.darkRead; | |
var lightShade = (newPosts) ? settings.lightNewReplies : settings.lightRead; | |
// Thread icon, author, view count, and last post | |
jQuery(this).children('td.icon, td.author, td.views, td.lastpost').each(function() { | |
jQuery(this).css({ "background-color" : darkShade, | |
"background-image" : "url('" + chrome.extension.getURL("images/") + "gradient.png')", | |
"background-repeat" : "repeat-x" | |
}); | |
}); | |
// Thread title, replies, and rating | |
jQuery(this).find('td.title, td.replies, td.rating').each(function() { | |
jQuery(this).css({ "background-color" : lightShade, | |
"background-image" : "url('" + chrome.extension.getURL("images/") + "gradient.png')", | |
"background-repeat" : "repeat-x" | |
}); | |
}); | |
// Display number of new replies for each thread | |
jQuery(this).find('td.replies').each(function() { | |
// Add in number of new replies | |
if (newPostCount != 0) { | |
var currentHtml = jQuery(this).html(); | |
// Strip HTML tags | |
newPostCount = parseInt(newPostCount.replace(/(<([^>]+)>)/ig, "")); | |
// Set the HTML value | |
jQuery(this).html(currentHtml + "<br /><div style='font-size: 12px;'>(" + newPostCount + ")</div>"); | |
} | |
}); | |
// Eliminate last-seen styling | |
jQuery(this).find('.lastseen').each(function() { | |
jQuery(this).css("background", "none"); | |
jQuery(this).css("border", "none"); | |
}); | |
// Reset post counts | |
newPosts = false; | |
newPostCount = 0; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment