mirror of
https://github.com/Hopiu/RandomWallpaperGnome3.git
synced 2026-03-16 22:20:24 +00:00
fix indentation
This commit is contained in:
parent
80de7a5728
commit
92f0b44e54
1 changed files with 18 additions and 18 deletions
|
|
@ -367,35 +367,35 @@ var RedditAdapter = new Lang.Class({
|
|||
requestRandomImage: function (callback) {
|
||||
let session = new Soup.SessionAsync();
|
||||
|
||||
const subreddits = this._settings.get('subreddits', 'string').split(',').map(s => s.trim()).join('+');
|
||||
const require_sfw = this._settings.get('allow-sfw', 'boolean');
|
||||
const url = encodeURI(`https://www.reddit.com/r/${subreddits}.json`);
|
||||
const subreddits = this._settings.get('subreddits', 'string').split(',').map(s => s.trim()).join('+');
|
||||
const require_sfw = this._settings.get('allow-sfw', 'boolean');
|
||||
const url = encodeURI(`https://www.reddit.com/r/${subreddits}.json`);
|
||||
|
||||
let message = Soup.Message.new('GET', url);
|
||||
|
||||
if (message === null) {
|
||||
this._error("Could not create request.", callback);
|
||||
return;
|
||||
this._error("Could not create request.", callback);
|
||||
return;
|
||||
}
|
||||
|
||||
session.queue_message(message, (session, message) => {
|
||||
try {
|
||||
const submissions = JSON.parse(message.response_body.data).data.children.filter(child => {
|
||||
if(child.data.post_hint !== 'image') return false;
|
||||
if(require_sfw) return child.data.over_18 === false;
|
||||
return true;
|
||||
});
|
||||
if(submissions.length === 0) {
|
||||
this._error("No suitable submissions found!", callback);
|
||||
return;
|
||||
}
|
||||
const random = Math.floor(Math.random() * submissions.length);
|
||||
const submission = submissions[random].data;
|
||||
const imageDownloadUrl = submission.preview.images[0].source.url;
|
||||
const submissions = JSON.parse(message.response_body.data).data.children.filter(child => {
|
||||
if(child.data.post_hint !== 'image') return false;
|
||||
if(require_sfw) return child.data.over_18 === false;
|
||||
return true;
|
||||
});
|
||||
if(submissions.length === 0) {
|
||||
this._error("No suitable submissions found!", callback);
|
||||
return;
|
||||
}
|
||||
const random = Math.floor(Math.random() * submissions.length);
|
||||
const submission = submissions[random].data;
|
||||
const imageDownloadUrl = submission.preview.images[0].source.url;
|
||||
|
||||
if (callback) {
|
||||
let historyEntry = new HistoryModule.HistoryEntry(null, 'reddit', imageDownloadUrl);
|
||||
historyEntry.source.sourceUrl = 'https://www.reddit.com/' + submission.permalink;
|
||||
historyEntry.source.sourceUrl = 'https://www.reddit.com/' + submission.permalink;
|
||||
callback(historyEntry);
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue