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

View File

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

View File

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