Reddit bug workaround to allow posting on the r/userscript subreddit.

Redirects Reddit's submit page for r/userscripts to the old Reddit interface to fix the bug accessing the new interfaces's submit page for the subreddit.

目前为 2025-01-04 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Reddit bug workaround to allow posting on the r/userscript subreddit.
  3. // @namespace https://gist.github.com/f-steff
  4. // @version 1.1
  5. // @description Redirects Reddit's submit page for r/userscripts to the old Reddit interface to fix the bug accessing the new interfaces's submit page for the subreddit.
  6. // @author Flemming Steffensen
  7. // @license MIT
  8. // @match https://www.reddit.com/r/userscripts/*
  9. // @grant none
  10. // @homepageURL https://gist.github.com/f-steff/cd4c5fafc574e5595fc7a153516792ab
  11. // @run-at document-idle
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Function to modify the "Create Post" button
  18. function modifyCreatePostButton() {
  19. const createPostButton = document.querySelector('a[data-testid="create-post"]');
  20. if (createPostButton && createPostButton.href.includes('www.reddit.com')) {
  21. createPostButton.href = createPostButton.href.replace('www.reddit.com', 'old.reddit.com');
  22. }
  23. }
  24.  
  25. // Ensure the DOM is fully loaded before running
  26. function init() {
  27. modifyCreatePostButton();
  28.  
  29. // Observe for dynamic changes to the page and reapply the modification if needed
  30. const observer = new MutationObserver(() => {
  31. modifyCreatePostButton();
  32. });
  33.  
  34. observer.observe(document.body, { childList: true, subtree: true });
  35. }
  36.  
  37. if (document.readyState === 'loading') {
  38. document.addEventListener('DOMContentLoaded', init);
  39. } else {
  40. init();
  41. }
  42. })();