Browse files

Removed main functionality out into separate file.

  • Loading branch information...
1 parent 44052aa commit 58215dd88f64edbeb1aed50046e60772350fdd47 @andrew-smith committed Jul 11, 2012
Showing with 74 additions and 79 deletions.
  1. +67 −0 base_contentscript.js
  2. +2 −2 manifest.json
  3. +5 −77 tf2tp_script.js
View
67 base_contentscript.js
@@ -0,0 +1,67 @@
+
+
+//formats item detail description
+function formatItemDetails(element, response)
+{
+ var itemDetails = "";
+ if(response.items.length == 0) {
+ itemDetails += "ERROR: Cannot find item";
+ }
+ else {
+ for(var i=0; i<response.items.length; i++)
+ {
+ var item = response.items[i];
+ itemDetails += "(" + item.quality + ") " + item.name + " (Est: " + item.est_price + ")" + _NL;
+ }
+ }
+
+ return itemDetails;
+}
+
+
+//ensures the data is valid before adding it to the string
+function validateDetails(name, object)
+{
+ if(object && object != "-1")
+ {
+ return "<p>" + name + ": " + object + "</p>";
+ }
+ else return "";
+}
+
+
+
+function getItemDetails(name, callback)
+{
+ chrome.extension.sendMessage({type: "item_details", itemName: name}, function(response) {
+ callback(response);
+ });
+}
+
+//creates a hovering element next to an element
+function hoverDetails(element, itemDetails)
+{
+//add a qtip popup
+$(element).qtip({
+ content: itemDetails,
+ style: {
+ name: 'dark',
+ width: {
+ min: 10,
+ max: 600
+ }
+ },
+ position: {
+ corner: {
+ target: 'bottomRight',
+ tooltip: 'bottomLeft'
+ }
+ },
+ show: { event: 'mouseover' },
+ hide: 'mouseout'
+}).qtip("updateWidth");
+
+$(element).qtip("updateWidth");
+$(element).qtip("api").updateContent(itemDetails, true);
+
+}
View
4 manifest.json
@@ -1,7 +1,7 @@
{
// Required
"name": "TF2 Item Linker",
- "version": "0.1.0",
+ "version": "0.1.1",
"manifest_version": 1,
// Recommended
"description": "Links items from the tf2 spreadsheet with online sites",
@@ -13,7 +13,7 @@
"content_scripts": [
{
"matches": ["http://tf2tp.com/*"],
- "js": ["jquery.js", "jquery.qtip-1.0.0-rc3.min.js", "tf2tp_script.js"]
+ "js": ["jquery.js", "jquery.qtip-1.0.0-rc3.min.js", "base_contentscript.js", "tf2tp_script.js"]
},
{
"matches": ["http://tf2spreadsheet.blogspot.com/*", "http://tf2spreadsheet.blogspot.co.nz/*"],
View
82 tf2tp_script.js
@@ -1,24 +1,17 @@
/**
- *
* Injected on any page on tf2tp.com
- *
*/
-
-
setup();
-
-
//the item id attribute on the div elements
var ITEM_ID_ATTR = "data-tf2itemid";
//item name
var ITEM_NAME_ATTR = "data-name";
//new line var
var _NL = "<br />";
-
/**
* inits all scripts and makes sure items are loaded
*/
@@ -28,77 +21,12 @@ function setup()
$(function() {
//find all elements with the attribute that links to an item id
$("div[" + ITEM_ID_ATTR + "]").each(function(index, element) {
-
- //$(element).click(function() {
- //send a message to background to get item details
- getItemDetails($(element).attr(ITEM_NAME_ATTR), function(response) {
-
- var itemDetails = formatItemDetails(element, response);
+ //send a message to background to get item details
+ getItemDetails($(element).attr(ITEM_NAME_ATTR), function(response) {
- //add a qtip popup
- $(element).qtip({
- content: itemDetails,
- style: {
- name: 'dark',
- width: {
- min: 10,
- max: 600
- }
- },
- position: {
- corner: {
- target: 'bottomRight',
- tooltip: 'bottomLeft'
- }
- },
- show: { event: 'mouseover' },
- hide: 'mouseout'
- }).qtip("updateWidth");
-
- $(element).qtip("updateWidth");
- $(element).qtip("api").updateContent(itemDetails, true);
- });
- //});
+ var itemDetails = formatItemDetails(element, response);
+ hoverDetails(element, itemDetails);
+ });
});
});
}
-
-
-
-//formats item detail description
-function formatItemDetails(element, response)
-{
- var itemDetails = "";
- if(response.items.length == 0) {
- itemDetails += "ERROR: Cannot find item";
- }
- else {
- for(var i=0; i<response.items.length; i++)
- {
- var item = response.items[i];
- itemDetails += "(" + item.quality + ") " + item.name + " (Est: " + item.est_price + ")" + _NL;
- }
- }
-
- return itemDetails;
-}
-
-
-//ensures the data is valid before adding it to the string
-function validateDetails(name, object)
-{
- if(object && object != "-1")
- {
- return "<p>" + name + ": " + object + "</p>";
- }
- else return "";
-}
-
-
-
-function getItemDetails(name, callback)
-{
- chrome.extension.sendMessage({type: "item_details", itemName: name}, function(response) {
- callback(response);
- });
-}

0 comments on commit 58215dd

Please sign in to comment.