Permalink
Browse files

move functions into utils.js; remove one's one tweets from mentions c…

…ount
  • Loading branch information...
1 parent c5daea0 commit 63cd48705c25a738dda60c230c39cc2e0336eb07 @clipperhouse committed Mar 14, 2012
Showing with 84 additions and 79 deletions.
  1. +3 −2 src/background.html
  2. +11 −76 src/js/contentscript.js
  3. +69 −0 src/js/utils.js
  4. +1 −1 src/manifest.json
View
@@ -1,5 +1,6 @@
<html>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
+<script type="text/javascript" src="js/utils.js"></script>
<script>
var datakeys = {
@@ -101,8 +102,8 @@
return true;
};
-var doSearch = function (q, callback){
- var storagekey = "refreshurl." + q;
+var doSearch = function (q, callback) {
+ var storagekey = "refreshurl." + q.remove("@");
var qs = localStorage[storagekey] || "?q=" + encodeURIComponent(q) + "&rpp=100";
var url = "http://search.twitter.com/search.json" + qs;
$.getJSON(url, function (response) {
View
@@ -20,64 +20,6 @@
};
(function($) {
- $.fn.filterByData = function(key, value) {
- if (value) {
- return this.filter(function () {
- return $(this).data(key) == value;
- });
- }
- return this.filter(function () {
- return $(this).data(key) != null;
- });
- };
-
- $.fn.findByData = function(selector, key, value) {
- return this.find(selector).filterByData(key, value);
- };
-
- var attributeFn = function(j, name, value) {
- if (value) {
- return j.attr(name, value)
- }
- return j.attr(name);
- };
-
- $.fn.id = function(id) {
- return attributeFn(this, "id", id);
- };
-
- $.fn.href = function(href) {
- return attributeFn(this, "href", href);
- };
-
- $.fn.src = function(src) {
- return attributeFn(this, "src", src);
- };
-
- $.fn.title = function(title) {
- return attributeFn(this, "title", title);
- };
-
- $.fn.for = function(obj) {
- if (obj.id()) {
- return attributeFn(this, "for", obj.id())
- }
- return attributeFn(this, "for", obj);
- };
-
- $.fn.checked = function(ischecked) {
- if (ischecked === true) {
- return this.attr("checked", "checked");
- }
- if (ischecked === false) {
- return this.removeAttr("checked", "checked");
- }
- };
-
- $.fn.findByClass = function(classname) {
- return this.find("." + classname);
- };
-
var newNotifier = function(){
var s = $("<small>").addClass(bb_classnames.notify).data(bb_datanames.count, 0);
return s;
@@ -148,20 +90,18 @@
$.fn.clearNotifier = function() {
return this.getNotifier().text("").data(bb_datanames.count, 0);
};
-
- $.fn.incrementData = function(key, inc) {
- return this.data(key, this.data(key) + inc);
- };
})(jQuery);
- String.prototype.remove = function(r) { return this.replace(r, ''); };
- String.prototype.removePrefix = function(r) { return this.remove(/^bb\-/); };
- String.prototype.last = function() { return this[this.length - 1]; };
-
var filterRTs = function(element) {
return element['text'] != null && element['text'].indexOf("RT ") != 0;
};
+ var filterUser = function (username) {
+ return function(element) {
+ return element['from_user'] != null && element['from_user'] != username.remove("@");
+ };
+ }
+
var body = $(document.body);
var wrapper = $("div.wrapper");
var dashboard = $("div.dashboard", wrapper);
@@ -347,9 +287,7 @@
var searchAll = function() {
updateSearches();
- for (var i in searches) {
- doSearch(searches[i]);
- }
+ searches.forEach(doSearch);
};
var doSearch = function(q) {
@@ -381,7 +319,7 @@
var elements = $("a.account-summary div.account-group").first();
mentions = $.map(elements, function (a) {
- return $(a).data("screen-name");
+ return "@" + $(a).data("screen-name");
});
if (mentions.length) {
@@ -400,12 +338,11 @@
var updateMentions = function (response) {
var q = decodeURIComponent(response.query).replace('+', ' ');
- var count = response.results.filter(filterRTs).length;
+ var count = response.results.filter(filterRTs).filter(filterUser(q)).length;
var datakey = "search-query";
-
var a = mentionsModule.content.findByData("a", datakey, q);
if (a.length == 0) {
- a = $("<a>").data(datakey, q).href("/#!/mentions/").text("@" + q)
+ a = $("<a>").data(datakey, q).href("/#!/mentions/").text(q)
.addNotifier()
.click(function(){
$(this).clearNotifier();
@@ -418,9 +355,7 @@
};
var mentionsAll = function() {
- for (var i in mentions) {
- doMentions(mentions[i]);
- }
+ mentions.forEach(doMentions);
};
var doMentions = function(q) {
View
@@ -0,0 +1,69 @@
+(function () {
+ (function($) {
+ $.fn.filterByData = function(key, value) {
+ if (value) {
+ return this.filter(function () {
+ return $(this).data(key) == value;
+ });
+ }
+ return this.filter(function () {
+ return $(this).data(key) != null;
+ });
+ };
+
+ $.fn.findByData = function(selector, key, value) {
+ return this.find(selector).filterByData(key, value);
+ };
+
+ var attributeFn = function(j, name, value) {
+ if (value) {
+ return j.attr(name, value)
+ }
+ return j.attr(name);
+ };
+
+ $.fn.id = function(id) {
+ return attributeFn(this, "id", id);
+ };
+
+ $.fn.href = function(href) {
+ return attributeFn(this, "href", href);
+ };
+
+ $.fn.src = function(src) {
+ return attributeFn(this, "src", src);
+ };
+
+ $.fn.title = function(title) {
+ return attributeFn(this, "title", title);
+ };
+
+ $.fn.for = function(obj) {
+ if (obj.id()) {
+ return attributeFn(this, "for", obj.id())
+ }
+ return attributeFn(this, "for", obj);
+ };
+
+ $.fn.checked = function(ischecked) {
+ if (ischecked === true) {
+ return this.attr("checked", "checked");
+ }
+ if (ischecked === false) {
+ return this.removeAttr("checked", "checked");
+ }
+ };
+
+ $.fn.findByClass = function(classname) {
+ return this.find("." + classname);
+ };
+
+ $.fn.incrementData = function(key, inc) {
+ return this.data(key, this.data(key) + inc);
+ };
+ })(jQuery);
+
+ String.prototype.remove = function(r) { return this.replace(r, ''); };
+ String.prototype.removePrefix = function(r) { return this.remove(/^bb\-/); };
+ String.prototype.last = function() { return this[this.length - 1]; };
+})();
View
@@ -14,7 +14,7 @@
{
"matches": ["*://twitter.com/*"],
"css": ["styles.css"],
- "js": ["js/jquery-1.7.1.min.js", "js/jquery.hoverIntent.min.js", "js/contentscript.js"]
+ "js": ["js/jquery-1.7.1.min.js", "js/jquery.hoverIntent.min.js", "js/utils.js", "js/contentscript.js"]
}
],
"permissions": [

0 comments on commit 63cd487

Please sign in to comment.