From 289a0a050ebc248a95ac3da3a3a2b43115db86d5 Mon Sep 17 00:00:00 2001 From: Les De Ridder Date: Thu, 5 May 2016 15:43:37 +0200 Subject: [PATCH] Fix URL blacklist --- background.js | 45 ++++++++++++++++++++++++++++++++------------- options.html | 2 +- options.js | 9 +++++---- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/background.js b/background.js index ef87805..fd129f1 100644 --- a/background.js +++ b/background.js @@ -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); + } + }); + }); }); }); diff --git a/options.html b/options.html index f017890..47c78b2 100644 --- a/options.html +++ b/options.html @@ -39,7 +39,7 @@

- Disable URL blacklist
+ Disable URL blacklist


diff --git a/options.js b/options.js index 46221cf..1024486 100644 --- a/options.js +++ b/options.js @@ -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 = '';