Fixed tracking noscript and removed reddit library
This commit is contained in:
parent
c239f71c3e
commit
61749d6a06
4 changed files with 34 additions and 29 deletions
|
|
@ -25,7 +25,6 @@
|
|||
<div class="panel-group"><div class="noscript">Please enable Javascript and disable any adblocker to view comments.</div></div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="../js/reddit.min.js"></script>
|
||||
<script src="../js/snuownd.min.js"></script>
|
||||
<script>var redditid = '{{ page.commentsid }}';</script>
|
||||
<script src="../js/snuownd.min.js"></script>
|
||||
<script src="../js/promisepage.js"></script>
|
||||
|
|
@ -28,6 +28,7 @@ hr
|
|||
|
||||
.noscript
|
||||
color: #d9534f
|
||||
display: none
|
||||
font-weight: bold
|
||||
|
||||
.placecomment
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
function renderComment(reddit, reply = false) {
|
||||
if(reply) {
|
||||
comment = "<div class='panel panel-default replycomment'><div class='panel-body'><i class='fa reply fa-reply' aria-hidden='true'></i> ";
|
||||
}
|
||||
else {
|
||||
comment = "<div class='panel panel-default'><div class='panel-body'>";
|
||||
}
|
||||
if (reply) {
|
||||
comment = "<div class='panel panel-default replycomment'><div class='panel-body'><i class='fa reply fa-reply' aria-hidden='true'></i> ";
|
||||
} else {
|
||||
comment = "<div class='panel panel-default'><div class='panel-body'>";
|
||||
}
|
||||
if (reddit.data.distinguished != null) {
|
||||
comment += "<i class='fa fa-check-square-o check' aria-hidden='true'></i> ";
|
||||
}
|
||||
|
|
@ -24,30 +23,35 @@ function renderComment(reddit, reply = false) {
|
|||
if (reddit.data.edited != false) {
|
||||
comment += "*";
|
||||
}
|
||||
comment += " <a target='_blank' href='https://reddit.com/r/trumptracker/comments/" + reddit.data.link_id.replace("t3_", "") + "/trumptracker/" + reddit.data.id + "/'><i class='fa fa-share-alt' aria-hidden='true'></i></a> <hr>" + SnuOwnd.getParser().render(reddit.data.body.replace(/(<([^>]+)>)/ig,""));
|
||||
comment += " <a target='_blank' href='https://reddit.com/r/trumptracker/comments/" + reddit.data.link_id.replace("t3_", "") + "/trumptracker/" + reddit.data.id + "/'><i class='fa fa-share-alt' aria-hidden='true'></i></a> <hr>" + SnuOwnd.getParser().render(reddit.data.body.replace(/(<([^>]+)>)/ig, ""));
|
||||
if (reddit.data.archived != false) {
|
||||
comment += " <i class='fa fa-archive archive' aria-hidden='true'></i>";
|
||||
}
|
||||
comment += "</div></div>";
|
||||
comment += "</div></div>";
|
||||
return comment;
|
||||
}
|
||||
|
||||
var nocomments = true;
|
||||
|
||||
function loopComments(reddit, reply = false) {
|
||||
if (!reply) {
|
||||
$.each(reddit, function(i, data) {
|
||||
$.each(data, function(i, d) {
|
||||
$.each(d.children, function(i, e) {
|
||||
$(".loader").hide();
|
||||
$(".panel-group").append(renderComment(e));
|
||||
if (e.data.replies != '') {
|
||||
loopComments(e.data.replies, true);
|
||||
}
|
||||
});
|
||||
if (d.hasOwnProperty("children")) {
|
||||
$.each(d.children, function(i, e) {
|
||||
nocomments = false;
|
||||
$(".loader").hide();
|
||||
$(".panel-group").append(renderComment(e));
|
||||
if (e.data.replies != '') {
|
||||
loopComments(e.data.replies, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
$.each(reddit.data.children, function(i, e) {
|
||||
$(".panel-group").append(renderComment(e,true));
|
||||
$(".panel-group").append(renderComment(e, true));
|
||||
if (e.data.replies != '') {
|
||||
loopComments(e.data.replies, true);
|
||||
}
|
||||
|
|
@ -55,20 +59,22 @@ function loopComments(reddit, reply = false) {
|
|||
}
|
||||
}
|
||||
|
||||
if(document.location.href.indexOf("?reddit") !== -1) {
|
||||
document.location = 'https://redd.it/' + redditid;
|
||||
if (document.location.href.indexOf("?reddit") !== -1) {
|
||||
document.location = 'https://redd.it/' + redditid;
|
||||
}
|
||||
|
||||
document.getElementsByClassName("loader")[0].style.display = 'block';
|
||||
document.getElementsByClassName("noscript")[0].outerHTML='';
|
||||
|
||||
window.addEventListener('load', function() {
|
||||
reddit.comments(redditid, "trumptracker").limit(20).sort("hot").fetch(function(res) {
|
||||
$.get("http://www.reddit.com/r/trumptracker/comments/" + redditid + ".json", function(res) {
|
||||
res.shift();
|
||||
loopComments(res);
|
||||
if ($(".panel-group").html().indexOf('<div class="panel ')) {
|
||||
$(".loader").hide();
|
||||
$("#reddit_comments").append("<h4>There are no comments yet</h4>");
|
||||
}
|
||||
setTimeout(function() {
|
||||
if (nocomments) {
|
||||
$(".loader").hide();
|
||||
$("#reddit_comments").append("<h4>There are no comments yet</h4>");
|
||||
}
|
||||
}, 500);
|
||||
}).fail(function() {
|
||||
$(".loader").hide();
|
||||
$(".noscript").show();
|
||||
});
|
||||
});
|
||||
1
js/reddit.min.js
vendored
1
js/reddit.min.js
vendored
|
|
@ -1 +0,0 @@
|
|||
!function(window){"use strict";function listing(on,extras){return extras=extras||[],withFilters(on,["after","before","count","limit","show"].concat(extras))}function fetch(on){return{fetch:function(res,err){getJSON(redditUrl(on),res,err)}}}function withFilters(on,filters){var ret={};on.params=on.params||{},filters=filters||[];for(var without=function(object,key){var ret={};for(var prop in object)object.hasOwnProperty(prop)&&prop!==key&&(ret[prop]=object[prop]);return ret},filter=function(f){return"show"===f?function(){return on.params[f]="all",without(this,f)}:function(arg){return on.params[f]=arg,without(this,f)}},i=0;i<filters.length;i++)ret[filters[i]]=filter(filters[i]);return ret.fetch=function(res,err){getJSON(redditUrl(on),res,err)},ret}function redditUrl(on){var url="https://www.reddit.com/",keys=function(object){var ret=[];for(var prop in object)object.hasOwnProperty(prop)&&ret.push(prop);return ret};if(void 0!==on.subreddit&&(url+="r/"+on.subreddit+"/"),url+=on.resource+".json",keys(on.params).length>0){var qs=[];for(var param in on.params)on.params.hasOwnProperty(param)&&qs.push(encodeURIComponent(param)+"="+encodeURIComponent(on.params[param]));url+="?"+qs.join("&")}return url}function getJSON(url,res,err){get(url,function(data){res(JSON.parse(data))},err)}function get(url,res,err){var xhr=new XMLHttpRequest;xhr.open("GET",url,!0),xhr.onload=function(){return res(xhr.response)},xhr.onerror=function(){return void 0!==err?err(xhr.response):void 0},xhr.send()}var reddit=window.reddit={};reddit.hot=function(subreddit){return listing({subreddit:subreddit,resource:"hot"})},reddit.top=function(subreddit){return listing({subreddit:subreddit,resource:"top"},["t"])},reddit.controversial=function(subreddit){return listing({subreddit:subreddit,resource:"controversial"},["t"])},reddit.new=function(subreddit){return listing({subreddit:subreddit,resource:"new"})},reddit.about=function(subreddit){return fetch({subreddit:subreddit,resource:"about"})},reddit.random=function(subreddit){return fetch({subreddit:subreddit,resource:"random"})},reddit.info=function(subreddit){var on={subreddit:subreddit,resource:"api/info"};return withFilters(on,["id","limit","url"])},reddit.comments=function(article,subreddit){var on={subreddit:subreddit,resource:"comments/"+article};return withFilters(on,["comment","context","depth","limit","sort"])},reddit.recommendedSubreddits=function(srnames){var on={resource:"api/recommend/sr/"+srnames};return withFilters(on,["omit"])},reddit.subredditsByTopic=function(query){var on={resource:"api/subreddits_by_topic",params:{query:query}};return fetch(on)},reddit.search=function(query,subreddit){var on={subreddit:subreddit,resource:"search",params:{q:query}};return withFilters(on,["after","before","count","limit","restrict_sr","show","sort","syntax","t"])},reddit.searchSubreddits=function(query){return listing({resource:"subreddits/search",params:{q:query}})},reddit.popularSubreddits=function(){return listing({resource:"subreddits/popular"})},reddit.newSubreddits=function(){return listing({resource:"subreddits/new"})},reddit.aboutUser=function(username){return fetch({resource:"user/"+username+"/about"})}}(window);
|
||||
Loading…
Add table
Add a link
Reference in a new issue