forked from hsbakshi/reddit-check
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
90 lines (81 loc) · 2.57 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const { PopupResults } = require('./js/react-components/popup_results');
const url_utils = require('./js/URL_utils');
// parse json data
function parsePosts(globalPage, tab) {
const url = tab.url;
const encodedUrl = encodeURIComponent(url);
const redditPosts = lscache.get(URL_STORAGE_KEY + url);
if (redditPosts != null && redditPosts != []) {
$("div#timeout").hide(0);
const listing = SubmissionCollectionLscache.get(url);
if (listing.length > 0) {
makeDisplay(listing);
}
} else {
// redditPosts can be empty if the entry expired in lscache
globalPage.getURLInfo(tab)
.then(function(listing) {
$("div#timeout").hide(0);
return listing;
})
.then(function(listing) {
if (listing.length > 0) {
makeDisplay(listing);
}
});
}
renderThreddSubreddit(encodedUrl);
}
function renderThreddSubreddit(encodedUrl) {
ReactDOM.render(
React.createElement(GenericCallToAction, {
button_description: "Share your feedback and keep up-to-date with Thredd's development!",
button_text: 'Join r/Thredd',
href: 'https://www.reddit.com/r/Thredd'
}), document.getElementById('create-post'));
}
function renderPopupMenu() {
ReactDOM.render(
React.createElement(PopupMenu, {}),
document.getElementById('popup-menu'));
}
function makeDisplay(redditPosts) {
ReactDOM.render(
React.createElement(PopupResults, {
posts: redditPosts
}), document.getElementById('links'));
}
function buildCommentUrl(permalink) {
var uri = new URI("comment.html")
var query = {
'id': permalink.id,
'num_comments': permalink.num_comments
}
return uri.search(query);
}
global.buildCommentUrl = buildCommentUrl;
chrome.runtime.getBackgroundPage(function (global) {
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
let tab = tabs[0];
url_utils.getTabUrl(function(url) {
const fake_tab = {
url:url,
id: tab.id
};
isBlacklisted(fake_tab,
function(input) {
$("div#blacklisted").show(0)
$("div#timeout").hide(0);
},
function (input) {
$("div#blacklisted").hide(0)
parsePosts(global, fake_tab)
});
});
});
});
renderPopupMenu();
lscache.set('trigger_notification', false, 5);