Fix URL blacklist

This commit is contained in:
Les De Ridder 2016-05-05 15:43:37 +02:00
parent ade0fa186e
commit 289a0a050e
3 changed files with 38 additions and 18 deletions

View File

@ -29,23 +29,23 @@ function copyToClipboard(url) {
document.execCommand('Copy', false, null);
}
var blacklist = ["pomf.", "mixtape.moe", "catgirlsare.sexy", "cocaine.ninja", "p.fuwafuwa.moe", "/wiki/"];
chrome.pageAction.onClicked.addListener(function(tab) {
getCurrentTabUrl(function(url) {
getBetterUrl(url, function(betterUrl) {
var filename = betterUrl.substr(betterUrl.lastIndexOf("/"));
filename = cleanExtension(filename);
chrome.storage.sync.get({url: '', tabbehaviour: '', copytoclipboard: false, replacebookmark: false, disableurlblacklist: false}, function(config) {
chrome.storage.sync.get({url: '', tabbehaviour: '', copytoclipboard: false, replacebookmark: false, disableblacklist: false}, function(config) {
if(config.url == '') {
alert("Please select a Pomf clone.");
chrome.tabs.create({ url: "options.html" });
return;
}
var blackList = ["pomf.", "mixtape.moe", "catgirlsare.sexy", "cocaine.ninja", "p.fuwafuwa.moe"];
if(!config.disableblacklist) {
for(black of blackList) {
for(black of blacklist) {
if(url.indexOf(black) != -1) {
return;
}
@ -135,7 +135,7 @@ function isInstagramUrl(url) {
return url.indexOf('instagram.com/p') != -1;
}
function isCoolUrl(url) {
function isCoolUrl(url, callback) {
url = url.toLowerCase();
var extensionIndex = url.lastIndexOf('.');
@ -143,22 +143,41 @@ function isCoolUrl(url) {
var validExtensions = ["jpg", "jpeg", "png", "gif", "webm", "gifv", "mp4", "mp3", "ogg", "opus"];
return validExtensions.indexOf(extension) != -1 || isInstagramUrl(url);
chrome.storage.sync.get({ disableblacklist: false }, function(config) {
if(!config.disableblacklist) {
for(black of blacklist) {
if(url.indexOf(black) != -1) {
return false;
}
}
} else {
console.log('blacklist disabled!');
}
callback(validExtensions.indexOf(extension) != -1 || isInstagramUrl(url));
});
}
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(isCoolUrl(tab.url) && tab.active)
{
chrome.pageAction.show(tabId);
if(tab.active) {
getBetterUrl(tab.url, function(betterUrl) {
isCoolUrl(betterUrl, function (cool) {
if(cool) {
chrome.pageAction.show(tabId);
}
});
});
}
});
chrome.tabs.onActivated.addListener(function(activeInfo) {
chrome.tabs.get(activeInfo.tabId, function(tab) {
getBetterUrl(tab.url, function(betterUrl) {
if(isCoolUrl(betterUrl)) {
chrome.pageAction.show(activeInfo.tabId);
}
})
isCoolUrl(betterUrl, function(cool) {
if (cool) {
chrome.pageAction.show(activeInfo.tabId);
}
});
});
});
});

View File

@ -39,7 +39,7 @@
<br />
<br />
<input type="checkbox" id="disableurlblacklist"> Disable URL blacklist<br />
<input type="checkbox" id="disableblacklist"> Disable URL blacklist<br />
<br />
<br />

View File

@ -29,7 +29,7 @@ function saveOptions() {
var tabbehaviour = document.querySelector('input[name="tabbehaviour"]:checked').value;
var copytoclipboard = document.getElementById('copytoclipboard').checked;
var replacebookmark = document.getElementById('replacebookmark').checked;
var disableurlblacklist = document.getElementById('disableurlblacklist').checked;
var disableblacklist = document.getElementById('disableblacklist').checked;
chrome.storage.sync.set({
pomfclone: pomfclone,
@ -38,7 +38,7 @@ function saveOptions() {
tabbehaviour: tabbehaviour,
copytoclipboard: copytoclipboard,
replacebookmark: replacebookmark,
disableurlblacklist: disableurlblacklist
disableblacklist: disableblacklist
}, function() {
var status = document.getElementById('status');
status.textContent = 'Options saved.';
@ -57,7 +57,8 @@ function restoreOptions() {
customUrl: '',
tabbehaviour: document.querySelector('input[name="tabbehaviour"]:checked').value,
copytoclipboard: false,
replacebookmark: false
replacebookmark: false,
disableblacklist: false
}, function(config) {
document.getElementById('pomfclone').value = config.pomfclone;
document.getElementById('urlbox').value = config.url;
@ -69,7 +70,7 @@ function restoreOptions() {
document.getElementById('copytoclipboard').checked = config.copytoclipboard;
document.getElementById('replacebookmark').checked = config.replacebookmark;
document.getElementById('disableurlblacklist').checked = config.disableurlblacklist;
document.getElementById('disableblacklist').checked = config.disableblacklist;
});
document.getElementById('status').textContent = '';