Skip to content

Commit ba6962b

Browse files
committed
added blacklisted images and report feature
1 parent 2c5c725 commit ba6962b

File tree

5 files changed

+106
-37
lines changed

5 files changed

+106
-37
lines changed

css/styles.css

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ body {
108108
padding: 10px;
109109
}
110110

111-
.settings-link, .reload, .rate-link {
111+
.settings-link, .reload, .rate-link, .report {
112112
opacity: .5;
113113
cursor: pointer;
114114
transition: all .2s;
@@ -138,11 +138,16 @@ body {
138138
left: 10px;
139139
}
140140

141-
.reload .loader {
141+
.report {
142+
left: 45px;
143+
}
144+
145+
.reload .loader,
146+
.report .loader {
142147
font-size: 20px !important;
143148
}
144149

145-
.settings-link:hover, .reload:hover, .rate-link:hover {
150+
.settings-link:hover, .reload:hover, .rate-link:hover, .report:hover {
146151
opacity: 1;
147152
}
148153

js/json/blacklist-images.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"images": [
3+
"https://images.unsplash.com/photo-1543365915-f8b34a5e6484?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=900&ixid=eyJhcHBfaWQiOjF9&ixlib=rb-1.2.1&q=80&w=1600",
4+
"https://images.unsplash.com/photo-1574843213652-807792123391?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=900&ixid=eyJhcHBfaWQiOjF9&ixlib=rb-1.2.1&q=80&w=1600"
5+
]
6+
}

js/main.js

Lines changed: 87 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $(document).ready(function(){
99
$('[data-toggle="tooltip"]').tooltip()
1010
})
1111
load(false, true);
12-
chrome.storage.sync.get(["show_date", "date", "showed_survey_popup"], function(result){
12+
chrome.storage.sync.get(["show_date", "date", "showed_survey_popup", "showed_new_feature_report"], function(result){
1313
if(!result.hasOwnProperty("show_date") || result.show_date){
1414
const date = new Date();
1515
let currentDate = date.toLocaleDateString();
@@ -35,6 +35,19 @@ $(document).ready(function(){
3535
}
3636
})
3737
}
38+
39+
if (!result.hasOwnProperty("showed_new_feature_report") || !result.showed_new_feature_report) {
40+
Swal.fire({
41+
icon: 'info',
42+
title: 'You can now report images!',
43+
html: "If there are any images that you don't like or find inappropriate, press the <b>Report</b> icon on the top left to report these images and never show them again!",
44+
showConfirmButton: false,
45+
showCloseButton: true,
46+
onClose: function () {
47+
chrome.storage.sync.set({showed_new_feature_report: true});
48+
}
49+
})
50+
}
3851
});
3952

4053
$(".reload").click(function(){
@@ -93,7 +106,42 @@ $(document).ready(function(){
93106
} else {
94107
window.open(chrome.runtime.getURL('options.html'));
95108
}
96-
})
109+
});
110+
111+
$(".report").click(function() {
112+
Swal.fire({
113+
title: 'Report Image',
114+
html: "If you think the image is inappropriate or you don't like it, please report the image and you will not " +
115+
"see it anymore.",
116+
showConfirmButton: true,
117+
showCloseButton: true,
118+
confirmButtonText: 'Report Image',
119+
showCancelButton: true,
120+
showLoaderOnConfirm: true,
121+
preConfirm: function () {
122+
const imageElm = $(".background-image");
123+
if (imageElm.length) {
124+
return $.ajax({
125+
url: 'http://quran-extension-api.alwaysdata.net/blacklistImage',
126+
type: 'PUT',
127+
data: {image: imageElm.attr('src')},
128+
success: function (result) {
129+
return result;
130+
}
131+
});
132+
}
133+
},
134+
allowOutsideClick: () => !Swal.isLoading()
135+
}).then (function () {
136+
load(true, false);
137+
})
138+
});
139+
140+
$(".translation-container").hover(function () {
141+
$(this).children(".body").show('fast');
142+
}, function () {
143+
$(this).children(".body").hide('fast');
144+
});
97145

98146
function load(reload, withTopSites){
99147
audio = null;
@@ -112,32 +160,7 @@ $(document).ready(function(){
112160
setBackgroundImage(result.image.src);
113161
}
114162
else {
115-
let xhr = new XMLHttpRequest();
116-
117-
$.ajax({
118-
method: 'GET',
119-
url: 'https://source.unsplash.com/1600x900/?nature,mountains,landscape,animal,gradient',
120-
headers: {
121-
'Access-Control-Expose-Headers': 'ETag'
122-
},
123-
xhr: function() {
124-
return xhr;
125-
},
126-
success: function(data){
127-
setBackgroundImage(xhr.responseURL);
128-
let timeout = calculateTimeout();
129-
chrome.storage.local.set({image: {src: xhr.responseURL, timeout}});
130-
},
131-
error: function(){
132-
setBackgroundImage('/assets/offline-image.jpg');
133-
},
134-
complete: function(){
135-
if(reload){
136-
$(".reload img").show();
137-
$(".reload .loader").hide();
138-
}
139-
}
140-
});
163+
setNewImage(reload);
141164
}
142165

143166
if(result.hasOwnProperty('verse') && result.verse && now <= result.verse.timeout && !reload){
@@ -305,9 +328,40 @@ $(document).ready(function(){
305328
}
306329
}
307330

308-
$(".translation-container").hover(function () {
309-
$(this).children(".body").show('fast');
310-
}, function () {
311-
$(this).children(".body").hide('fast');
312-
});
331+
function setNewImage(reload) {
332+
let xhr = new XMLHttpRequest();
333+
$.ajax({
334+
method: 'GET',
335+
url: 'https://source.unsplash.com/1600x900/?nature,mountains,landscape,animal',
336+
headers: {
337+
'Access-Control-Expose-Headers': 'ETag'
338+
},
339+
xhr: function() {
340+
return xhr;
341+
},
342+
success: function(data){
343+
$.getJSON('http://quran-extension-api.alwaysdata.net/isImageBlacklisted?image=' + encodeURI(xhr.responseURL),
344+
function(json, textStatus) {
345+
if (json.success) {
346+
if (json.blacklisted) {
347+
setNewImage(false);
348+
} else {
349+
setBackgroundImage(xhr.responseURL);
350+
let timeout = calculateTimeout();
351+
chrome.storage.local.set({image: {src: xhr.responseURL, timeout}});
352+
}
353+
}
354+
});
355+
},
356+
error: function(){
357+
setBackgroundImage('/assets/offline-image.jpg');
358+
},
359+
complete: function(){
360+
if(reload){
361+
$(".reload img").show();
362+
$(".reload .loader").hide();
363+
}
364+
}
365+
});
366+
}
313367
});

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Quran In New Tab",
3-
"version": "1.8",
3+
"version": "1.8.1",
44
"description": "View Quran verses on the new tab page.",
55
"permissions": [
66
"storage",

newtab.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<img src="assets/reload.svg" alt="Reload" />
1515
<div class="loader"></div>
1616
</div>
17+
<div class="report" data-toggle="tooltip" title="Report Image">
18+
<img src="assets/alert-triangle.svg" alt="Report Image" />
19+
<div class="loader"></div>
20+
</div>
1721
<div class="overlay">
1822
</div>
1923
<a href="https://chrome.google.com/webstore/detail/quran-in-new-tab/hggkcijghhpkdjeokpfgbhnpecliiijg"

0 commit comments

Comments
 (0)