-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
quickly search boardgamegeek from amazon, coolstuffinc, miniaturemark…
…et, and gamesurpus
- Loading branch information
Matthew Cross
committed
Feb 11, 2017
1 parent
7273975
commit af1e8ba
Showing
10 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"manifest_version": 2, | ||
|
||
"name": "Find on Boardgamegeek", | ||
"description": "Find a game on Boardgamegeek", | ||
"version": "1.0", | ||
|
||
"browser_action": { | ||
"default_icon": "icon.png", | ||
"default_popup": "popup.html" | ||
}, | ||
|
||
"content_scripts": [ | ||
{ | ||
"matches": ["https://www.amazon.com/*"], | ||
"js": [ | ||
"scripts/content_scripts/content_script.js", | ||
"scripts/content_scripts/amazon.js" | ||
] | ||
}, | ||
{ | ||
"matches": ["http://www.coolstuffinc.com/*"], | ||
"js": [ | ||
"scripts/content_scripts/content_script.js", | ||
"scripts/content_scripts/coolstuffinc.js" | ||
] | ||
}, | ||
{ | ||
"matches": ["http://www.miniaturemarket.com/*"], | ||
"js": [ | ||
"scripts/content_scripts/content_script.js", | ||
"scripts/content_scripts/miniature_market.js" | ||
] | ||
}, | ||
{ | ||
"matches": ["http://www.gamesurplus.com/*"], | ||
"js": [ | ||
"scripts/content_scripts/content_script.js", | ||
"scripts/content_scripts/game_surplus.js" | ||
] | ||
} | ||
], | ||
|
||
"permissions": [ | ||
"activeTab", | ||
"https://www.boardgamegeek.com/" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!doctype html> | ||
<!-- | ||
This page is shown when the extension button is clicked, because the | ||
"browser_action" field in manifest.json contains the "default_popup" key with | ||
value "popup.html". | ||
--> | ||
<html> | ||
<head> | ||
<title>Boardgamegeek Search</title> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
<!-- Latest compiled and minified CSS --> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | ||
|
||
<!-- Optional theme --> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> | ||
|
||
<!-- Latest compiled and minified JavaScript --> | ||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> | ||
|
||
<!-- | ||
- JavaScript and HTML must be in separate files: see our Content Security | ||
- Policy documentation[1] for details and explanation. | ||
- | ||
- [1]: https://developer.chrome.com/extensions/contentSecurityPolicy | ||
--> | ||
<script src="jquery-3.1.1.min.js"></script> | ||
<script src="popup.js"></script> | ||
</head> | ||
<body> | ||
<div class="container" style="width:200px"/> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
chrome.runtime.onMessage.addListener(function(message) { | ||
bggApiSearch(message.gameName); | ||
}); | ||
|
||
function bggSearch(gameName) { | ||
window.open("https://boardgamegeek.com/geeksearch.php?action=search&objecttype=boardgame&q="+ encodeURI(gameName)+"&B1=Go"); | ||
} | ||
|
||
function bggApiSearch(gameName) { | ||
$.get( "https://www.boardgamegeek.com/xmlapi2/search?query=" + gameName + "&type=boardgame,boardgamexpansion", function(data) { | ||
var items = $(data).find("item"); | ||
items.each(function(index, item) { | ||
var id = $(item).attr("id"); | ||
var name = $(item).find("name").attr("value"); | ||
var year = $(item).find("yearpublished").attr("value"); | ||
|
||
$(".container").append("<div><a target='_blank' href='https://boardgamegeek.com/boardgame/"+ id +"'>" + name + " - (" + year + ")" + "</a></div>"); | ||
}); | ||
|
||
console.log(data); | ||
}); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function () { | ||
chrome.tabs.query({ active: true }, function(tabs) { | ||
chrome.tabs.sendMessage(tabs[0].id, { action: "send_game_name" }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function locateGameNameElement() { | ||
return extractFirstMatchingElement(document.querySelectorAll('#productTitle')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function sanitizeGameName(gameName) { | ||
var replacementTerms = ["(New Arrival)", "Expansion", "Board Game"]; | ||
|
||
replacementTerms.forEach(function(replacementTerm) { | ||
gameName = gameName.replace(replacementTerm, ""); | ||
}); | ||
|
||
return gameName; | ||
} | ||
|
||
function extractFirstMatchingElement(elements) { | ||
if(elements != null && elements[0] != null) { | ||
return elements[0].innerText; | ||
} | ||
} | ||
|
||
function sendGameName() { | ||
var gameNameElement = locateGameNameElement(); | ||
var gameName = sanitizeGameName(gameNameElement); | ||
|
||
chrome.runtime.sendMessage({ gameName: gameName }); | ||
} | ||
|
||
chrome.runtime.onMessage.addListener(function(message) { | ||
sendGameName(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function locateGameNameElement() { | ||
return extractFirstMatchingElement(document.querySelectorAll('h1[itemprop="name"]')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function locateGameNameElement() { | ||
return extractFirstMatchingElement(document.querySelectorAll('#prod_info_head')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function locateGameNameElement() { | ||
return extractFirstMatchingElement(document.querySelectorAll('h1.product-name')); | ||
} |