Browse files

Make baNdit load. Add naBBit links for users. Stop infinite loop when

usernames have single quotes/apostrophes in them
  • Loading branch information...
1 parent d26b7f9 commit 9502d14aaf192d7253e3b27d5e5e9092cd61b669 @ciphero committed Sep 30, 2011
Showing with 43 additions and 20 deletions.
  1. +43 −20 js/baNdit_thread.js
View
63 js/baNdit_thread.js
@@ -11,6 +11,8 @@ const BanditIgnoreReplyType = {
NON_ATTENTION : 2,
};
+const WebmonkeesURL = "http://webmonkees.com/naBBits/";
+
function GetDefaultUserOptions(username) {
return {
userName: username || "",
@@ -218,6 +220,12 @@ function PreProcessCommentsPage() {
var username = commentHeader.children("span.ui:first").text();
+ // this shenanignans inserts nabbit icon links.
+ // TODO: move into global extension settings, to even do this?
+ var userIDSpan = commentHeader.children(".uid");
+ var timeSpan = commentHeader.children(".time");
+ InjectNabbitLinks(userIDSpan.text(), userIDSpan, timeSpan);
+
ThreadPosters.push(username);
commentHeader.attr("username", username);
@@ -229,14 +237,21 @@ function PreProcessCommentsPage() {
ThreadPosters = baNdit_unique(ThreadPosters);
}
+function InjectNabbitLinks(userID, userIDSpan, timestampSpan) {
+ userIDSpan.html("<img src=\"{0}{1}.gif\" width=58 height=18 alt=({1}) title=({1}) onerror=\"this.onerror=null;this.src='http://cdn.bannination.net/172/img/blank.gif'\">".format(WebmonkeesURL, userID));
+ if(userID != 0) {
+ timestampSpan.html(timestampSpan.html() + "<a href={0}0/notes.htm#{1}><img src=\"{0}m{1}.png\" width=180 height=18 align=top id=({1}) title=\"{1}\" border=0 onerror=\"this.onerror=null;this.src='http://cdn.bannination.net/172/img/blank.gif'\"></a>".format(WebmonkeesURL, userID));
+ }
+}
+
function ForEachPoster(fn) {
// fn must take a userOptions object as it's one parameter
if(!fn || !ThreadPosters || ThreadPosters.length == 0) return;
$.each(ThreadPosters, function() {
var userOptions = GetUserOptions(this);
- if(!userOptions) continue;
+ if(!userOptions) return;
fn(userOptions);
});
@@ -245,7 +260,11 @@ function ForEachPoster(fn) {
function InitializeUserNotes() {
ForEachPoster(SetUserNotes);
}
+
function ClearUserNotes(username) {
+ // handle usernames with single quotes
+ username = MakeUsernameSelectorSafe(username);
+
$("div.ch[username='{0}'] span.ui a abbr".format(username)).each(function(){
var node = $(this);
var text = node.text();
@@ -257,8 +276,9 @@ function SetUserNotes(userOptions) {
if(!userOptions) return;
var needsUserNotes = stringNotEmpty(userOptions.notes);
+ var username = MakeUsernameSelectorSafe(userOptions.userName);
- ClearUserNotes(userOptions.userName);
+ ClearUserNotes(username);
if(!needsUserNotes) return;
@@ -271,7 +291,7 @@ function SetUserNotes(userOptions) {
var abbrContent = fakeDiv.html();
- $("div.ch[username='{0}'] span.ui a".format(userOptions.userName))
+ $("div.ch[username='{0}'] span.ui a".format(username))
.each(function() {
$(this)
.css("text-decoration", "none")
@@ -291,10 +311,10 @@ function ClearUserColors(username) {
function SetUserColors(userOptions) {
if(!userOptions) return;
-
- ClearUserColors(userOptions.userName);
+ username = MakeUsernameSelectorSafe(userOptions.userName);
- $("div.ch[username='{0}']".format(userOptions.userName))
+ ClearUserColors(username);
+ $("div.ch[username='{0}']".format(username))
.each(function() {
$(this)
.css("background-color", userOptions.bgColor || null)
@@ -308,13 +328,13 @@ function SetUserColors(userOptions) {
function PayAttentionToUser(userOptions) {
if(!userOptions) return;
-
- UnmarkUserToPayAttention(userOptions.userName);
+ username = MakeUsernameSelectorSafe(userOptions.userName);
+ UnmarkUserToPayAttention(username);
var ignore = parseInt(userOptions.ignore) || BanditIgnoreType.NONE;
if(ignore == BanditIgnoreType.PAY_ATTENTION) {
- MarkUserToPayAttention(userOptions.userName);
+ MarkUserToPayAttention(username);
}
}
@@ -328,7 +348,7 @@ function InitializeIgnoredUsers() {
}
function RedisplayUser(userOptions) {
- var username = userOptions.userName;
+ var username = MakeUsernameSelectorSafe(userOptions.userName);
$("div.ch[username='{0}'],div.cb[username='{0}']".format(username)).show();
$("div.ch[username='{0}'] span.baNdit_hide".format(username)).remove();
$("hr.baNdit_superIgnore[username='{0}']".format(username)).remove();
@@ -500,30 +520,30 @@ function SuperIgnoreUser(username) {
// TODO: Add "Ignored users in this thread" to toolbar button
function IgnoreUsers(userOptions) {
var ignore = parseInt(userOptions.ignore) || BanditIgnoreType.NONE;
-
+ var username = MakeUsernameSelectorSafe(userOptions.userName);
switch(ignore) {
case BanditIgnoreType.IGNORE_USER:
- IgnoreUser(userOptions.userName);
- IgnoreReplies(userOptions);
+ IgnoreUser(username);
+ IgnoreReplies(username);
break;
case BanditIgnoreType.SUPERIGNORE_USER:
- SuperIgnoreUser(userOptions.userName);
- IgnoreReplies(userOptions);
+ SuperIgnoreUser(username);
+ IgnoreReplies(username);
break;
}
}
-function IgnoreReplies(userOptions) {
+function IgnoreReplies(username) {
var ignoreReplies = parseInt(userOptions.ignoreReplies) || BanditIgnoreReplyType.NONE;
switch(ignoreReplies) {
case BanditIgnoreReplyType.NONE:
break;
case BanditIgnoreReplyType.ALL:
- IgnoreAllRepliesTo(userOptions.userName);
+ IgnoreAllRepliesTo(username);
break;
case BanditIgnoreReplyType.NON_ATTENTION:
- IgnoreAllNonAttentionRepliesTo(userOptions.userName);
+ IgnoreAllNonAttentionRepliesTo(username);
break;
}
}
@@ -707,6 +727,10 @@ function GetIMGTagDialog() {
return tagDialog;
}
+function MakeUsernameSelectorSafe(name) {
+ return name.replace(/'/g, '\\\'');
+}
+
function HTMLToolbar_AddLink() {
GetHTMLTagDialog().dialog("open");
}
@@ -820,12 +844,11 @@ function baNdit_main() {
InitializePaidAttentionUsers();
InitializeIgnoredUsers();
MarkPostsAboveCoolScore();
-
AddHTMLToolbar();
SetupPasteHandler();
CreateUserOptionsDialogs();
}
-baNdit_main();
+baNdit_main();

0 comments on commit 9502d14

Please sign in to comment.