Add Newest Tab and NSFW filter back to Gumroad

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

  1. // ==UserScript==
  2. // @name Add Newest Tab and NSFW filter back to Gumroad
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Adds the "Newest" tab, and the NSFW filter option back to Gumroad
  6. // @author TohruTheDragon
  7. // @match https://gumroad.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function addNewestTab() {
  16. var tabList = document.querySelector('.tab-pills[role="tablist"]');
  17. if (tabList) {
  18. var newestTab = document.createElement('div');
  19. newestTab.setAttribute('role', 'tab');
  20. newestTab.setAttribute('aria-selected', 'false');
  21. newestTab.textContent = 'Newest';
  22. newestTab.style.cursor = 'pointer';
  23.  
  24. newestTab.addEventListener('click', function () {
  25. window.location.href = '?sort=newest';
  26. });
  27.  
  28. tabList.appendChild(newestTab);
  29. }
  30. }
  31.  
  32. function addNSFWSwitch() {
  33. var detailsElements = document.querySelectorAll('.stack details');
  34. var lastDetails = detailsElements[detailsElements.length - 1];
  35.  
  36. if (lastDetails) {
  37. var toggleContainer = document.createElement('div');
  38. toggleContainer.style.display = 'flex';
  39. toggleContainer.style.alignItems = 'center';
  40. toggleContainer.style.marginTop = '10px';
  41.  
  42. var label = document.createElement('label');
  43. label.textContent = 'NSFW Content';
  44. toggleContainer.appendChild(label);
  45.  
  46. var toggleSwitch = document.createElement('input');
  47. toggleSwitch.type = 'checkbox';
  48. toggleSwitch.style.marginLeft = '10px';
  49. toggleSwitch.style.border = '1px solid white';
  50. toggleContainer.appendChild(toggleSwitch);
  51.  
  52. lastDetails.appendChild(toggleContainer);
  53.  
  54. function updateAndRedirect() {
  55. var currentURL = new URL(window.location.href);
  56. currentURL.searchParams.set('show_nsfw', toggleSwitch.checked ? 'yes' : 'no');
  57. window.location.href = currentURL.toString();
  58. }
  59.  
  60. toggleSwitch.addEventListener('change', updateAndRedirect);
  61.  
  62. var currentURLParams = new URLSearchParams(window.location.search);
  63. if (currentURLParams.get('show_nsfw') === 'yes') {
  64. toggleSwitch.checked = true;
  65. } else {
  66. toggleSwitch.checked = false;
  67. }
  68. }
  69. }
  70.  
  71. window.addEventListener('DOMContentLoaded', function () {
  72. setTimeout(function() {
  73. addNewestTab();
  74. addNSFWSwitch();
  75. }, 500);
  76. });
  77. })();