mirror of
https://github.com/gurnec/removeddit.git
synced 2026-03-11 08:54:27 +00:00
Added error handling
This commit is contained in:
parent
5aaacc65ea
commit
c2623432b4
6 changed files with 4062 additions and 21 deletions
|
|
@ -22,12 +22,36 @@ return {
|
|||
|
||||
error: function(msg) {
|
||||
statusImage.src = errorImg
|
||||
loadingText.innerHTML = "<b>ERROR: " + msg + "</b>"
|
||||
loadingText.innerHTML = "<b>"+msg+"</b>"
|
||||
console.error(msg)
|
||||
}
|
||||
}})()
|
||||
|
||||
|
||||
// Check browser support
|
||||
var isSupported = self.fetch && _ && self.Promise;
|
||||
|
||||
if(!isSupported) {
|
||||
console.log("isSupported",isSupported);
|
||||
|
||||
(function() {
|
||||
var isMissing = [];
|
||||
|
||||
if(!self.fetch) isMissing.push("fetch");
|
||||
if(!self.Promise) isMissing.push("promise");
|
||||
if(!_) push("lodash");
|
||||
|
||||
var url = "https://www.reddit.com/message/compose/?to=Jubbeart";
|
||||
url += "&subject="+encodeURIComponent("Missing dependencies: " + isMissing.join(" "));
|
||||
url += "&message="+encodeURIComponent("Comment (optional): ");
|
||||
url += "%0A%0A"+encodeURIComponent("Browser details: "+navigator.userAgent);
|
||||
Status.error("Error: Missing dependencies ("+isMissing+"). Contact <a href=\""+url+"\">/u/jubbeart</a>");
|
||||
})();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Reddit API
|
||||
var Reddit = (function() {
|
||||
var init = {headers: {"Authorization": ""}};
|
||||
|
|
@ -45,11 +69,21 @@ return {
|
|||
},
|
||||
method: "POST",
|
||||
body: "grant_type="+encodeURIComponent("https://oauth.reddit.com/grants/installed_client")+"&device_id=DO_NOT_TRACK_THIS_DEVICE"
|
||||
})
|
||||
.then(function(response) { return response.json() })
|
||||
})
|
||||
.then(function(response) {
|
||||
if(response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
return Promise.reject("Can't connect to Reddit API (401)");
|
||||
}
|
||||
})
|
||||
.then(function(json) {
|
||||
init.headers.Authorization = "bearer " + json.access_token;
|
||||
});
|
||||
})
|
||||
.catch(function(error) {
|
||||
return Promise.reject("Can't connect to Reddit API (402)");
|
||||
})
|
||||
|
||||
}
|
||||
}})()
|
||||
|
||||
|
|
@ -83,6 +117,8 @@ return {
|
|||
});
|
||||
},
|
||||
json: json
|
||||
|
||||
|
||||
}})()
|
||||
|
||||
var URLs = (function(){
|
||||
|
|
|
|||
3950
static/snuownd.js
Normal file
3950
static/snuownd.js
Normal file
File diff suppressed because it is too large
Load diff
1
static/subreddit.js
Normal file
1
static/subreddit.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
"use strict";
|
||||
|
|
@ -15,11 +15,17 @@ return {
|
|||
return Promise.all([
|
||||
fetch(URLs.thread, Reddit.init)
|
||||
.then(Fetch2.json)
|
||||
.then(ThreadHTML.createThread),
|
||||
.then(ThreadHTML.createThread)
|
||||
.catch(function(error) {
|
||||
return Promise.reject("Could not get thread from Reddit");
|
||||
}),
|
||||
|
||||
fetch(URLs.pushshiftIDs)
|
||||
.then(Fetch2.json)
|
||||
.then(_.property("data"))
|
||||
.then(_.property("data"))
|
||||
.catch(function(error) {
|
||||
return Promise.reject("Could not get removed comment IDs");
|
||||
}),
|
||||
])
|
||||
})
|
||||
.then(function(results) {
|
||||
|
|
@ -29,15 +35,23 @@ return {
|
|||
Status.loading("Loading comments from reddit...");
|
||||
HandleIDs.normal(thread);
|
||||
console.log("After normal", Comments.ids.length);
|
||||
return HandleIDs.morechildren();
|
||||
return HandleIDs.morechildren()
|
||||
.catch(function(error){
|
||||
return Promise.reject("Could not get comments from Reddit (moreChildren)");
|
||||
});
|
||||
})
|
||||
.then(function(){
|
||||
console.log("After morechildren", Comments.ids.length);
|
||||
return Promise.all(_.map(_.uniq(Comments.countinuethread), function(id) {
|
||||
return fetch(URLs.thread+"/_/"+id.split("_")[1], Reddit.init)
|
||||
.then(Fetch2.json)
|
||||
}));
|
||||
}).then(function(smallerThreads){
|
||||
.catch(function(error){ return Promise.reject("Could not get comments from Reddit (continueThisThread)") })
|
||||
}))
|
||||
.catch(function(error){
|
||||
return Promise.reject("Could not get comments from Reddit (continueThisThread)");
|
||||
});
|
||||
})
|
||||
.then(function(smallerThreads){
|
||||
_.forEach(smallerThreads, function(thread){
|
||||
HandleIDs.normal(thread);
|
||||
})
|
||||
|
|
@ -48,7 +62,10 @@ return {
|
|||
HandleIDs.removed();
|
||||
console.log("Removed", Comments.removed.length);
|
||||
ThreadHTML.createCommentInfo(Comments.removed.length);
|
||||
return Fetch2.multiple(URLs.format(URLs.pushshiftComments, Comments.removed), null, "data");
|
||||
return Fetch2.multiple(URLs.format(URLs.pushshiftComments, Comments.removed), null, "data")
|
||||
.catch(function(error){
|
||||
return Promise.reject("Could not get removed comments");
|
||||
});
|
||||
})
|
||||
.then(function(removedComments){
|
||||
Status.loading("Generating comments...");
|
||||
|
|
@ -56,6 +73,13 @@ return {
|
|||
})
|
||||
.then(function(){
|
||||
Status.success();
|
||||
})
|
||||
.catch(function(error) {
|
||||
if(_.includes(_.lowerCase(error), "error")) {
|
||||
Status.error(error);
|
||||
} else {
|
||||
Status.error("Error: "+error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}})()
|
||||
|
|
@ -384,4 +408,6 @@ var ThreadHTML = (function(){
|
|||
}
|
||||
})()
|
||||
|
||||
app.loadPage()
|
||||
if(isSupported) {
|
||||
app.loadPage()
|
||||
}
|
||||
30
subreddit.html
Normal file
30
subreddit.html
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Removeddit</title>
|
||||
<meta charset="utf-8">
|
||||
<meta type="description" content="Display removed and deleted comments from Reddit">
|
||||
<meta type="author" content="Jesper Wrang">
|
||||
<meta name="google-site-verification" content="Hb7-KTi33kHkzQwP9_7s5DxecMN2xFctAm3e21fu4R0" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="/static/style.css" rel="stylesheet">
|
||||
<link rel="shotcut icon" href="/static/favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<header id="header">
|
||||
<a href="/" id="header-title-link"><h1 id="header-title">Removeddit</h1></a>
|
||||
<div id="loading">
|
||||
<p id="loading-text"></p>
|
||||
<img id="loading-image" src="/static/loading.gif"></img>
|
||||
</div>
|
||||
</header>
|
||||
<div id="main"></div>
|
||||
<script src="/static/lodash.min.js"></script>
|
||||
<script src="/static/promise.min.js"></script>
|
||||
<script src="/static/fetch.js"></script>
|
||||
<script src="/static/id.js"></script>
|
||||
<script src="/static/functions.js"></script>
|
||||
<script src="/static/subreddit.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
18
thread.html
18
thread.html
|
|
@ -18,15 +18,13 @@
|
|||
<img id="loading-image" src="/static/loading.gif"></img>
|
||||
</div>
|
||||
</header>
|
||||
<div id="main">
|
||||
<div id="loading-comments" class="loading-comments"></div>
|
||||
<script src="https://cdn.rawgit.com/gamefreak/snuownd/533e8dcb/snuownd.js"></script>
|
||||
<script src="/static/lodash.min.js"></script>
|
||||
<script src="/static/promise.min.js"></script>
|
||||
<script src="/static/fetch.js"></script>
|
||||
<script src="/static/id.js"></script>
|
||||
<script src="/static/functions.js"></script>
|
||||
<script src="/static/thread.js"></script>
|
||||
</div>
|
||||
<div id="main"></div>
|
||||
<script src="/static/snuownd.js"></script>
|
||||
<script src="/static/lodash.min.js"></script>
|
||||
<script src="/static/promise.min.js"></script>
|
||||
<script src="/static/fetch.js"></script>
|
||||
<script src="/static/id.js"></script>
|
||||
<script src="/static/functions.js"></script>
|
||||
<script src="/static/thread.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in a new issue