Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

usernames have single quotes/apostrophes in them
  • Loading branch information...
commit 9502d14aaf192d7253e3b27d5e5e9092cd61b669 1 parent d26b7f9
ciphero authored

Showing 1 changed file with 43 additions and 20 deletions. Show diff stats Hide diff stats

  1. +43 20 js/baNdit_thread.js
63 js/baNdit_thread.js
@@ -11,6 +11,8 @@ const BanditIgnoreReplyType = {
11 11 NON_ATTENTION : 2,
12 12 };
13 13
  14 +const WebmonkeesURL = "http://webmonkees.com/naBBits/";
  15 +
14 16 function GetDefaultUserOptions(username) {
15 17 return {
16 18 userName: username || "",
@@ -218,6 +220,12 @@ function PreProcessCommentsPage() {
218 220
219 221 var username = commentHeader.children("span.ui:first").text();
220 222
  223 + // this shenanignans inserts nabbit icon links.
  224 + // TODO: move into global extension settings, to even do this?
  225 + var userIDSpan = commentHeader.children(".uid");
  226 + var timeSpan = commentHeader.children(".time");
  227 + InjectNabbitLinks(userIDSpan.text(), userIDSpan, timeSpan);
  228 +
221 229 ThreadPosters.push(username);
222 230
223 231 commentHeader.attr("username", username);
@@ -229,6 +237,13 @@ function PreProcessCommentsPage() {
229 237 ThreadPosters = baNdit_unique(ThreadPosters);
230 238 }
231 239
  240 +function InjectNabbitLinks(userID, userIDSpan, timestampSpan) {
  241 + 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));
  242 + if(userID != 0) {
  243 + 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));
  244 + }
  245 +}
  246 +
