]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/UserContent.pm
b34ebf91b0caa9649bdf071180bd69fea5049126
[public-inbox.git] / lib / PublicInbox / UserContent.pm
1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # Self-updating module containing a sample CSS for client-side
5 # customization by users of public-inbox.  Used by Makefile.PL
6 package PublicInbox::UserContent;
7 use strict;
8 use warnings;
9
10 # this sub is updated automatically:
11 sub CSS () {
12         <<'_'
13         /*
14          * Dark color scheme using 216 web-safe colors, inspired
15          * somewhat by the default color scheme in mutt.
16          * It reduces eyestrain for me, and energy usage for all:
17          * https://en.wikipedia.org/wiki/Light-on-dark_color_scheme
18          */
19         * { background:#000; color:#ccc }
20
21         /*
22          * Underlined links add visual noise which make them hard-to-read.
23          * Use colors to make them stand out, instead.
24          */
25         a { color:#69f; text-decoration:none }
26         a:visited { color:#96f }
27
28         /* quoted text gets a different color */
29         *.q { color:#09f }
30
31         /*
32          * these may be used with cgit, too
33          * (cgit uses <div>, public-inbox uses <span>)
34          */
35         *.add { color:#0ff }
36         *.del { color:#f0f }
37         *.head { color:#fff }
38         *.hunk { color:#c93 }
39 _
40 }
41 # end of auto-updated sub
42
43 # return a sample CSS
44 sub sample ($$) {
45         my ($ibx, $env) = @_;
46         my $url_prefix = $ibx->base_url($env);
47         my $preamble = <<"";
48 /*
49  * Firefox users: this goes in \$PROFILE_FOLDER/chrome/userContent.css
50  * where \$PROFILE_FOLDER is platform-specific
51  *
52  * cf. http://kb.mozillazine.org/UserContent.css
53  *     http://kb.mozillazine.org/Profile_folder_-_Firefox
54  *
55  * Users of dillo can remove the entire lines with "moz-only"
56  * in them and place the resulting file in ~/.dillo/style.css
57  */
58 \@-moz-document url-prefix($url_prefix) { /* moz-only */
59
60         $preamble . CSS() . "\n} /* moz-only */\n";
61 }
62
63 # Auto-update this file based on the contents of a CSS file:
64 # usage: perl -I lib __FILE__ contrib/css/216dark.css
65 # (See Makefile.PL)
66 if (scalar(@ARGV) == 1 && -r __FILE__) {
67         use autodie;
68         open my $ro, '<', $ARGV[0];
69         my $css = do { local $/; <$ro> };
70         $css =~ s/^([ \t]*\S)/\t$1/smg;
71         open my $rw, '+<', __FILE__;
72         my $out = do { local $/; <$rw> };
73         $out =~ s/^sub CSS.*^_\n\}/sub CSS () {\n\t<<'_'\n${css}_\n}/sm;
74         seek $rw, 0, 0;
75         print $rw $out;
76 }
77
78 1;