From ed79ed25a7d66323118febf748790180d8677482 Mon Sep 17 00:00:00 2001 From: Zed Date: Sun, 29 Mar 2020 09:03:06 +0200 Subject: [PATCH] Add Instagram replacement preference Fixes #133 --- src/formatters.nim | 3 +++ src/parserutils.nim | 6 +++--- src/prefs.nim | 1 + src/prefs_impl.nim | 4 ++++ src/sass/inputs.scss | 4 ++-- src/views/rss.nimf | 6 +++--- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/formatters.nim b/src/formatters.nim index b981428..3e2a871 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -9,6 +9,7 @@ from unicode import Rune, `$` const ytRegex = re"([A-z.]+\.)?youtu(be\.com|\.be)" twRegex = re"(www\.|mobile\.)?twitter\.com" + igRegex = re"(www\.)?instagram.com" cards = "cards.twitter.com/cards" tco = "https://t.co" nbsp = $Rune(0x000A0) @@ -41,6 +42,8 @@ proc replaceUrl*(url: string; prefs: Prefs; absolute=""): string = result = result.replace(ytRegex, prefs.replaceYouTube) if prefs.replaceYouTube in result: result = result.replace("/c/", "/") + if prefs.replaceInstagram.len > 0: + result = result.replace(igRegex, prefs.replaceInstagram) if prefs.replaceTwitter.len > 0: result = result.replace(tco, "https://" & prefs.replaceTwitter & "/t.co") result = result.replace(cards, prefs.replaceTwitter & "/cards") diff --git a/src/parserutils.nim b/src/parserutils.nim index 01d582d..cdd003d 100644 --- a/src/parserutils.nim +++ b/src/parserutils.nim @@ -1,4 +1,5 @@ -import xmltree, strtabs, strformat, strutils, times, uri, options, json +import xmltree, times, uri, options, json +import strtabs, strformat, strutils, sequtils import regex import types, formatters @@ -183,8 +184,7 @@ proc parseTweetReply*(node: XmlNode): seq[string] = let selector = if "Quote" in node.attr("class"): "b" else: "a b" - for username in reply.selectAll(selector): - result.add username.innerText() + result = reply.selectAll(selector).map(innerText) proc getGif(player: XmlNode): Gif = let diff --git a/src/prefs.nim b/src/prefs.nim index f388a89..7a0401c 100644 --- a/src/prefs.nim +++ b/src/prefs.nim @@ -19,6 +19,7 @@ withDb: safeAddColumn Prefs.hidePins safeAddColumn Prefs.hideReplies safeAddColumn Prefs.infiniteScroll + safeAddColumn Prefs.replaceInstagram proc getDefaultPrefs(cfg: Config): Prefs = result = genDefaultPrefs() diff --git a/src/prefs_impl.nim b/src/prefs_impl.nim index c2febcc..d38376a 100644 --- a/src/prefs_impl.nim +++ b/src/prefs_impl.nim @@ -53,6 +53,10 @@ genPrefs: "Replace YouTube links with Invidious (blank to disable)" placeholder: "Invidious hostname" + replaceInstagram(input, ""): + "Replace Instagram links with Bibliogram (blank to disable)" + placeholder: "Bibliogram hostname" + Media: mp4Playback(checkbox, true): "Enable mp4 video playback" diff --git a/src/sass/inputs.scss b/src/sass/inputs.scss index ff7f475..17c2a22 100644 --- a/src/sass/inputs.scss +++ b/src/sass/inputs.scss @@ -151,7 +151,7 @@ input::-webkit-datetime-edit-year-field:focus { } label { - padding-right: 135px; + padding-right: 150px; } select { @@ -167,7 +167,7 @@ input::-webkit-datetime-edit-year-field:focus { input[type="text"] { position: absolute; right: 0; - max-width: 120px; + max-width: 140px; } .pref-group { diff --git a/src/views/rss.nimf b/src/views/rss.nimf index e46a3df..50415dc 100644 --- a/src/views/rss.nimf +++ b/src/views/rss.nimf @@ -60,7 +60,7 @@ #end proc # #proc renderTimelineRss*(timeline: Timeline; profile: Profile; hostname: string; multi=false): string = -#let prefs = Prefs(replaceTwitter: hostname, replaceYoutube: "invidio.us") +#let prefs = Prefs(replaceTwitter: hostname, replaceYouTube: "invidio.us") #result = "" #let user = (if multi: "" else: "@") & profile.username #var title = profile.fullname @@ -90,7 +90,7 @@ #end proc # #proc renderListRss*(tweets: seq[Tweet]; name, list, hostname: string): string = -#let prefs = Prefs(replaceTwitter: hostname, replaceYoutube: "invidio.us") +#let prefs = Prefs(replaceTwitter: hostname, replaceYouTube: "invidio.us") #let link = &"https://{hostname}/{name}/lists/{list}" #result = "" @@ -108,7 +108,7 @@ #end proc # #proc renderSearchRss*(tweets: seq[Tweet]; name, param, hostname: string): string = -#let prefs = Prefs(replaceTwitter: hostname, replaceYoutube: "invidio.us") +#let prefs = Prefs(replaceTwitter: hostname, replaceYouTube: "invidio.us") #let link = &"https://{hostname}/search" #result = ""