Auto-apply reddit Preferences

Automatically POSTs preferred settings and reloads the page to apply them

// ==UserScript==
// @name         Auto-apply reddit Preferences
// @description  Automatically POSTs preferred settings and reloads the page to apply them
// @match        https://safereddit.com/*
// @match https://redlib.catsarch.com/*
// @version 0.0.1.20250628081622
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==

(function () {
  'use strict';

  // Avoid repeated POSTs by setting a flag in-memory for the session
  if (sessionStorage.getItem('saferedditSettingsApplied') === 'true') return;

  // Define your preferences
  const prefs = new URLSearchParams({
    theme: 'dark',
    remove_default_feeds: 'off',
    front_page: 'all',
    layout: 'card',
    wide: 'off',
    video_quality: 'best',
    post_sort: 'new',
    comment_sort: 'new',
    blur_spoiler: 'on',
    autoplay_videos: 'off',
    fixed_navbar: 'on',
    hide_sidebar_and_summary: 'off',
    use_hls: 'on',
    hide_hls_notification: 'on',
    hide_awards: 'off',
    hide_score: 'off',
    disable_visit_reddit_confirmation: 'off'
  });

  fetch('/settings', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    body: prefs.toString()
  }).then(() => {
    sessionStorage.setItem('saferedditSettingsApplied', 'true');
    window.location.reload();
  });
})();