232 247 function ForEachPoster(fn) {
233 248 // fn must take a userOptions object as it's one parameter
234 249 if(!fn || !ThreadPosters || ThreadPosters.length == 0) return;
@@ -236,7 +251,7 @@ function ForEachPoster(fn) {
236 251 $.each(ThreadPosters, function() {
237 252 var userOptions = GetUserOptions(this);
238 253
239   - if(!userOptions) continue;
  254 + if(!userOptions) return;
240 255
241 256 fn(userOptions);
242 257 });
@@ -245,7 +260,11 @@ function ForEachPoster(fn) {
245 260 function InitializeUserNotes() {
246 261 ForEachPoster(SetUserNotes);
247 262 }
  263 +
248 264 function ClearUserNotes(username) {
  265 + // handle usernames with single quotes
  266 + username = MakeUsernameSelectorSafe(username);
  267 +
249 268 $("div.ch[username='{0}'] span.ui a abbr".format(username)).each(function(){
250 269 var node = $(this);
251 270 var text = node.text();
@@ -257,8 +276,9 @@ function SetUserNotes(userOptions) {
257 276 if(!userOptions) return;
258 277
259 278 var needsUserNotes = stringNotEmpty(userOptions.notes);
  279 + var username = MakeUsernameSelectorSafe(userOptions.userName);
260 280
261   - ClearUserNotes(userOptions.userName);
  281 + ClearUserNotes(username);
262 282
263 283 if(!needsUserNotes) return;
264 284
@@ -271,7 +291,7 @@ function SetUserNotes(userOptions) {
271 291
272 292 var abbrContent = fakeDiv.html();
273 293
274   - $("div.ch[username='{0}'] span.ui a".format(userOptions.userName))
  294 + $("div.ch[username='{0}'] span.ui a".format(username))
275 295 .each(function() {
276 296 $(this)
277 297 .css("text-decoration", "none")
@@ -291,10 +311,10 @@ function ClearUserColors(username) {
291 311
292 312 function SetUserColors(userOptions) {
293 313 if(!userOptions) return;
294   -
295   - ClearUserColors(userOptions.userName);
  314 + username = MakeUsernameSelectorSafe(userOptions.userName);
296 315
297   - $("div.ch[username='{0}']".format(userOptions.userName))
  316 + ClearUserColors(username);
  317 + $("div.ch[username='{0}']".format(username))
298 318 .each(function() {
299 319 $(this)
300 320 .css("background-color", userOptions.bgColor || null)
@@ -308,13 +328,13 @@ function SetUserColors(userOptions) {
308 328
309 329 function PayAttentionToUser(userOptions) {
310 330 if(!userOptions) return;
311   -
312   - UnmarkUserToPayAttention(userOptions.userName);
  331 + username = MakeUsernameSelectorSafe(userOptions.userName);
  332 + UnmarkUserToPayAttention(username);
313 333
314 334 var ignore = parseInt(userOptions.ignore) || BanditIgnoreType.NONE;
315 335
316 336 if(ignore == BanditIgnoreType.PAY_ATTENTION) {
317   - MarkUserToPayAttention(userOptions.userName);
  337 + MarkUserToPayAttention(username);
318 338 }
319 339 }
320 340
@@ -328,7 +348,7 @@ function InitializeIgnoredUsers() {
328 348 }
329 349
330 350 function RedisplayUser(userOptions) {
331   - var username = userOptions.userName;
  351 + var username = MakeUsernameSelectorSafe(userOptions.userName);
332 352 $("div.ch[username='{0}'],div.cb[username='{0}']".format(username)).show();
333 353 $("div.ch[username='{0}'] span.baNdit_hide".format(username)).remove();
334 354 $("hr.baNdit_superIgnore[username='{0}']".format(username)).remove();
@@ -500,30 +520,30 @@ function SuperIgnoreUser(username) {
500 520 // TODO: Add "Ignored users in this thread" to toolbar button
501 521 function IgnoreUsers(userOptions) {
502 522 var ignore = parseInt(userOptions.ignore) || BanditIgnoreType.NONE;
503   -
  523 + var username = MakeUsernameSelectorSafe(userOptions.userName);
504 524 switch(ignore) {
505 525 case BanditIgnoreType.IGNORE_USER:
506   - IgnoreUser(userOptions.userName);
507   - IgnoreReplies(userOptions);
  526 + IgnoreUser(username);
  527 + IgnoreReplies(username);
508 528 break;
509 529 case BanditIgnoreType.SUPERIGNORE_USER:
510   - SuperIgnoreUser(userOptions.userName);
511   - IgnoreReplies(userOptions);
  530 + SuperIgnoreUser(username);
  531 + IgnoreReplies(username);
512 532 break;
513 533 }
514 534 }
515 535
516   -function IgnoreReplies(userOptions) {
  536 +function IgnoreReplies(username) {
517 537 var ignoreReplies = parseInt(userOptions.ignoreReplies) || BanditIgnoreReplyType.NONE;
518 538
519 539 switch(ignoreReplies) {
520 540 case BanditIgnoreReplyType.NONE:
521 541 break;
522 542 case BanditIgnoreReplyType.ALL:
523   - IgnoreAllRepliesTo(userOptions.userName);
  543 + IgnoreAllRepliesTo(username);
524 544 break;
525 545 case BanditIgnoreReplyType.NON_ATTENTION:
526   - IgnoreAllNonAttentionRepliesTo(userOptions.userName);
  546 + IgnoreAllNonAttentionRepliesTo(username);
527 547 break;
528 548 }
529 549 }
@@ -707,6 +727,10 @@ function GetIMGTagDialog() {
707 727 return tagDialog;
708 728 }
709 729
  730 +function MakeUsernameSelectorSafe(name) {
  731 + return name.replace(/'/g, '\\\'');
  732 +}
  733 +
710 734 function HTMLToolbar_AddLink() {
711 735 GetHTMLTagDialog().dialog("open");
712 736 }
@@ -820,7 +844,6 @@ function baNdit_main() {
820 844 InitializePaidAttentionUsers();
821 845 InitializeIgnoredUsers();
822 846 MarkPostsAboveCoolScore();
823   -
824 847 AddHTMLToolbar();
825 848
826 849 SetupPasteHandler();
@@ -828,4 +851,4 @@ function baNdit_main() {
828 851 CreateUserOptionsDialogs();
829 852 }
830 853
831   -baNdit_main();
  854 +baNdit_main();

0 comments on commit 9502d14

Please sign in to comment.
Something went wrong with that request. Please try again.