[Buggy] Redlib Quirk Fixer

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

当前为 2024-07-04 提交的版本,查看 最新版本

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