|
|
| A.cc Extension: Ban Poster |
|
ImLeftFooted
Member #3,935
October 2003
|
New a.cc javascript extension. Adds a 'ban' link by every post which can be used to ban that annoying user you're tired of hearing from.
To install, select all of this text (make sure to scroll down!) and copy it to your clipboard (control + C): // Ignore Poster app Version 0.1 // // namespace: ban // This class represents a post in the thread // // class ban_Post // { // id should reference an id value for the table containing the post. // doc is an option value. Defaults to global document. function ban_Post(id, doc) { if(!doc) doc = document; this.id = id; this.doc = doc; this.table = doc.getElementById(id); this.tableBackup = null; this.memberId = this.getMemberId(); this.showing = true; } ban_Post.prototype.createBackup = function() { this.tableBackup = this.table.cloneNode(true); } ban_Post.prototype.hide = function() { if(!this.showing) return; this.table.innerHTML = '<tr><td><center>Poster banned. <a id="ban_link' + ++ban_linkNum + '" href="javascript:;">unban</a></center></td></tr>'; this.showing = false; var post = this; this.doc.getElementById("ban_link" + ban_linkNum).onclick = function() { var id = post.memberId; if(id.length) ban_setBanned(id, false); post.show(); } } ban_Post.prototype.show = function() { if(this.showing) return; this.table.parentNode.replaceChild(this.tableBackup.cloneNode(true), this.table); this.showing = true; } // Returns true if this post should be banned or false otherwise ban_Post.prototype.isBanned = function() { var id = this.getMemberId(); return id.length ? ban_isBanned(id) : false; } ban_Post.prototype.getMemberId = function() { var str = this.table.className.toString(); var end = str.indexOf(' '); if(end == -1) return ""; var ret = str.substring(1, end); if(ret == null) ret = ""; return ret; } ban_Post.prototype.getHeader = function() { var divs = this.table.getElementsByTagName("DIV"); for(var i = 0; i < divs.length; i++) if(divs[i].className == "header") return divs[i].innerHTML; return null; } ban_Post.prototype.setHeader = function(header) { var divs = this.table.getElementsByTagName("DIV"); for(var i = 0; i < divs.length; i++) if(divs[i].className == "header") divs[i].innerHTML = header; } // } // Returns true if the member with id 'memberId' is banned. // isBanned finds this information in the cookies function ban_isBanned(memberId) { return ban_readCookie("ban_" + memberId) != null; } // Sets the member with id 'memberId' to either banned or // not banned depending on if 'isBanned' is true or false // respectively. function ban_setBanned(memberId, isBanned) { if(isBanned == null || isBanned) ban_createCookie("ban_" + memberId, 1); else ban_eraseCookie("ban_" + memberId); ban_updateBans(); } // Returns a list of ban_Post instances that have been found // doc is the document to search, defaults to the global document function ban_findPosts(doc) { if(!doc) doc = document; var tables = doc.getElementsByTagName("table"); var posts = new Array; for(var i = 0; i < tables.length; i++) if(tables[i].id.indexOf("post-") == 0) posts[posts.length] = new ban_Post(tables[i].id, doc); return posts; } var ban_linkNum = 0; function ban_updateBans() { if(posts == null) return; for(var i = 0; i < posts.length; i++) if(posts[i].isBanned()) posts[i].hide(); else posts[i].show(); } var posts = null; function ban_load_helper(aTag) { aTag.onclick = function() { if(this.ban_memberId) ban_setBanned(this.ban_memberId); } } function ban_load() { posts = ban_findPosts(document); for(var i = 0; i < posts.length; i++) { posts[i].setHeader(posts[i].getHeader() + '<a id="ban_link' + ++ban_linkNum + '" href="javascript:;">Ban</a>'); var a = document.getElementById("ban_link" + ban_linkNum); if(a != null) { a.ban_memberId = posts[i].memberId; ban_load_helper(a); } posts[i].createBackup(); if(posts[i].isBanned()) posts[i].hide(); } } doc.add_onLoad(ban_load); // Cookies! // { function ban_createCookie(name,value,days) { if(days == null) days = 365; var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); document.cookie = name+"="+value+expires+"; path=/"; } function ban_readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function ban_eraseCookie(name) { ban_createCookie(name,"",-1); } // }Then navigate to the extensions page and select the bottom text box with your mouse and paste (control + V). You must be logged in to navigate to this page. Click save and enjoy! png;972;768;160;126 |
|
Jakub Wasilewski
Member #3,653
June 2003
|
Dustin, how nice of you to choose me as the example --------------------------- |
|
ImLeftFooted
Member #3,935
October 2003
|
Sorry, what was that now? |
|
kentl
Member #2,905
November 2002
|
Does this work in practise? What if you have a problem which the banned user answers. Then you write something like "Anyone?" after he has given the answer. It will look strange anyway. |
|
Kauhiz
Member #4,798
July 2004
|
Pretty cool, thanks Dustin! kentl: Look at the screenshot --- |
|
kentl
Member #2,905
November 2002
|
Quote:
kentl: Look at the screenshot
Yes I looked at it before I posted. |
|
Kauhiz
Member #4,798
July 2004
|
It says poster banned when a banned poster posts (man, that sounded like a nursery rhyme or something). So you won't just be oblivious to someone posting. And you can unban them just as easily. --- |
|
kentl
Member #2,905
November 2002
|
But when would you actually keep someone banned? It could get strange in almost every kind of situation if you miss a post by someone. And if you always have to switch between banned and unbanned it sounds like it will get tedious and more annoying than just skimming through uninteresting posts. |
|
BAF
Member #2,981
December 2002
|
I guess a cooler, but not necessarily any more usable approach would be to show the post as normal, but hide the whole thing with the poster blocked message, then provide a link to view the post anyway (without unblocking them). Also, block is the correct word here, because you aren't really banning them, just blocking them. |
|
Sirocco
Member #88
April 2000
|
Funny. Allegro.cc is one of the only boards I'm on where I wouldn't even consider blocking someone. --> |
|
ImLeftFooted
Member #3,935
October 2003
|
Quote:
Also, block is the correct word here, because you aren't really banning them, just blocking them.
Yes but isn't "banning" someone a tad more satisfying? |
|
|