[Buggy] Redlib Quirk Fixer

Fix some quirks of Redlib (previously Libreddit) instances (disabled HLS, disabled NSFW, etc). Buggy, see README.

当前为 2024-02-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name [Buggy] Redlib Quirk Fixer
  3. // @namespace happyviking
  4. // @version 1.7.0
  5. // @grant none
  6. // @run-at document-end
  7. // @license MIT
  8. // @description Fix some quirks of Redlib (previously Libreddit) instances (disabled HLS, disabled NSFW, etc). Buggy, see README.
  9. // @icon https://gitlab.com/uploads/-/system/project/avatar/32545239/libreddit.png
  10. // @author HappyViking
  11.  
  12. // <<INSTANCES START HERE>>
  13. // @match https://eu.safereddit.com/*
  14. // @match https://l.opnxng.com/*
  15. // @match https://libreddit.bus-hit.me/*
  16. // @match https://libreddit.privacydev.net/*
  17. // @match https://libreddit.projectsegfau.lt/*
  18. // @match https://reddit.idevicehacked.com/*
  19. // @match https://reddit.invak.id/*
  20. // @match https://redlib.freedit.eu/*
  21. // @match https://redlib.matthew.science/*
  22. // @match https://redlib.nohost.network/*
  23. // @match https://redlib.perennialte.ch/*
  24. // @match https://redlib.r4fo.com/*
  25. // @match https://redlib.tux.pizza/*
  26. // @match https://redlib.vimmer.dev/*
  27. // @match https://redlib.xn--hackerhhle-kcb.org/*
  28. // @match https://rl.bloat.cat/*
  29. // @match https://redlib.catsarch.com/*
  30. // @match https://safereddit.com/*
  31. // @match https://libreddit.freedit.eu/*
  32. // @match https://libreddit.hu/*
  33. // @match https://libreddit.kylrth.com/*
  34. // @match https://libreddit.lunar.icu/*
  35. // @match https://libreddit.mha.fi/*
  36. // @match https://libreddit.northboot.xyz/*
  37. // @match https://libreddit.oxymagnesium.com/*
  38. // @match https://libreddit.pussthecat.org/*
  39. // @match https://libreddit.spike.codes/*
  40. // @match https://libreddit.strongthany.cc/*
  41. // @match https://libreddit.tiekoetter.com/*
  42. // @match https://lr.4201337.xyz/*
  43. // @match https://lr.aeong.one/*
  44. // @match https://lr.artemislena.eu/*
  45. // @match https://lr.slipfox.xyz/*
  46. // @match https://r.walkx.fyi/*
  47. // @match https://reddit.rtrace.io/*
  48. // @match https://reddit.simo.sh/*
  49. // @match https://reddit.smnz.de/*
  50. // @match https://reddit.utsav2.dev/*
  51. // @match https://snoo.habedieeh.re/*
  52. // @match https://libreddit.kutay.dev/*
  53. // @match https://libreddit.tux.pizza/*
  54. // @match https://lr.vern.cc/*
  55. // @match https://r.darklab.sh/*
  56. // @match https://reddit.leptons.xyz/*
  57. // @match https://discuss.whatever.social/*
  58. // @match https://libreddit.kavin.rocks/*
  59. // @match https://libreddit.cachyos.org/*
  60. // @match https://libreddit.domain.glass/*
  61. // @match https://libreddit.privacy.com.de/*
  62. // @match https://reddit.baby/*
  63. // <<INSTANCES END HERE>>
  64.  
  65. // @match https://geoblock.ste.company/restricted/*
  66.  
  67. // ==/UserScript==
  68.  
  69. let shouldReloadWithNewPreferences = false
  70. let preferencesString = ""
  71.  
  72. function setPreference(name, val) {
  73. preferencesString += `&${name}=${val}`
  74. shouldReloadWithNewPreferences = true
  75. }
  76.  
  77. function tryNewInstance(suffix){
  78. location.replace('https://farside.link/redlib/' + suffix ?? (window.location.pathname + window.location.search));
  79. }
  80.  
  81. function setCookie(name, val) {
  82. const expiry = new Date()
  83. expiry.setMonth(expiry.getMonth() + 1)
  84. const domainAssociation = "domain=" + window.location.hostname;
  85. document.cookie = `${name}=${val};${domainAssociation};expires=${expiry.toUTCString()}`;
  86. }
  87. function getCookie(name) {
  88. const nameInfo = name + "=";
  89. const cookieList = document.cookie.split(';');
  90. return cookieList.find(c => c.trim().startsWith(nameInfo))
  91. }
  92.  
  93. function fixNSFWGate() {
  94. const nsfwElement = document.getElementById("nsfw_landing")
  95. if (!nsfwElement) return;
  96. const nsfwInfo = nsfwElement.querySelector("p")?.innerHTML
  97. if (!nsfwInfo) return
  98. if (nsfwInfo.includes("SFW-only")){
  99. const addedMessage = document.createElement("p")
  100. addedMessage.textContent = "Redirecting you to new instance..."
  101. nsfwElement.appendChild(addedMessage)
  102. tryNewInstance()
  103. }else{
  104. setPreference("show_nsfw", "on")
  105. }
  106. }
  107.  
  108. // In case the server doesn't actually serve a proper page, for any reason.
  109. // Since some might just have something like captcha pages (which are fine), we'll
  110. // only do this for some known problematic instances
  111. function fixInvalidPage(){
  112. if (["reddit.invak.id", "reddit.simo.sh"].includes(window.location.hostname)){
  113. const description = document.querySelector('meta[name="description"]')?.content
  114. if (!description ||
  115. typeof description != "string" ||
  116. !["libreddit", "redlib"].some(x => description.toLowerCase().includes(x))){
  117. tryNewInstance()
  118. }
  119. }
  120. }
  121.  
  122.  
  123. function fixDefaultCommentOrder(){
  124. if (["lr.artemislena.eu"].includes(window.location.hostname)){
  125. const COOKIE_NAME = window.location.hostname + "FIXED_COMMENT_ORDER"
  126. if (!getCookie(COOKIE_NAME)){
  127. setCookie(COOKIE_NAME, "yes")
  128. setPreference("comment_sort", "confidence")
  129. }
  130. }
  131. }
  132.  
  133. function fixNoHls() {
  134. const notifications = document.getElementsByClassName("post_notification")
  135. for (const notification of notifications){
  136. const notifMessage = notification.querySelector("a")?.textContent
  137. if (notifMessage.trim() === "Enable HLS"){
  138. setPreference("use_hls", "on")
  139. break
  140. }
  141. }
  142. }
  143.  
  144. function fixGeoFencing() {
  145. if (window.location.hostname == "geoblock.ste.company" && window.location.search.includes("reddit")) {
  146. const redirect = new URL(location.href).searchParams.get('path')
  147. tryNewInstance(redirect)
  148. }
  149. }
  150.  
  151. fixInvalidPage()
  152. fixGeoFencing()
  153. fixDefaultCommentOrder()
  154. fixNSFWGate()
  155. fixNoHls()
  156.  
  157. if (shouldReloadWithNewPreferences){
  158. // We might as well turn on HLS before we realize that it's not enabled and we
  159. // have to reload a second time...
  160. setPreference("use_hls", "on")
  161. location.replace(`https://${window.location.hostname}/settings/update?${preferencesString}&redirect=${encodeURI(window.location.pathname.slice(1) + window.location.search)}`)
  162. }