Skip to content

Commit

Permalink
quickly search boardgamegeek from amazon, coolstuffinc, miniaturemark…
Browse files Browse the repository at this point in the history
…et, and gamesurpus
  • Loading branch information
Matthew Cross committed Feb 11, 2017
1 parent 7273975 commit af1e8ba
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 0 deletions.
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions jquery-3.1.1.min.js

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions manifest.json
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/"
]
}
35 changes: 35 additions & 0 deletions popup.html
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>
28 changes: 28 additions & 0 deletions popup.js
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" });
});
});
3 changes: 3 additions & 0 deletions scripts/content_scripts/amazon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function locateGameNameElement() {
return extractFirstMatchingElement(document.querySelectorAll('#productTitle'));
}
26 changes: 26 additions & 0 deletions scripts/content_scripts/content_script.js
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();
});
3 changes: 3 additions & 0 deletions scripts/content_scripts/coolstuffinc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function locateGameNameElement() {
return extractFirstMatchingElement(document.querySelectorAll('h1[itemprop="name"]'));
}
3 changes: 3 additions & 0 deletions scripts/content_scripts/game_surplus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function locateGameNameElement() {
return extractFirstMatchingElement(document.querySelectorAll('#prod_info_head'));
}
3 changes: 3 additions & 0 deletions scripts/content_scripts/miniature_market.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function locateGameNameElement() {
return extractFirstMatchingElement(document.querySelectorAll('h1.product-name'));
}

0 comments on commit af1e8ba

Please sign in to comment.