Permalink
Browse files

Initial import

  • Loading branch information...
cfinke committed May 3, 2011
0 parents commit b1d63ae74eacddcdaad6259b44be0c670c576e7f
@@ -0,0 +1,9 @@
+Comment Snob is an extension for Google Chrome that filters out undesirable comments from comment threads on the Web.
+
+* More than # spelling mistakes.
+* All capital letters
+* No capital letters
+* Doesn't start with a capital letter
+* Excessive punctuation (!!!! ????)
+* Excessive capitalization
+* Profanity
@@ -0,0 +1,95 @@
+{
+ "extName": {
+ "message": "Comment Snob"
+ },
+ "extDescription": {
+ "message": "Filters out undesirable comments from the Web."
+ },
+ "action_save": {
+ "message": "Save"
+ },
+ "options_page_title": {
+ "message": "Comment Snob Options"
+ },
+ "label_site": {
+ "message": "Site:"
+ },
+ "label_hide_all": {
+ "message": "Hide all comments"
+ },
+ "label_hide_no_capital": {
+ "message": "Hide comments that have no capital letters."
+ },
+ "label_hide_only_capital": {
+ "message": "Hide comments that have only capital letters."
+ },
+ "label_hide_start_lower": {
+ "message": "Hide comments that do not start with a capital letter."
+ },
+ "label_hide_too_much_punctuation": {
+ "message": "Hide comments that have excessive punctuation. (!!!!! ?????)"
+ },
+ "label_hide_too_much_capitalization": {
+ "message": "Hide comments that have excessive capitalization."
+ },
+ "label_hide_too_much_profanity": {
+ "message": "Hide comments that include profanity."
+ },
+ "label_hide_spelling": {
+ "message": "Hide comments with at least this many spelling mistakes. (Set to zero to disable spellchecking.)"
+ },
+ "label_hidden_reason": {
+ "message": "Comment hidden ($reason$)",
+ "placeholders": {
+ "reason": {
+ "content": "$1"
+ }
+ }
+ },
+ "label_show": {
+ "message": "Show"
+ },
+ "label_hide": {
+ "message": "Hide"
+ },
+ "reason_no_capital": {
+ "message": "No capital letters",
+ "description": "A reason shown to the user when hiding a comment."
+ },
+ "reason_only_capital": {
+ "message": "All capital letters",
+ "description": "A reason shown to the user when hiding a comment."
+ },
+ "reason_start_lower": {
+ "message": "Doesn't start with a capital letter",
+ "description": "A reason shown to the user when hiding a comment."
+ },
+ "reason_too_much_punctuation": {
+ "message": "Excessive punctuation",
+ "description": "A reason shown to the user when hiding a comment."
+ },
+ "reason_too_much_capitalization": {
+ "message": "Excessive capitalization",
+ "description": "A reason shown to the user when hiding a comment."
+ },
+ "reason_too_much_profanity": {
+ "message": "Profanity",
+ "description": "A reason shown to the user when hiding a comment."
+ },
+ "reason_spelling": {
+ "message" : "Too many spelling mistakes",
+ "description": "A reason shown to the user when hiding a comment."
+ },
+ "option_default": {
+ "message": "(Default)"
+ },
+ "action_remove": {
+ "message": "Remove This Rule"
+ },
+ "action_add": {
+ "message": "Add a new rule"
+ },
+ "install_rule": {
+ "message": "Install a Comment Snob Rule from this page"
+ }
+}
@@ -0,0 +1,5 @@
+<script src="jquery.js" type="text/javascript"></script>
+<script src="lib/typo/typo.js" type="text/javascript"></script>
+<script src="comment-snob.js" type="text/javascript"></script>
+<script src="minify.json.js" type="text/javascript"></script>
+<script src="background.js" type="text/javascript"></script>
@@ -0,0 +1,90 @@
+var currentRules = null;
+var dictionaryObject = null;
+
+chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
+ currentRules = null;
+
+ // Re-get the rules for this tab.
+ chrome.tabs.sendRequest(tabId, { subject : "rules" });
+
+ // Check if this page matches any of the rules.
+ var rules = COMMENT_SNOB.prefs.getJSONPref("rules", {});
+
+ for (var i in rules) {
+ var regex = new RegExp(rules[i].url, "i");
+
+ if (tab.url.match(regex)) {
+ var prefs = COMMENT_SNOB.getRulePrefs(i);
+
+ var response = {
+ subject : "filter",
+ rule : rules[i],
+ prefs : prefs
+ };
+
+ if (prefs.mistakes) {
+ if (!dictionaryObject) {
+ dictionaryObject = JSON.parse(JSON.stringify(new Typo("en_US")));
+ }
+
+ response.dictionaryObject = dictionaryObject;
+ }
+
+ chrome.tabs.sendRequest(tabId, response);
+
+ break;
+ }
+ }
+});
+
+chrome.extension.onRequest.addListener(function (request, sender, sendResponse) {
+ if (request.subject === "install_rule") {
+ if ("rule" in request.rule) {
+ var rv = COMMENT_SNOB.addRule(request.rule.rule);
+ sendResponse(rv);
+ }
+ else if ("href" in request.rule) {
+ function handleText(text) {
+ var text = JSON.minify(text);
+
+ try {
+ var json = JSON.parse(text);
+ } catch (e) {
+ sendResponse({ status : false, msg : "Invalid JSON: " + e });
+ return;
+ }
+
+ var rv = COMMENT_SNOB.addRule(json);
+ sendResponse(rv);
+ }
+
+ if (request.rule.href.indexOf("data:") === 0) {
+ var parts = request.rule.href.split(";");
+
+ if (parts[1].indexOf("base64,") === 0) {
+ var text = atob(parts[1].replace("base64,", ""));
+ }
+ else {
+ var text = decodeURIComponent(parts[1].replace(/\+/g, " "));
+ }
+
+ handleText(text);
+ }
+ else {
+ var req = new XMLHttpRequest();
+ req.open("GET", request.rule.href, true);
+
+ req.onreadystatechange = function () {
+ if (req.readyState == 4) {
+ var text = req.responseText;
+ handleText(text);
+ }
+ };
+
+ req.send(null);
+ }
+ }
+ }
+});
+
+COMMENT_SNOB.load();
Oops, something went wrong.

0 comments on commit b1d63ae

Please sign in to comment.