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 const
ytRegex = re"([A-z.]+\.)?youtu(be\.com|\.be)" ytRegex = re"([A-z.]+\.)?youtu(be\.com|\.be)"
twRegex = re"(www\.|mobile\.)?twitter\.com" twRegex = re"(www\.|mobile\.)?twitter\.com"
igRegex = re"(www\.)?instagram.com"
cards = "cards.twitter.com/cards" cards = "cards.twitter.com/cards"
tco = "https://t.co" tco = "https://t.co"
nbsp = $Rune(0x000A0) nbsp = $Rune(0x000A0)
@ -41,6 +42,8 @@ proc replaceUrl*(url: string; prefs: Prefs; absolute=""): string =
result = result.replace(ytRegex, prefs.replaceYouTube) result = result.replace(ytRegex, prefs.replaceYouTube)
if prefs.replaceYouTube in result: if prefs.replaceYouTube in result:
result = result.replace("/c/", "/") result = result.replace("/c/", "/")
if prefs.replaceInstagram.len > 0:
result = result.replace(igRegex, prefs.replaceInstagram)
if prefs.replaceTwitter.len > 0: if prefs.replaceTwitter.len > 0:
result = result.replace(tco, "https://" & prefs.replaceTwitter & "/t.co") result = result.replace(tco, "https://" & prefs.replaceTwitter & "/t.co")
result = result.replace(cards, prefs.replaceTwitter & "/cards") 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 regex
import types, formatters import types, formatters
@ -183,8 +184,7 @@ proc parseTweetReply*(node: XmlNode): seq[string] =
let selector = if "Quote" in node.attr("class"): "b" let selector = if "Quote" in node.attr("class"): "b"
else: "a b" else: "a b"
for username in reply.selectAll(selector): result = reply.selectAll(selector).map(innerText)
result.add username.innerText()
proc getGif(player: XmlNode): Gif = proc getGif(player: XmlNode): Gif =
let let

View File

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

View File

@ -53,6 +53,10 @@ genPrefs:
"Replace YouTube links with Invidious (blank to disable)" "Replace YouTube links with Invidious (blank to disable)"
placeholder: "Invidious hostname" placeholder: "Invidious hostname"
replaceInstagram(input, ""):
"Replace Instagram links with Bibliogram (blank to disable)"
placeholder: "Bibliogram hostname"
Media: Media:
mp4Playback(checkbox, true): mp4Playback(checkbox, true):
"Enable mp4 video playback" "Enable mp4 video playback"

View File

@ -151,7 +151,7 @@ input::-webkit-datetime-edit-year-field:focus {
} }
label { label {
padding-right: 135px; padding-right: 150px;
} }
select { select {
@ -167,7 +167,7 @@ input::-webkit-datetime-edit-year-field:focus {
input[type="text"] { input[type="text"] {
position: absolute; position: absolute;
right: 0; right: 0;
max-width: 120px; max-width: 140px;
} }
.pref-group { .pref-group {

View File

@ -60,7 +60,7 @@
#end proc #end proc
# #
#proc renderTimelineRss*(timeline: Timeline; profile: Profile; hostname: string; multi=false): string = #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 = "" #result = ""
#let user = (if multi: "" else: "@") & profile.username #let user = (if multi: "" else: "@") & profile.username
#var title = profile.fullname #var title = profile.fullname
@ -90,7 +90,7 @@
#end proc #end proc
# #
#proc renderListRss*(tweets: seq[Tweet]; name, list, hostname: string): string = #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}" #let link = &"https://{hostname}/{name}/lists/{list}"
#result = "" #result = ""
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
@ -108,7 +108,7 @@
#end proc #end proc
# #
#proc renderSearchRss*(tweets: seq[Tweet]; name, param, hostname: string): string = #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" #let link = &"https://{hostname}/search"
#result = "" #result = ""
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>