summaryrefslogtreecommitdiffstats
path: root/assets/js/themes.js
blob: 90a05c36ed41ce6e44d350ada7771883a8c1652f (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var toggle_theme = document.getElementById('toggle_theme');
toggle_theme.href = 'javascript:void(0);';

toggle_theme.addEventListener('click', function () {
    var dark_mode = document.getElementById('dark_theme').media === 'none';

    var url = '/toggle_theme?redirect=false';
    var xhr = new XMLHttpRequest();
    xhr.responseType = 'json';
    xhr.timeout = 10000;
    xhr.open('GET', url, true);

    set_mode(dark_mode);
    window.localStorage.setItem('dark_mode', dark_mode ? 'dark' : 'light');

    xhr.send();
});

window.addEventListener('storage', function (e) {
    if (e.key === 'dark_mode') {
        update_mode(e.newValue);
    }
});

window.addEventListener('load', function () {
    window.localStorage.setItem('dark_mode', document.getElementById('dark_mode_pref').textContent);
    // Update localStorage if dark mode preference changed on preferences page
    update_mode(window.localStorage.dark_mode);
});

function set_mode (bool) {
    document.getElementById('dark_theme').media = !bool ? 'none' : '';
    document.getElementById('light_theme').media = bool ? 'none' : '';

    if (bool) {
        toggle_theme.children[0].setAttribute('class', 'icon ion-ios-sunny');
    } else {
        toggle_theme.children[0].setAttribute('class', 'icon ion-ios-moon');
    }
}

function update_mode (mode) {
    if (mode === 'true' /* for backwards compatibility */ || mode === 'dark') {
        // If preference for dark mode indicated
        set_mode(true);
    }
	else if (mode === 'false' /* for backwards compaibility */ || mode === 'light') {
		// If preference for light mode indicated
		set_mode(false);
	}
    else if (document.getElementById('dark_mode_pref').textContent === '' && window.matchMedia('(prefers-color-scheme: dark)').matches) {
        // If no preference indicated here and no preference indicated on the preferences page (backend), but the browser tells us that the operating system has a dark theme
        set_mode(true);
    }
    // else do nothing, falling back to the mode defined by the `dark_mode` preference on the preferences page (backend)
}


td>alefvanoon 2021-04-10add insta.trom.tfalefvanoon 2021-04-10add search.trom.tfalefvanoon 2021-04-09add searx.silkky.cloudalefvanoon 2021-04-09add libreddit.silkky.cloudalefvanoon 2021-04-09add some invidious insalefvanoon 2021-04-09add some invidious insalefvanoon 2021-04-09refactor: drop teddit image redirect supportJason Kim No longer redirect image links for teddit instances. Add a comment detailing the two issues I found. Now, the feature should be stable. 2021-04-09fix: don't redirect for rest of instancesJason Kim Unbreak old.reddit.com and i.reddit.com by ignoring image redirects for them. 2021-04-08fix: redirect teddit differentlyJason Kim Teddit image urls are different from libreddit. Handle each separately. Test manually: - libredd.it: pass - libreddit.spike.codes: pass - libreddit.kavin.rocks: pass - libreddit.insanity.wtf: fail (site doesn't work in general) - libreddit.dothq.co: pass - teddit.net: mostly fail - teddit.ggc-project.de: mostly fail - teddit.kavin.rocks: mostly fail - old.reddit.com: fail - i.reddit.com: fail - snew.notabug.io: fail (site doesn't work in general) Teddit image urls have two issues. First, the links almost never work (404) if the image url is visited directly before visiting the main page. Once the main page is visited, however, the image url starts working. I'm guessing this is an issue with teddit instances not fetching images unless the main page is accessed. Second, some image links are different/incompatible for some reason. For example, <https://i.redd.it/htg3owj12ok21.png> turns into <https://teddit.net/pics/w:null_TpEyuHnjif6578pV0lBuM-kNW1bXqxbvqbOHjhRZVr0.png>. Libreddit seems to not have this issue. 2021-04-08feat: add img prefix for i.redd.itJason Kim "i.redd.it/<imgfile>" redirects "libredd.it/<imgfile>". Make it redirect to "libredd.it/img/<imgfile>". Tested only for "libredd.it". 2021-04-08feat: add i.redd.it to reddit targetsJason Kim Add "i.redd.it" to list of urls to redirect for Reddit. Although the redirect works, the link should be invalid because it still needs an "img" path prefix. 2021-04-07Update Bibliogram instances listCadence Ember Set it to match the list of actually working instances. https://git.sr.ht/~cadence/bibliogram-docs/tree/master/docs/Instances.md 2021-04-05Update manifest.jsonHarsh Barsaiyan 2021-03-30Add ViewTubeHarsh Barsaiyan 2021-03-20Add Ecosia search engineCamille019 2021-03-11Add Whoogle SearchHarsh Barsaiyan 2021-03-02Disable SimplyTranslate redirects by defaultfattalion 2021-02-25Add SimplyTranslate supportfattalion 2021-02-24add invidious instanceAndrew Zhao