aboutsummaryrefslogtreecommitdiffstats
path: root/scripts-greasemonkey/duckduckgo_dark_theme.user.js
blob: ba88a16862f986791c6da9cedd96f3f1ac15150d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// ==UserScript==
// @name          DuckDuckGo Always Terminal Theme
// @namespace     DuckDuckGoDarkTheme
// @description   Enables Therminal Theme Forever.
// @author        Jesús E.
// @version       0.1.1
// @grant         none
// @include       /^http(s|)://(www[.]|)duckduckgo[.]com/.*$/
// @include       /^http(s|)://3g2upl4pq6kufc4m[.]onion/.*$/
// @run-at        document-start
// @icon          https://duckduckgo.com/favicon.ico
// ==/UserScript==

(function main() {
  'use strict';

  const consoleCSS = 'background: #000; color: #00FF00; padding: 0px 7px; border: 1px solid #00FF00; line-height: 16px;';
  const name = GM_info.script.name;
  const log = (...args) => console.log('%cUSERSCRIPT | %s: %s', consoleCSS, name, ...args);

  log('start');

  // set darkmode cookie before page loaded
  const cookiePref = document.cookie.replace(/(?:(?:^|.*;\s*)ae\s*=\s*([^;]*).*$)|^.*$/, '$1');
  const cookiePrefDark = 't';
  const expires = 'max-age=315360000';
  if (!cookiePref.includes(cookiePrefDark)) {
    document.cookie = `ae=${cookiePrefDark}${cookiePref ? `&${cookiePref}` : ''};path=/;${expires}`;
    log('cookie injected');
  }

}());