Last active
November 19, 2019 07:41
-
-
Save thevladeffect/f6b60d20428c00d1a9dfdbada91aa478 to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name Board Games Hub | |
// @namespace https://github.com/thevladeffect | |
// @version 0.2 | |
// @description Add Board Games Hub link to game page | |
// @author Vlad | |
// @match boardgamegeek.com/boardgame* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function getElementByXpath(path) { | |
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
} | |
const title = getElementByXpath("(//a[@ui-sref='geekitem.overview'])[2]").text.trim(); | |
const url = `http://www.boardgameshub.ro/stock/${encodeURI(title)}`; | |
const link = document.createElement('a'); | |
link.className = 'btn-group-sm'; | |
link.href = url; | |
link.target = '_blank'; | |
const button = document.createElement('button'); | |
button.className = 'btn btn-subtle'; | |
button.textContent = 'Board Games Hub'; | |
link.append(button); | |
const actions = document.getElementsByClassName('toolbar-actions')[0]; | |
actions.appendChild(link); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment