mirror of
https://github.com/gurnec/removeddit.git
synced 2026-03-11 08:54:27 +00:00
Removed unnecessary connection to the Reddit API for subreddits
This commit is contained in:
parent
f882169e2a
commit
f2da0c27ba
4 changed files with 151 additions and 15 deletions
|
|
@ -1,4 +1,8 @@
|
|||
extends base.pug
|
||||
|
||||
block main
|
||||
h1 Comming soon
|
||||
block vars
|
||||
- var script = true
|
||||
|
||||
append script
|
||||
script(src='/static/js/libraries/js.cookie.js')
|
||||
script(src='/static/js/search.js')
|
||||
|
|
@ -17,7 +17,14 @@
|
|||
</div>
|
||||
</header>
|
||||
<div id="main">
|
||||
<h1>Comming soon</h1>
|
||||
</div>
|
||||
<script src="/static/js/libraries/snuownd.js"></script>
|
||||
<script src="/static/js/libraries/lodash.min.js"></script>
|
||||
<script src="/static/js/polyfills/promise.min.js"></script>
|
||||
<script src="/static/js/polyfills/fetch.js"></script>
|
||||
<script src="/static/js/id.js"></script>
|
||||
<script src="/static/js/functions.js"></script>
|
||||
<script src="/static/js/libraries/js.cookie.js"></script>
|
||||
<script src="/static/js/search.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
128
static/js/search.js
Normal file
128
static/js/search.js
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
var app = (function(){
|
||||
return {
|
||||
loadPage: function(){
|
||||
|
||||
SearchHTML.createSearch();
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
/*
|
||||
|
||||
Comments:
|
||||
comment body (body) string
|
||||
sort (sort) asc,desc
|
||||
author (author) string
|
||||
subreddit (subreddit) string
|
||||
between (after/before) "date"
|
||||
|
||||
|
||||
Thread:
|
||||
title (title) string
|
||||
selftext (body) string
|
||||
sort (sort) asc,desc
|
||||
author (author) string
|
||||
subreddit (subreddit) string
|
||||
between (after/before) "date"
|
||||
over_18 (over_18) sfw,nsfw,both
|
||||
locked (locked) bool
|
||||
|
||||
*/
|
||||
|
||||
var ElasticSearch = (function(){
|
||||
return {
|
||||
comment: function(){
|
||||
|
||||
},
|
||||
thread: function(){
|
||||
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
var Vars = (function(){
|
||||
var lookup = {};
|
||||
var keys = [];
|
||||
var defaults = [];
|
||||
|
||||
return {
|
||||
loadVars: function(){
|
||||
|
||||
},
|
||||
get: function(key){
|
||||
return lookup[key];
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
var SearchHTML = (function(){
|
||||
var mainDiv = document.getElementById("main");
|
||||
|
||||
var createRadioInput = function(name, displayNames, values, defaultValue) {
|
||||
var inputs = "";
|
||||
|
||||
for(var i = 0, len = displayNames.length; i < len; i++){
|
||||
inputs += '<input type="radio" id="'+name+i+'" name="'+name+'" ';
|
||||
inputs += 'value="'+values[i]+'" '+(defaultValue === values[i] ? 'checked':'')+' >';
|
||||
inputs += '<label for="'+name+i+'">'+displayNames[i]+'</label>';
|
||||
}
|
||||
return inputs;
|
||||
};
|
||||
|
||||
var inputRow = function(text, input) {
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
createSearch: function(){
|
||||
var searchBox = document.createElement("div");
|
||||
searchBox.id = "searchBox";
|
||||
|
||||
var showAdvanced = _.defaultTo(Cookies.get("showAdvanced"), true);
|
||||
var searchThread = _.defaultTo(Cookies.get("searchThread"), true);
|
||||
/*
|
||||
Thread:
|
||||
title (title) string *
|
||||
selftext (body) string *
|
||||
sort (sort) asc,desc *
|
||||
author (author) string *
|
||||
subreddit (subreddit) string *
|
||||
between (after/before) "date"
|
||||
over_18 (over_18) sfw,nsfw,both *
|
||||
locked (locked) bool *
|
||||
*/
|
||||
var html = 'Im looking for: ';
|
||||
html += '<input type="radio" id="threadSearch" name="search" value="thread"'+(searchThread ? ' checked ':'')+'><label for="threadSearch">Thread</label>';
|
||||
html += '<input type="radio" id="commentSearch" name="search" value="comment"'+(!searchThread ? ' checked ':'')+'><label for="commentSearch">Comment</label>';
|
||||
html += '<label for="title">Title: </label><input type="text" id="title" name="title">';
|
||||
html += '<label for="threadBody">Selftext: </label><input type="text" id="threadBody" name="body">';
|
||||
html += '<label for="threadSubreddit">Subreddit: </label><input type="text" id="threadSubreddit" name="subreddit">';
|
||||
html += '<label for="threadAuthor">Author: </label><input type="text" id="threadAuthor" name="author">';
|
||||
html += 'Posted between time < time &l time';
|
||||
html += "Over 18: ";
|
||||
html += createRadioInput("over_18", ["Both","nsfw","sfw"], ["both","nsfw","sfw"], _.defaultTo(GetVars.get("over_18"), "both"));
|
||||
html += "Locked: ";
|
||||
html += createRadioInput("locked", ["Both","True", "False"], ["both","true","false"], _.defaultTo(GetVars.get("locked"), "both"));
|
||||
html += "Sort score: ";
|
||||
html += createRadioInput("sort", ["Highest","Lowest"], ["desc","asc"], _.defaultTo(GetVars.get("sort"), "desc"));
|
||||
searchBox.innerHTML = html;
|
||||
|
||||
mainDiv.appendChild(searchBox);
|
||||
},
|
||||
|
||||
commentResults: function(){
|
||||
|
||||
},
|
||||
|
||||
threadResults: function(){
|
||||
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
if(isSupported) {
|
||||
app.loadPage();
|
||||
}
|
||||
|
|
@ -16,12 +16,9 @@ return {
|
|||
var timeDifference = Time.difference(Time.toUTC(Vars.getTime()));
|
||||
SubredditHTML.createInfo(Reddit.subreddit, Vars.getTime());
|
||||
|
||||
Reddit.fetchToken()
|
||||
.then(function(){
|
||||
return fetch(ElasticSearch.subreddit(Reddit.subreddit, timeDifference, Vars.getPage()))
|
||||
.catch(function(error){
|
||||
fetch(ElasticSearch.subreddit(Reddit.subreddit, timeDifference, Vars.getPage()))
|
||||
.catch(function(error){
|
||||
return Promise.reject("Could not get removed posts");
|
||||
});
|
||||
})
|
||||
.then(function(response){
|
||||
if(response.ok) {
|
||||
|
|
@ -33,7 +30,7 @@ return {
|
|||
.then(Fetch2.json)
|
||||
.then(function(json){
|
||||
var sourceArray = json.hits.hits;
|
||||
var pageNr = (Vars.getPage() - 1) * 25 + 1;
|
||||
var pageNr = (Vars.getPage() - 1) * Vars.postPerPage + 1;
|
||||
for(var i = 0, len = sourceArray.length; i < len; i++) {
|
||||
SubredditHTML.createThread(sourceArray[i]._source, pageNr+i);
|
||||
}
|
||||
|
|
@ -57,6 +54,7 @@ var Vars = (function(){
|
|||
var page;
|
||||
|
||||
return {
|
||||
postPerPage: 50,
|
||||
isAll: _.toLower(Reddit.subreddit) === 'all',
|
||||
loadTime: function(){
|
||||
var tmpTime = _.defaultTo(GetVars.get("t"), Cookies.get("t"));
|
||||
|
|
@ -110,15 +108,15 @@ return {
|
|||
'},'+
|
||||
'"_source":["author","url","subreddit","link_flair_text","score","title","created_utc","selftext","num_comments","domain","permalink","id","thumbnail","thumbnail_height","thumbnail_width"],'+
|
||||
'"sort":[{"score":"desc"}],'+
|
||||
'"from":'+(page-1)*25+','+
|
||||
'"size":25}';
|
||||
'"from":'+(page-1)*Vars.postPerPage+','+
|
||||
'"size":'+Vars.postPerPage+'}';
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
var SubredditHTML = (function(){
|
||||
var mainDiv = document.getElementById("main");
|
||||
return {
|
||||
return {
|
||||
createThread: function(thread, postRank) {
|
||||
var threadDiv = document.createElement("div");
|
||||
threadDiv.className = "thread";
|
||||
|
|
@ -172,7 +170,6 @@ return {
|
|||
infoDiv.className = "subreddit-info";
|
||||
infoDiv.innerHTML = 'top post of <a href="https://www.reddit.com/r/'+subreddit+'">/r/'+subreddit+'</a> from:';
|
||||
|
||||
|
||||
var values = ["hour", "12hour", "day", "week", "month", "6month", "year", "all"];
|
||||
var display = ["past hour", "past 12 hours", "past day", "past week", "past month", "past 6 months", "past year", "all time"];
|
||||
var options = "";
|
||||
|
|
@ -196,7 +193,7 @@ return {
|
|||
pagination.id = "pagination";
|
||||
|
||||
var start = Math.max(Vars.getPage()-3, 1);
|
||||
var end = Math.min(start + 9, Math.ceil(totalPosts/25));
|
||||
var end = Math.min(start + 9, Math.ceil(totalPosts/Vars.postPerPage));
|
||||
var links = "Page: ";
|
||||
var hrefBase = document.location.href.split("?")[0] + "?t=" + Vars.getTime() + "&page=";
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue