stop adding target="_blank" in the backend and move it to the frontend (to accomodate PWA users) - THANK YOU GEESE I LOVE YOU SO MUCH (#473)
* test * bleg * remove User.newtab and see if anyone complains (#471) * fddfpull/2/head
parent
f52aec0477
commit
88f3cd519d
|
@ -255,7 +255,7 @@ function bs_trigger(e) {
|
|||
}
|
||||
})
|
||||
|
||||
if (typeof update_speed_emoji_modal != 'undefined') {
|
||||
if (typeof update_speed_emoji_modal == 'function') {
|
||||
let forms = e.querySelectorAll("textarea, .allow-emojis");
|
||||
forms.forEach(i => {
|
||||
let pseudo_div = document.createElement("div");
|
||||
|
@ -266,6 +266,9 @@ function bs_trigger(e) {
|
|||
i.addEventListener('keydown', speed_carot_navigate, false);
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof link_trigger === "function")
|
||||
link_trigger(e);
|
||||
}
|
||||
|
||||
var bsTriggerOnReady = function() {
|
||||
|
|
|
@ -98,9 +98,9 @@ def notify_mentions(send_to, mentions, mention_str='site mention'):
|
|||
text = sanitize(m['text'], golden=False)
|
||||
notif_text = (
|
||||
f'<p>New {mention_str} by <a href="https://old.reddit.com/u/{author}" '
|
||||
f'rel="nofollow noopener" target="_blank">/u/{author}</a></p>'
|
||||
f'rel="nofollow noopener">/u/{author}</a></p>'
|
||||
f'<p><a href="https://old.reddit.com{permalink}?context=89" '
|
||||
'rel="nofollow noopener" target="_blank">'
|
||||
'rel="nofollow noopener">'
|
||||
f'https://old.reddit.com{permalink}?context=89</a></p>'
|
||||
f'{text}'
|
||||
)
|
||||
|
|
|
@ -63,7 +63,6 @@ def allowed_attributes(tag, name, value):
|
|||
if name == 'href' and '\\' not in value and 'xn--' not in value:
|
||||
return True
|
||||
if name == 'rel' and value == 'nofollow noopener': return True
|
||||
if name == 'target' and value == '_blank': return True
|
||||
return False
|
||||
|
||||
if tag == 'img':
|
||||
|
@ -145,8 +144,7 @@ def callback(attrs, new=False):
|
|||
del attrs[(None, "href")] # Make unclickable and reset harmful payload
|
||||
return attrs
|
||||
|
||||
if not href.startswith('/') and not href.startswith(f'{SITE_FULL}/'):
|
||||
attrs[(None, "target")] = "_blank"
|
||||
if not is_site_url(href):
|
||||
attrs[(None, "rel")] = "nofollow noopener"
|
||||
|
||||
return attrs
|
||||
|
@ -271,7 +269,7 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys
|
|||
# replacing zero width characters, overlines, fake colons
|
||||
sanitized = sanitized.replace('\u200e','').replace('\u200b','').replace("\ufeff", "").replace("\u033f","").replace("\u0589", ":")
|
||||
|
||||
sanitized = reddit_regex.sub(r'\1<a href="https://old.reddit.com/\2" rel="nofollow noopener" target="_blank">/\2</a>', sanitized)
|
||||
sanitized = reddit_regex.sub(r'\1<a href="https://old.reddit.com/\2" rel="nofollow noopener">/\2</a>', sanitized)
|
||||
sanitized = sub_regex.sub(r'\1<a href="/\2">/\2</a>', sanitized)
|
||||
|
||||
v = getattr(g, 'v', None)
|
||||
|
@ -298,7 +296,7 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys
|
|||
for tag in soup.find_all("img"):
|
||||
if tag.get("src") and not tag["src"].startswith('/pp/'):
|
||||
if not is_safe_url(tag["src"]):
|
||||
a = soup.new_tag("a", href=tag["src"], rel="nofollow noopener", target="_blank")
|
||||
a = soup.new_tag("a", href=tag["src"], rel="nofollow noopener")
|
||||
a.string = tag["src"]
|
||||
tag.replace_with(a)
|
||||
continue
|
||||
|
@ -312,7 +310,6 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys
|
|||
a = soup.new_tag("a", href=tag["data-src"])
|
||||
if not is_site_url(a["href"]):
|
||||
a["rel"] = "nofollow noopener"
|
||||
a["target"] = "_blank"
|
||||
tag = tag.replace_with(a)
|
||||
a.append(tag)
|
||||
|
||||
|
|
|
@ -153,7 +153,7 @@ def vote_post_comment(target_id, new, v, cls, vote_cls):
|
|||
elif target.sub and target.sub not in UNNERFED_HOLES:
|
||||
mul = 0.7
|
||||
elif not target.sub and target.body_html and target.author.id not in BOOSTED_USERS_EXCLUDED:
|
||||
x = target.body_html.count('" target="_blank" rel="nofollow noopener">')
|
||||
x = target.body_html.count('<a href="https://')
|
||||
x += target.body_html.count('<a href="/images/')
|
||||
target.realupvotes += min(x*2, 20)
|
||||
mul = 1 + x/10
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
|
||||
{% if not p.is_image and p.thumb_url and not p.embed_url %}
|
||||
<div class="card-header bg-transparent border-0 d-none d-md-flex flex-row flex-nowrap pl-3 p-0">
|
||||
<a rel="nofollow noopener" href="{{p.realurl(v)}}" style="height: fit-content"{% if not v or v.newtabexternal %}target="_blank"{% endif %}><img loading="lazy" src="{{p.thumb_url}}" class="post-img d-mob-none" alt="Unable to load image"></a>
|
||||
<a rel="nofollow noopener" href="{{p.realurl(v)}}" style="height: fit-content"><img loading="lazy" src="{{p.thumb_url}}" class="post-img d-mob-none" alt="Unable to load image"></a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
@ -103,7 +103,7 @@
|
|||
{% endif %}
|
||||
{% if p.realurl(v) and not v_forbid_deleted %}
|
||||
<h1 id="post-title" class="card-title post-title text-left mb-md-3 {% if p.author.agendaposter and p.sub != 'chudrama' %}agendaposter{% endif %}">
|
||||
<a {% if p.author.rainbow %}class="rainbow-text"{% endif %} {% if not v or v.newtabexternal %}target="_blank"{% endif %} rel="nofollow noopener" href="{{p.realurl(v)}}">
|
||||
<a {% if p.author.rainbow %}class="rainbow-text"{% endif %} rel="nofollow noopener" href="{{p.realurl(v)}}">
|
||||
{% if p.club %}<span class="patron font-weight-bolder mr-1" style="background-color:red; font-size:12px; line-height:2;">{{CC}}</span>{% endif %}
|
||||
{% if p.flair %}<span class="patron font-weight-bolder mr-1" style="background-color:var(--primary); font-size:12px; line-height:2;">{{p.flair | safe}}</span>{% endif %}
|
||||
{{p.realtitle(v) | safe}}
|
||||
|
@ -121,7 +121,7 @@
|
|||
<div id="post-body" class="post-body mt-3">
|
||||
{% if p.realurl(v) %}
|
||||
{% if not p.embed_url and not p.is_image %}
|
||||
<a rel="nofollow noopener" href="{{p.realurl(v)}}" {% if not v or v.newtabexternal %}target="_blank"{% endif %}>
|
||||
<a rel="nofollow noopener" href="{{p.realurl(v)}}">
|
||||
<div class="d-flex {% if p.is_video or p.is_audio %}d-md-none{% endif %} justify-content-between align-items-center border rounded p-2 mb-3">
|
||||
<span>{{p.realurl(v)}}</span>
|
||||
<i class="fas fa-external-link-alt text-small"></i>
|
||||
|
@ -149,7 +149,7 @@
|
|||
{% if p.is_image %}
|
||||
<div class="row no-gutters mb-4">
|
||||
<div class="col">
|
||||
<a {% if not v or v.newtabexternal %}target="_blank"{% endif %} rel="nofollow noopener" href="{{p.realurl(v)}}">
|
||||
<a rel="nofollow noopener" href="{{p.realurl(v)}}">
|
||||
<img onclick="expandDesktopImage()" src="{{p.realurl(v)}}" class="img-fluid" style="max-height:500px" alt="Unable to load image">
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
@ -98,7 +98,7 @@
|
|||
<img onclick="toggleyoutube('{{p.id}}')" alt="post thumnail" loading="lazy" src="{{p.thumb_url}}" class="post-img">
|
||||
</a>
|
||||
{% else %}
|
||||
<a {% if not v or v.newtabexternal %}target="_blank"{% endif %} rel="nofollow noopener" href="{{p.realurl(v)}}">
|
||||
<a rel="nofollow noopener" href="{{p.realurl(v)}}">
|
||||
<img alt="post thumnail" loading="lazy" src="{{p.thumb_url}}" class="post-img">
|
||||
<i class="ext-link fas fa-external-link"></i>
|
||||
</a>
|
||||
|
|
|
@ -11,6 +11,26 @@
|
|||
{% macro javascript() %}
|
||||
<script defer src="{{'js/vendor/bootstrap.js' | asset}}"></script>
|
||||
<script defer src="{{'js/core.js' | asset}}"></script>
|
||||
|
||||
{% if not v or v.newtabexternal %}
|
||||
<script>
|
||||
if (!window.matchMedia('(display-mode: standalone)')['matches']) { // if not PWA
|
||||
function link_trigger(e) {
|
||||
const links = e.getElementsByTagName('a') // get all link elements
|
||||
for (const link of links) { // loop on them
|
||||
if (!(link.href.startsWith('/') || link.href.startsWith('{{SITE_FULL}}'))) // if not site url
|
||||
{
|
||||
console.log('hello')
|
||||
link.target = "_blank" // open in new tab
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', link_trigger(document));
|
||||
}
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
{% endmacro %}
|
||||
|
||||
{% macro page_meta(title=none) %}
|
||||
|
|
Loading…
Reference in New Issue