Add Newest Tab and NSFW filter back to Gumroad

Adds the "Newest" tab, and the NSFW filter option back to Gumroad

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Add Newest Tab and NSFW filter back to Gumroad
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds the "Newest" tab, and the NSFW filter option back to Gumroad
// @author       TohruTheDragon
// @match        https://gumroad.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function addNewestTab() {
        var tabList = document.querySelector('.tab-pills[role="tablist"]');
        if (tabList) {
            var newestTab = document.createElement('div');
            newestTab.setAttribute('role', 'tab');
            newestTab.setAttribute('aria-selected', 'false');
            newestTab.textContent = 'Newest';
            newestTab.style.cursor = 'pointer';

            newestTab.addEventListener('click', function () {
                window.location.href = '?sort=newest';
            });

            tabList.appendChild(newestTab);
        }
    }

    function addNSFWSwitch() {
        var detailsElements = document.querySelectorAll('.stack details');
        var lastDetails = detailsElements[detailsElements.length - 1];

        if (lastDetails) {
            var toggleContainer = document.createElement('div');
            toggleContainer.style.display = 'flex';
            toggleContainer.style.alignItems = 'center';
            toggleContainer.style.marginTop = '10px';

            var label = document.createElement('label');
            label.textContent = 'NSFW Content';
            toggleContainer.appendChild(label);

            var toggleSwitch = document.createElement('input');
            toggleSwitch.type = 'checkbox';
            toggleSwitch.style.marginLeft = '10px';
            toggleSwitch.style.border = '1px solid white';
            toggleContainer.appendChild(toggleSwitch);

            lastDetails.appendChild(toggleContainer);

            function updateAndRedirect() {
                var currentURL = new URL(window.location.href);
                currentURL.searchParams.set('show_nsfw', toggleSwitch.checked ? 'yes' : 'no');
                window.location.href = currentURL.toString();
            }

            toggleSwitch.addEventListener('change', updateAndRedirect);

            var currentURLParams = new URLSearchParams(window.location.search);
            if (currentURLParams.get('show_nsfw') === 'yes') {
                toggleSwitch.checked = true;
            } else {
                toggleSwitch.checked = false;
            }
        }
    }

    window.addEventListener('DOMContentLoaded', function () {
        setTimeout(function() {
            addNewestTab();
            addNSFWSwitch();
        }, 500);
    });
})();