Add Instagram replacement preference

Fixes #133
This commit is contained in:
Zed 2020-03-29 09:03:06 +02:00
parent a7ffb6d2f2
commit ed79ed25a7
6 changed files with 16 additions and 8 deletions

View file

@ -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")

View file

@ -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

View file

@ -19,6 +19,7 @@ withDb:
safeAddColumn Prefs.hidePins
safeAddColumn Prefs.hideReplies
safeAddColumn Prefs.infiniteScroll
safeAddColumn Prefs.replaceInstagram
proc getDefaultPrefs(cfg: Config): Prefs =
result = genDefaultPrefs()

View file

@ -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"

View file

@ -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 {

View file

@ -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 = ""
<?xml version="1.0" encoding="UTF-8"?>
@ -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 = ""
<?xml version="1.0" encoding="UTF-8"?>