Skip to content

Commit

Permalink
bookmarklet for nitter rss url
Browse files Browse the repository at this point in the history
  • Loading branch information
KTachibanaM committed Nov 10, 2024
1 parent b670d38 commit 8de666d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This is a forked version of Nitter ([original version](https://github.com/sekai-
* Fix video playback via Nitter proxying
* Fix photo rail section on profile page
* Add optional Sentry error reporting
* Add bookmarklet that opens protected RSS URL from a Twitter page
* Unified Docker image for x86_64 and arm64

## Usage
Expand Down
2 changes: 1 addition & 1 deletion src/routes/preferences.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ proc createPrefRouter*(cfg: Config) =
get "/settings":
let
prefs = cookiePrefs()
html = renderPreferences(prefs, refPath(), findThemes(cfg.staticDir))
html = renderPreferences(prefs, refPath(), findThemes(cfg.staticDir), cfg.hostname, cfg.useHttps)
resp renderMain(html, request, cfg, prefs, "Preferences")

get "/settings/@i?":
Expand Down
25 changes: 24 additions & 1 deletion src/views/preferences.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import karax/[karaxdsl, vdom]
import renderutils
import ../types, ../prefs_impl

from os import getEnv, existsEnv

macro renderPrefs*(): untyped =
result = nnkCall.newTree(
ident("buildHtml"), ident("tdiv"), nnkStmtList.newTree())
Expand Down Expand Up @@ -32,14 +34,35 @@ macro renderPrefs*(): untyped =

result[2].add stmt

proc renderPreferences*(prefs: Prefs; path: string; themes: seq[string]): VNode =
let openNitterRssUrlJs = """
javascript:(function() {
const url = window.location.href;
if (!url.startsWith("https://x.com")) {
alert("This is not a Twitter page");
return
}
const rssUrl = `HTTP_OR_S://HOSTNAME${url.slice("https://x.com".length)}/rssRSS_KEY`;
window.open(rssUrl, '_blank').focus();
})();
"""

proc renderPreferences*(prefs: Prefs; path: string; themes: seq[string]; hostname: string; useHttps: bool): VNode =
buildHtml(tdiv(class="overlay-panel")):
fieldset(class="preferences"):
form(`method`="post", action="/saveprefs", autocomplete="off"):
refererField path

renderPrefs()

legend:
text "Bookmarklets (drag them to bookmark bar)"

a(href=openNitterRssUrlJs
.replace("HTTP_OR_S", if useHttps: "https" else: "http")
.replace("HOSTNAME", hostname)
.replace("RSS_KEY", if existsEnv("INSTANCE_RSS_PASSWORD"): "?key=" & getEnv("INSTANCE_RSS_PASSWORD") else: "")):
text "Open Nitter RSS URL"

h4(class="note"):
text "Preferences are stored client-side using cookies without any personal information."

Expand Down

0 comments on commit 8de666d

Please sign in to comment.