Last active
December 28, 2020 20:07
-
-
Save barthenry/6afb5656dcda49c870a4c525c1217dc2 to your computer and use it in GitHub Desktop.
Adds shortcut button on BGG board game page for quick redirection to sleeves geeklist
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 BGG sleeves button | |
// @namespace https://gist.github.com/barthenry | |
// @version 1.0.1 | |
// @description Adds shortcut button on BGG board game page for quick redirection to sleeves geeklist | |
// @author Bart Henry | |
// @match https://boardgamegeek.com/boardgame/* | |
// @match https://bgg.cc/boardgame/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let actionBar = document.querySelector('.toolbar-actions'); | |
let newActionButton = document.createElement('div'); | |
newActionButton.className = 'toolbar-action'; | |
newActionButton.innerHTML =`<span class="btn-group"> | |
<button class="btn btn-sm btn-subtle ng-isolate-scope"> | |
<i class="fi-clipboard-pencil toolbar-action-icon visible-xs"></i> | |
Sleeves | |
</button>`; | |
actionBar.append(newActionButton); | |
let url = window.location.href; | |
let redirectUrl = url.match(window.location.origin + '/boardgame/[0-9]+/[-A-Za-z]+')[0] + '/geeklists?pageid=1&sort=hot&geeklist=sleeves'; | |
newActionButton.addEventListener('click', function(){ | |
window.location = redirectUrl; | |
}); | |
window.addEventListener('load', function() { | |
if (location.search.includes('geeklist=sleeves')){ | |
let allGeekLists = document.querySelectorAll('.summary-item-title > a'); | |
if (allGeekLists.length > 0){ | |
history.pushState({}, document.title, url); | |
} | |
for (let i = 0; i < allGeekLists.length; ++i) { | |
let geekListUrl = allGeekLists[i].href; | |
if (geekListUrl.includes('geeklist/164572')) { | |
window.location = geekListUrl; | |
} | |
} | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment