From e8cc66dce7993da0ba3bbecd5fdd3f60ecb106ec Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 24 Jan 2021 15:32:14 -0700 Subject: [PATCH] Update components, fix url rewriter. Closes #2538 --- resources/assets/js/app.js | 18 +++++++++++++++ .../assets/js/components/PostComponent.vue | 22 ++++--------------- resources/assets/js/components/RemotePost.vue | 22 ++++--------------- resources/assets/js/components/Timeline.vue | 22 ++++--------------- 4 files changed, 30 insertions(+), 54 deletions(-) diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 9ca23ef5b..2d1af4b41 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -96,6 +96,24 @@ window.App.util = { return interval + "m"; } return Math.floor(seconds) + "s"; + }), + rewriteLinks: (function(i) { + + let tag = i.innerText; + + if(i.href.startsWith(window.location.origin)) { + return i.href; + } + + if(tag.startsWith('#') == true) { + tag = '/discover/tags/' + tag.substr(1) +'?src=rph'; + } else if(tag.startsWith('@') == true) { + tag = '/' + i.innerText + '?src=rpp'; + } else { + tag = '/i/redirect?url=' + encodeURIComponent(tag); + } + + return tag; }) }, filters: [ diff --git a/resources/assets/js/components/PostComponent.vue b/resources/assets/js/components/PostComponent.vue index e53767c74..2c23b9bf0 100644 --- a/resources/assets/js/components/PostComponent.vue +++ b/resources/assets/js/components/PostComponent.vue @@ -905,15 +905,8 @@ export default { }, 3000); setTimeout(function() { self.fetchState(); - document.querySelectorAll('.status-comment .comment-text a').forEach(function(i, e) { - if(i.href.startsWith(window.location.origin)) { - return; - } - let tag = i.innerText; - if(tag.startsWith('#')) { - tag = tag.substr(1); - } - i.href = '/discover/tags/'+tag+'?src=rph'; + document.querySelectorAll('.status-comment .postCommentsContainer .comment-body a').forEach(function(i, e) { + i.href = App.util.format.rewriteLinks(i); }); }, 500); }).catch(error => { @@ -1260,15 +1253,8 @@ export default { $('.postCommentsLoader').addClass('d-none'); $('.postCommentsContainer').removeClass('d-none'); setTimeout(function() { - document.querySelectorAll('.comments .comment-body a').forEach(function(i, e) { - if(i.href.startsWith(window.location.origin)) { - return; - } - let tag = i.innerText; - if(tag.startsWith('#')) { - tag = tag.substr(1); - } - i.href = '/discover/tags/'+tag+'?src=rph'; + document.querySelectorAll('.status-comment .postCommentsContainer .comment-body a').forEach(function(i, e) { + i.href = App.util.format.rewriteLinks(i); }); }, 500); }).catch(error => { diff --git a/resources/assets/js/components/RemotePost.vue b/resources/assets/js/components/RemotePost.vue index 1296a7090..35d019346 100644 --- a/resources/assets/js/components/RemotePost.vue +++ b/resources/assets/js/components/RemotePost.vue @@ -627,15 +627,8 @@ export default { }, 3000); setTimeout(function() { self.fetchState(); - document.querySelectorAll('.status-comment .comment-text a').forEach(function(i, e) { - if(i.href.startsWith(window.location.origin)) { - return; - } - let tag = i.innerText; - if(tag.startsWith('#')) { - tag = tag.substr(1); - } - i.href = '/discover/tags/'+tag+'?src=rph'; + document.querySelectorAll('.status-comment .postCommentsContainer .comment-body a').forEach(function(i, e) { + i.href = App.util.format.rewriteLinks(i); }); }, 500); }).catch(error => { @@ -977,15 +970,8 @@ export default { $('.postCommentsLoader').addClass('d-none'); $('.postCommentsContainer').removeClass('d-none'); setTimeout(function() { - document.querySelectorAll('.comments .comment-body a').forEach(function(i, e) { - if(i.href.startsWith(window.location.origin)) { - return; - } - let tag = i.innerText; - if(tag.startsWith('#')) { - tag = tag.substr(1); - } - i.href = '/discover/tags/'+tag+'?src=rph'; + document.querySelectorAll('.status-comment .postCommentsContainer .comment-body a').forEach(function(i, e) { + i.href = App.util.format.rewriteLinks(i); }); }, 500); }).catch(error => { diff --git a/resources/assets/js/components/Timeline.vue b/resources/assets/js/components/Timeline.vue index a8db2fb3d..4f3b2ba41 100644 --- a/resources/assets/js/components/Timeline.vue +++ b/resources/assets/js/components/Timeline.vue @@ -839,15 +839,8 @@ body-class="p-2 rounded"> // this.fetchStories(); this.rtw(); setTimeout(function() { - document.querySelectorAll('.caption .status-content a').forEach(function(i, e) { - if(i.href.startsWith(window.location.origin)) { - return; - } - let tag = i.innerText; - if(tag.startsWith('#')) { - tag = tag.substr(1); - } - i.href = '/discover/tags/'+tag+'?src=rph'; + document.querySelectorAll('.timeline .card-body .comments .comment-body a').forEach(function(i, e) { + i.href = App.util.format.rewriteLinks(i); }); }, 500); }).catch(err => { @@ -1004,15 +997,8 @@ body-class="p-2 rounded"> }); this.replies = _.reverse(data); setTimeout(function() { - document.querySelectorAll('.comments .comment-body a').forEach(function(i, e) { - if(i.href.startsWith(window.location.origin)) { - return; - } - let tag = i.innerText; - if(tag.startsWith('#')) { - tag = tag.substr(1); - } - i.href = '/discover/tags/'+tag+'?src=rph'; + document.querySelectorAll('.timeline .card-body .comments .comment-body a').forEach(function(i, e) { + i.href = App.util.format.rewriteLinks(i); }); }, 500); }).catch(err => {