A place to cache linked articles (think custom and personal wayback machine)
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

3 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <!doctype html><!-- This is a valid HTML5 document. -->
  2. <!-- Screen readers, SEO, extensions and so on. -->
  3. <html lang="fr">
  4. <!-- Has to be within the first 1024 bytes, hence before the <title>
  5. See: https://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#charset -->
  6. <meta charset="utf-8">
  7. <!-- Why no `X-UA-Compatible` meta: https://stackoverflow.com/a/6771584 -->
  8. <!-- The viewport meta is quite crowded and we are responsible for that.
  9. See: https://codepen.io/tigt/post/meta-viewport-for-2015 -->
  10. <meta name="viewport" content="width=device-width,initial-scale=1">
  11. <!-- Required to make a valid HTML5 document. -->
  12. <title>Against alcohol (archive) — David Larlet</title>
  13. <meta name="description" content="Publication mise en cache pour en conserver une trace.">
  14. <!-- That good ol' feed, subscribe :). -->
  15. <link rel="alternate" type="application/atom+xml" title="Feed" href="/david/log/">
  16. <!-- Generated from https://realfavicongenerator.net/ such a mess. -->
  17. <link rel="apple-touch-icon" sizes="180x180" href="/static/david/icons2/apple-touch-icon.png">
  18. <link rel="icon" type="image/png" sizes="32x32" href="/static/david/icons2/favicon-32x32.png">
  19. <link rel="icon" type="image/png" sizes="16x16" href="/static/david/icons2/favicon-16x16.png">
  20. <link rel="manifest" href="/static/david/icons2/site.webmanifest">
  21. <link rel="mask-icon" href="/static/david/icons2/safari-pinned-tab.svg" color="#07486c">
  22. <link rel="shortcut icon" href="/static/david/icons2/favicon.ico">
  23. <meta name="msapplication-TileColor" content="#f0f0ea">
  24. <meta name="msapplication-config" content="/static/david/icons2/browserconfig.xml">
  25. <meta name="theme-color" content="#f0f0ea">
  26. <!-- Documented, feel free to shoot an email. -->
  27. <link rel="stylesheet" href="/static/david/css/style_2021-01-20.css">
  28. <!-- See https://www.zachleat.com/web/comprehensive-webfonts/ for the trade-off. -->
  29. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  30. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  31. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  32. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  33. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  34. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  35. <script>
  36. function toggleTheme(themeName) {
  37. document.documentElement.classList.toggle(
  38. 'forced-dark',
  39. themeName === 'dark'
  40. )
  41. document.documentElement.classList.toggle(
  42. 'forced-light',
  43. themeName === 'light'
  44. )
  45. }
  46. const selectedTheme = localStorage.getItem('theme')
  47. if (selectedTheme !== 'undefined') {
  48. toggleTheme(selectedTheme)
  49. }
  50. </script>
  51. <meta name="robots" content="noindex, nofollow">
  52. <meta content="origin-when-cross-origin" name="referrer">
  53. <!-- Canonical URL for SEO purposes -->
  54. <link rel="canonical" href="https://fergus-mccullough.com/index.php/2021/04/09/against-alcohol/">
  55. <body class="remarkdown h1-underline h2-underline h3-underline em-underscore hr-center ul-star pre-tick">
  56. <article>
  57. <header>
  58. <h1>Against alcohol</h1>
  59. </header>
  60. <nav>
  61. <p class="center">
  62. <a href="/david/" title="Aller à l’accueil"><svg class="icon icon-home">
  63. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-home"></use>
  64. </svg> Accueil</a> •
  65. <a href="https://fergus-mccullough.com/index.php/2021/04/09/against-alcohol/" title="Lien vers le contenu original">Source originale</a>
  66. </p>
  67. </nav>
  68. <hr>
  69. <p><em>A review of <a href="https://www.amazon.co.uk/Drink-Science-Alcohol-Your-Health-ebook/dp/B07SZLPS5B/">Drink?: The New Science of Alcohol and Your Health</a> by Professor David Nutt, with comments</em>.</p>
  70. <p><em>N.B. all statistics are from the book unless otherwise indicated. The book mainly concerned itself with the United Kingdom, but I think the lessons are broadly applicable to other Western countries too.</em></p>
  71. <p>This useful little book provides a summary of the latest science on the impact of alcohol, which I’ll briefly outline, and goes on to suggest some actions in light of that knowledge.</p>
  72. <p>The overriding impression I got during the book was that alcohol is Really Bad for your health:</p>
  73. <blockquote class="wp-block-quote"><p>Alcohol use is one of the top five causes of disease and disability in almost all countries in Europe. In the UK, alcohol is now the leading cause of death in men between the ages of 16 and 54 years, accounting for over 20 per cent of the total. More than three- quarters of liver cirrhosis deaths, 7 per cent of cancer deaths and 25 per cent of injury deaths in adults under 65 years of age in Europe in 2004 were estimated to be due to alcohol.1 According to the government, alcohol is the third leading risk factor for death and disability after smoking and obesity. That’s a pretty scary list, right?”</p></blockquote>
  74. <p>At least one in five cases of dementia is caused by alcohol (although there is a study that contradicts this). It can also exacerbate mental health problems, especially anxiety and depression. One major American study suggested that up to a quarter of young alcoholics have social anxiety disorder.</p>
  75. <p>This isn’t a big surprise, of course. What I didn’t realise before, though, is how poorly evidenced the beneficial effects of alcohol are. Looking at the available studies, Nutt writes that the positive effect on cardiovascular health has never been definitely proven (i.e. beyond mere association), and even if there is a partial effect, the optimal level of consumption would be around one unit a day. And the benefits don’t outweigh all the other risks, which include cancer.</p>
  76. <p>The impact of alcohol on my country, the UK, is pretty significant. 10.8m Brits drink at levels posing some risk to their health, and 1.6m ‘may have some level of alcohol dependence’. Different figures, from the NHS, suggest around 9% of men and 3% of women show such signs (which my back of the envelope calculations suggest would be something like 3.3m people in total). <em>[Edit: I amended this paragraph to show these are two different surveys that don’t agree with each other. Sorry for originally implying they were the same survey.]</em></p>
  77. <p>It’s estimated that alcohol contributes to 30,000 deaths a year in England, Scotland and Wales. And it’s thought to cause 5% of the global disease burden.</p>
  78. <p>There is enough evidence here to make a strong case against alcohol on a number of grounds (which Nutt himself does not quite do).</p>
  79. <p>Alcohol is a drain on economic growth, damaging our productivity and forcing us to spend money on healthcare that could be used elsewhere. The CDC estimated the cost of hangovers to the American economy as $249bn in 2010. The Institute of Alcohol Studies estimates a cost of £1.4bn a year for British productivity. (The charity Alcohol Change UK puts the productivity damage at <a href="https://alcoholchange.org.uk/alcohol-facts/fact-sheets/alcohol-in-the-workplace">£7bn a year</a> instead. I haven’t tried to understand why those figures are so different.)  If you think economic growth is <a href="https://www.amazon.co.uk/Stubborn-Attachments-Prosperous-Responsible-Individuals/dp/1732265135/">important</a>, then alcohol is not worth the hassle.</p>
  80. <p>Treating the results of excess alcohol consumption is a huge burden for the NHS, which is under increasing strain as the population ages. In 2017/18, 338,000 hospital admissions were mainly attributable to alcohol, and 23% of those were due to accidents.</p>
  81. <p>It’s a little strange that this isn’t talked about more. Over the past twelve months we’ve seen an outpouring of public support for the NHS, and polls suggest that it’s the one institution that almost everyone in Britain cares about. So why not ease the burden on its workers (and the public purse) by reducing our alcohol consumption?</p>
  82. <p>Alcohol fuels violence: victims thought offenders were under the influence of alcohol 40% of all violent crimes in 2016/17  — that’s half a million incidents. (It’s hard to know how accurate this figure is, but even if it was only 20% of the total, that’s a lot of crimes. And we can be pretty confident some crimes are not reported.)</p>
  83. <p>Those figures include sexual violence. Alcohol is the most common date rape drug, involved in 46% of cases studied by a London toxicology lab, while drugs only featured in 33% and sedative drugs in just 2%.</p>
  84. <blockquote class="wp-block-quote"><p>One in three women have been sexually taken advantage of while under the influence of drugs or alcohol, mostly in private homes by someone they know, according to the 2019 Global Drug Survey. Nearly 90 per cent of these cases involved alcohol.”</p></blockquote>
  85. <p>As Nutt makes clear, ‘this is not to put any blame on the women — of course these crimes should not happen.’</p>
  86. <p>This is, then, the case against alcohol — it undermines our health and our economy. It contributes to violence, including sexual violence. It’s an addictive drug that ensnares too many people in society.</p>
  87. <hr class="wp-block-separator">
  88. <p>The evidence here is so damning that I almost wonder whether Nutt is being <a href="https://www.reddit.com/r/explainlikeimfive/comments/60823b/eli5what_does_tyler_cowen_mean_when_he_says/">Straussian</a> when he suggests that we should still drink (within limits). Some of the arguments he makes in favour of alcohol are almost ridiculous:</p>
  89. <blockquote class="wp-block-quote"><p>A glass to hold gives us something to do with our hands in awkward situations, particularly now smoking has become so vilified.”</p></blockquote>
  90. <p>I’m taking him out of context, but only a bit. He adds in the next sentence that food and socialising, which regularly go hand-in-hand with alcohol, are good things. I agree. But there’s no reason that you can’t drink something non-alcoholic while you enjoy dinner and company. If you really want to hold a glass, it doesn’t have to contain a liquid that is harmful to your health and wider society.</p>
  91. <p>Alcohol is important for rituals, he points out:</p>
  92. <blockquote class="wp-block-quote"><p>Nearly all of our celebration rituals revolve around alcohol, from the cradle to the grave. We wet the baby’s head, we toast exam results and birthdays, we crack open the fizz at both wedding breakfasts and divorce parties. And we say goodbye to our loved ones with alcohol at a funeral wake (and drown our sorrows too). When you are working out how much to drink – or not drink – you may want to factor in the social benefits you get from it.”</p></blockquote>
  93. <p>Left unaddressed is why we think that alcohol is necessary to any of those (good and often great) <a href="https://www.nytimes.com/2019/04/22/opinion/rituals-meaning.html">rituals</a>. It’s not. I don’t see why you can’t get most of those social benefits anyway.</p>
  94. <p>It will be very tough to change those cultural norms, although, as Nutt notes, an increasing number of young people are eschewing alcohol altogether. This trend seems to be linked to a greater focus on health and ‘wellness’, although it may also be because people are taking other drugs instead.</p>
  95. <p>The other reason that nothing is done about alcohol is the drinks industry. In chapter 11, Nutt relates a sad tale of a cabinet office committee under Blair that proposed new policies to tackle alcohol addiction, but was scuppered by a drinks industry lobbying effort. This is not a surprise:</p>
  96. <blockquote class="wp-block-quote"><p>Despite repeating their message of ‘sensible drinking’ at every opportunity, the drinks industry wants you to keep drinking. That is its reason for existing. One estimate is that, if everyone drank within recommended limits, the industry would lose £13 billion. That’s a lot of lost profit. Its aim is often aided by the government, which wants the tax income.”</p></blockquote>
  97. <p>The government is pretty much in the pocket of this industry, with gifts to MPs in the ‘All-Party Parliamentary Beer Group’ every year and the perceived importance of the tax revenue from alcohol. There is something disgusting about MPs receiving gifts like that while alcohol causes so much harm in society. And they are being shortsighted, fiscally:</p>
  98. <blockquote class="wp-block-quote"><p>…in fact, it’s been estimated that when you add in the costs of alcohol to society, there is a net loss to the Exchequer . This is undeniably a difficult argument to disentangle economically, and a complicated sum. But the costs of alcohol to society are relatively well established. These are: £3.5bn on health, especially hospital admissions and accident and emergency attendances; £6.5bn for policing drunkenness; £20bn for lost productivity through hangovers. The total is £30 billion.”</p></blockquote>
  99. <p>Nutt has his own set of policy solutions, and I think they’d be great: taxing drinks by the amount of alcohol in them and increase that tax back to 1950s levels (i.e. triple it); stop selling strong alcohol in supermarkets; make it a law that all alcohol outlets must sell non-alcoholic drinks; install breathalysers in pubs and stop drunk people from buying more alcohol; banning all alcohol advertising; and many more.</p>
  100. <p>He focuses most on minimum unit pricing (MUP). As the government has not raised its duty on alcohol, it now costs a third of what it did in 1970 in real terms. Nutt points to evidence that consumption goes down when prices go up. The duty paid in England varies wildly by the type of drink, rather than relating to the amount of alcohol in it, so it’s possible to get a lot of alcohol for little money.</p>
  101. <p>Scotland, however, introduced MUP in 2018 — with initially positive results:</p>
  102. <blockquote class="wp-block-quote"><p>Research from Newcastle University has shown that the amount of alcohol bought in shops and supermarkets per person per week fell by 1.2 units (just over half a pint of beer or a measure of spirits) compared with what would have been drunk without MUP. In England over the same time, consumption increased.18 The biggest drop – two units a week – was in the heaviest fifth of drinkers. This shows that the policy is having the biggest impact on exactly the people it needs to. The number of units bought per person per week in Scotland is still higher than in England, at 19 units, but it did start from a much higher level. The Welsh Assembly has now passed legislation for MUP . At the same time as MUP was introduced, Scotland made two other important policy changes for alcohol. It reduced the drink-driving limit (from 80mg% to 50mg%) and banned discounted alcohol such as bulk-buys in supermarkets and two-for-one offers in bars. All the evidence suggests that, together with MUP, these should result in a real cut in harms.”</p></blockquote>
  103. <p>Targeting the heaviest drinkers is important because they are the worst-affected; they contribute the vast majority of the health costs.</p>
  104. <p>France had an extremely high rate of liver cirrhosis in the 1980s as a result of alcohol consumption. They tackled this by focusing on advertising (banning the drinks industry from it, basically); health warnings on bottles (‘alcohol abuse is dangerous for health’); price (restrictions on ‘happy hours’ and somehow they pressured the wine industry to make higher quality wine); driving (reducing the blood alcohol content limit). </p>
  105. <p>The French wine industry has turned out to be more profitable following these changes, as it makes better quality wine now. But the UK hasn’t followed suit, says Nutt:</p>
  106. <blockquote class="wp-block-quote"><p>The UK drinks industry know this data. They know that if we went down the route of raising the price of alcohol, they would be more profitable over time. In my opinion, the reason they don’t is that making money in the short term is so easy. And they think that if they make any concessions in this direction, people will begin to question all our other beliefs around alcohol and health.”</p></blockquote>
  107. <p>Is this a case of companies prioritising short term economic performance over the long run? If Nutt is right, then presumably the drinks businesses must fear the consequences of a shaking out; perhaps each is worried that they wouldn’t survive the instability. If a law change is on the cards, then one can imagine some private equity </p>
  108. <p>Nutt also favours the <a href="https://en.wikipedia.org/wiki/Alcoholic_drinks_in_Sweden#Regulation_and_taxation">Swedish model</a>, in which only government shops are allowed to sell alcohol of more than 3.5% ABV (<a href="https://en.wikipedia.org/wiki/Alcohol_by_volume">Alcohol By Volume</a>). They are only open at certain times of the day, forcing you to plan before you drink:</p>
  109. <blockquote class="wp-block-quote"><p>This system has led to the Swedes drinking roughly three-quarters of what we drink per year in the UK. And to a rate of deaths from liver cirrhosis approximately half of ours. This shows, yet again, how small changes in consumption lead to bigger health gains.”</p></blockquote>
  110. <p>Not sure he really proves that these government run shops have this effect, but still, it seems like a sound policy.</p>
  111. <p>I was also struck by this story:</p>
  112. <blockquote class="wp-block-quote"><p>Public Health England wanted to do an advertising campaign promoting (at least) two drink-free days a week.38 This is sensible, safe and appropriate advice. But PHE doesn’t have much money for public advertising so they agreed to partner with Drinkaware, a charity that’s funded by the alcohol industry. Hundreds of academics signed a petition censoring PHE. And their senior alcohol advisor Ian Gilmore resigned in protest.39 It wasn’t the content of the campaign that was contentious, it was where the money was coming from. As a pragmatist, I don’t have a problem with industry funding independent research and education, providing they don’t get to have any influence on the content and outputs. But I can see why people do object. What is a shame is that the campaign didn’t happen because there was no other source of funding. In reality, people will die as a result of not knowing this useful information.”</p></blockquote>
  113. <p>It seems like the academics were failing to think at the margin here; the choice here was between a campaign and no campaign, and regardless of the source of funding, getting people to drink less would have been good. I can’t help but be reminded of mistakes made by those working on public health in 2020, where a failure to think on the margin and act fast led to worse public health outcomes.</p>
  114. <p>So alcohol is bad, too much alcohol is *really* bad, and we could go a significant distance to solving this problem if we could work out the political economy a bit better.</p>
  115. <p>But we can’t work out the political economy, at least for now. Unless there is a sudden national temperance movement, the drinks industry is a powerful lobbying force in the UK.</p>
  116. <p>Alcohol’s damaging impact on society remains, then. You could lobby your MP, and if enough people do that effectively then maybe the drinks industry would eventually be cowed.</p>
  117. <p>That seems a bit unsatisfactory, though. The book shows that so much of alcohol consumption is cultural; it’s just ‘the done thing’ to go out for an alcoholic drink or ten with your mates. If you have any experience in British society, then you will know this to be true.</p>
  118. <p>The winners in this equilibrium are people who, for one reason or another, can manage this situation well. They aren’t genetically predisposed to alcohol addiction; they are socially confident so don’t feel the need for Dutch courage or the need to show off by drinking too much; or, perhaps, they are successful or content in the different spheres of their life, so they don’t have pain that they want to numb. Some successful people are vulnerable too in a different way, being wined and dined if you’re an executive, or trying to climb a corporate ladder by getting drinks with whoever after work.</p>
  119. <p>It seems wrong that a privileged (!) class of people who can manage alcohol effectively in their lives do not try harder to make sure that the under-privileged, vulnerable members of society don’t end up addicted to this awful drug.</p>
  120. <p>It’s possible to consume alcohol in a safe manner, with risks to your long term health that you might consider acceptable if you enjoy drinking it. But at some margin, you are contributing to the idea that it’s normal to drink it. And we need to break down that norm.</p>
  121. <p>I don’t really enjoy drinking alcohol, frankly. I drink a little bit at some social occasions, but following my own argument here, I’m not really sure that I should. By properly abstaining, I could help to undermine the idea that alcohol is normal. And it wouldn’t be that much extra effort to do so.</p>
  122. <p>I don’t know what Nutt’s personal political or moral views are, but I can’t help but notice that modern liberalism has no real argument against people harming themselves and others with alcohol if that’s what they want to do. In the absence of a Christian or other religious framework, it’s quite difficult to argue that you <em>should</em> do anything about alcohol. Who can tell you what makes your life worthwhile?</p>
  123. <p>Take the increase in the minimum drinking age in America in the 1980s for example. The National Minimum Drinking Age Act is thought to have saved hundreds of thousands of young lives that would have been lost as a result of drink-driving. But Nutt doesn’t want to raise the minimum drinking age, despite this data:</p>
  124. <blockquote class="wp-block-quote"><p>If someone can vote, if they can join the army, fight and die, get married, then they should be allowed to buy alcohol.”</p></blockquote>
  125. <p>Granted, there is a certain logic here. Yet the same argument could be made about cocaine or heroin — you’re an adult, you can decide (Nutt, it seems has been willing to follow his logic to its conclusion for <a href="https://en.wikipedia.org/wiki/David_Nutt#%22Equasy%22">ecstasy</a>, at least from a ‘harm caused’ perspective). Those drugs are damaging for people and society, and I don’t think anyone has a ‘right’ to take them. But modern liberalism says that you are an autonomous person from age 18 who has no responsibilities to others, and thus provides limited moral arguments against drugs of any kind. If this moral framework is not available to British society anymore, then perhaps <a href="https://marginalrevolution.com/marginalrevolution/2017/08/im-mormons-one.html">individual teetotalism is the only way to go</a>. That way the norm of alcohol consumption can be undermined, one person at a time. </p>
  126. <p>A Christian framework can be extremely helpful here. The Bible is <a href="https://ca.thegospelcoalition.org/columns/ad-fontes/the-case-for-cautious-consumption/">not definitively teetotal</a> (for instance, Christ makes wine for the wedding at Cana in John 2:1-11). But abstention could be the right option for you, either for personal reasons or because of your <a href="https://web.archive.org/web/20060704174712/http://www.bpnews.net/bpcolumn.asp?ID=2298">convictions</a>. The Bible does, however, prohibit drunkenness (for example, see Ephesians 5:18), which leads to much worse health and social outcomes than light drinking. Crucially, there are no grounds for looking down on people who take a different path from you, as long as it is within these guardrails (see Romans 14:21 or a discussion <a href="https://www.thegospelcoalition.org/blogs/justin-taylor/alcohol-liberty-and-legalism/">here</a>).</p>
  127. <p>Alcohol occupies a sinister position in British society and culture. But there is a better way, with stricter rules and different norms. You don’t have to fully agree with my prescriptions here to wonder what a society with no alcohol problems would look like. Formerly wasted talent could be used in the economy, an invigorated health service could enjoy reduced waiting times, families and relationships could be healthier and less violent. If we want to get there, it’s worth talking more about the problem of alcohol.</p>
  128. </article>
  129. <hr>
  130. <footer>
  131. <p>
  132. <a href="/david/" title="Aller à l’accueil"><svg class="icon icon-home">
  133. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-home"></use>
  134. </svg> Accueil</a> •
  135. <a href="/david/log/" title="Accès au flux RSS"><svg class="icon icon-rss2">
  136. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-rss2"></use>
  137. </svg> RSS</a> •
  138. <a href="http://larlet.com" title="Go to my English profile" data-instant><svg class="icon icon-user-tie">
  139. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-user-tie"></use>
  140. </svg> Pro</a> •
  141. <a href="mailto:david%40larlet.fr" title="Envoyer un courriel"><svg class="icon icon-mail">
  142. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-mail"></use>
  143. </svg> Email</a> •
  144. <abbr class="nowrap" title="Hébergeur : Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33184162340"><svg class="icon icon-hammer2">
  145. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-hammer2"></use>
  146. </svg> Légal</abbr>
  147. </p>
  148. <template id="theme-selector">
  149. <form>
  150. <fieldset>
  151. <legend><svg class="icon icon-brightness-contrast">
  152. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-brightness-contrast"></use>
  153. </svg> Thème</legend>
  154. <label>
  155. <input type="radio" value="auto" name="chosen-color-scheme" checked> Auto
  156. </label>
  157. <label>
  158. <input type="radio" value="dark" name="chosen-color-scheme"> Foncé
  159. </label>
  160. <label>
  161. <input type="radio" value="light" name="chosen-color-scheme"> Clair
  162. </label>
  163. </fieldset>
  164. </form>
  165. </template>
  166. </footer>
  167. <script>
  168. function loadThemeForm(templateName) {
  169. const themeSelectorTemplate = document.querySelector(templateName)
  170. const form = themeSelectorTemplate.content.firstElementChild
  171. themeSelectorTemplate.replaceWith(form)
  172. form.addEventListener('change', (e) => {
  173. const chosenColorScheme = e.target.value
  174. localStorage.setItem('theme', chosenColorScheme)
  175. toggleTheme(chosenColorScheme)
  176. })
  177. const selectedTheme = localStorage.getItem('theme')
  178. if (selectedTheme && selectedTheme !== 'undefined') {
  179. form.querySelector(`[value="${selectedTheme}"]`).checked = true
  180. }
  181. }
  182. const prefersColorSchemeDark = '(prefers-color-scheme: dark)'
  183. window.addEventListener('load', () => {
  184. let hasDarkRules = false
  185. for (const styleSheet of Array.from(document.styleSheets)) {
  186. let mediaRules = []
  187. for (const cssRule of styleSheet.cssRules) {
  188. if (cssRule.type !== CSSRule.MEDIA_RULE) {
  189. continue
  190. }
  191. // WARNING: Safari does not have/supports `conditionText`.
  192. if (cssRule.conditionText) {
  193. if (cssRule.conditionText !== prefersColorSchemeDark) {
  194. continue
  195. }
  196. } else {
  197. if (cssRule.cssText.startsWith(prefersColorSchemeDark)) {
  198. continue
  199. }
  200. }
  201. mediaRules = mediaRules.concat(Array.from(cssRule.cssRules))
  202. }
  203. // WARNING: do not try to insert a Rule to a styleSheet you are
  204. // currently iterating on, otherwise the browser will be stuck
  205. // in a infinite loop…
  206. for (const mediaRule of mediaRules) {
  207. styleSheet.insertRule(mediaRule.cssText)
  208. hasDarkRules = true
  209. }
  210. }
  211. if (hasDarkRules) {
  212. loadThemeForm('#theme-selector')
  213. }
  214. })
  215. </script>
  216. </body>
  217. </html>