Bandcamp Collapsable Shop

Bundles up all bandcamp purchase options under one collapsable

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Bandcamp Collapsable Shop
// @namespace    https://github.com/lukalovre/BandcampCollapsableShop
// @version      1.0
// @description  Bundles up all bandcamp purchase options under one collapsable
// @author       Luka Lovre
// @match        https://*.bandcamp.com/*
// @grant       none
// @license MIT
// ==/UserScript==

window.self === window.top && window.siteroot && "https://bandcamp.com" == window.siteroot && (function() {

    let shopButton = document.createElement("button");
    shopButton.textContent = "Shop";
    shopButton.style.width = '50px';
    shopButton.style.height = '20px';
    shopButton.style.fontSize = '12px';
    shopButton.style.float = "right";

    // Default Bandcamp following button colors
    shopButton.style.background = '#619aa9';
    shopButton.style.color = '#fff';

    const hide = element => {
        element.style.display = 'none'
    }

    const show = element => {
        element.style.display = 'block'
    }

    const toggle = element => {
        // if the element is visible, hide it
        if (window.getComputedStyle(element).display !== 'none') {
            hide(element)
            return
        }

        show(element)
    }

    let shopSection = '.tralbumCommands';
    let shopButtonLocationParent = '#name-section h3';
    let shopButtonLocation = '#name-section h3 [itemprop="byArtist"]';

    shopButton.addEventListener("click", function() {
        let element = document.querySelector(shopSection);
        toggle(element);
    });

    document.querySelector(shopSection).style.display = "none";
    document.querySelector(shopButtonLocationParent).insertBefore(shopButton, document.querySelector(shopButtonLocation));
}());