diff --git a/extension/assets/popup.html b/extension/assets/popup.html index d9b3ebb..ee108d0 100644 --- a/extension/assets/popup.html +++ b/extension/assets/popup.html @@ -5,7 +5,7 @@ margin: 0px; padding: 0px; } - + a, .fakelink { font-family: 'Lato', sans-serif; text-decoration: none; @@ -15,27 +15,35 @@ padding: 8px; display: block !important; } - + p.fakelink { color: #999; margin: 0; } - - + + a:hover { background: #EEE; } - + hr { margin: 0; } + + .disabled { + color: #000; + background-color: #9f9; + pointer-events: none; + cursor: default; + }
+
+ Quick Blacklist Preferences Github - \ No newline at end of file + diff --git a/extension/assets/style.css b/extension/assets/style.css index 5db10c1..9b6c860 100644 --- a/extension/assets/style.css +++ b/extension/assets/style.css @@ -23,4 +23,4 @@ a.delete:hover { #clear { margin-bottom: 30px; -} \ No newline at end of file +} diff --git a/extension/js/background.js b/extension/js/background.js index 1b1d56d..83c5847 100644 --- a/extension/js/background.js +++ b/extension/js/background.js @@ -62,7 +62,7 @@ function init() { } else { window.blacklist = obj; } - + var obj = items['preferences']; if (obj === undefined) { window.preferences = {}; @@ -143,7 +143,6 @@ function handleMessage(data, sender, sendRespones) { } } - function omnibarHandler(text, suggest) { dispatchSuggestions(text, suggestionsComplete, suggest); } @@ -174,14 +173,14 @@ function suggestionsComplete(suggestions, shouldDate, suggestCb) { hour = hour.toString() + "am"; } } - + var fmt = (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getUTCFullYear().toString().substring(2,4); if (shouldDate) { description += ':: ' + escape(fmt + " " + hour) + ' '; } else { description += ':: ' + escape(fmt) + ' '; } - + description += '- ' + escape(elem.title); res.push({content:elem.url, description:description}); } @@ -197,11 +196,11 @@ function suggestionsComplete(suggestions, shouldDate, suggestCb) { function clearCache() { return; var now = +(new Date()); - + for (var time in cache) { if (now - parseInt(time) > MILLIS_BEFORE_CLEAR) { delete cache[time]; - } + } } } @@ -209,7 +208,6 @@ function escapeRegExp(str) { return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); } -// shouldArchive function shouldArchive(data) { // blacklist = {"REGEX", "PAGE", "SITE"} // custom / regex, DEFAULT_BLACKLIST @@ -323,7 +321,7 @@ function dispatchSuggestions(text, cb, suggestCb) { sorted = preloaded.slice(0, get.length - index + 1); } get = get.slice(0,index); - + chrome.storage.local.get(get, function(items) { for (var key in items) { sorted.push(items[key]); @@ -338,7 +336,7 @@ function binarySearch(arr, value, lt, gt, i, j) { if (Math.abs(j - i) <= 1) { return (i + j)/2; } - + var m = Math.floor((i + j)/2) var cmpVal = arr[m]; if (gt(cmpVal, value)) { diff --git a/extension/js/popup.js b/extension/js/popup.js index 274a079..f413a9f 100644 --- a/extension/js/popup.js +++ b/extension/js/popup.js @@ -1,5 +1,31 @@ window.addEventListener('click',function(e){ - if(e.target.href!==undefined){ + if(e.target.href!==undefined && e.target.href.length > 0){ chrome.tabs.create({url:e.target.href}) } -}); \ No newline at end of file +}); + +window.addEventListener('DOMContentLoaded', function() { + var quickBlacklist = document.getElementById('quick-blacklist'); + quickBlacklist.addEventListener('click', function() { + disableIfBlacklisted(true); + }); +}); + +function disableIfBlacklisted(add=false){ + var quickBlacklist = document.getElementById('quick-blacklist'); + chrome.storage.local.get(['blacklist'], function(items) { + chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) { + var tabUrl = tabs[0].url; + var blacklist = items['blacklist']; + if(!blacklist['SITE'].includes(tabUrl) && add){ + blacklist['SITE'].push(tabUrl) + chrome.storage.local.set({'blacklist':blacklist}); + } + if(blacklist['SITE'].includes(tabUrl)){ + quickBlacklist.classList.add('disabled'); + } + }); + }); +} + +disableIfBlacklisted(false); diff --git a/extension/js/preferences.js b/extension/js/preferences.js index c003273..b556da0 100644 --- a/extension/js/preferences.js +++ b/extension/js/preferences.js @@ -1,6 +1,6 @@ (function() { var allPageDisplay = null; - + var add = function(type, content) { var tab = document.getElementById("blacklist_tbl") var row = tab.insertRow() @@ -8,16 +8,16 @@ stringCell.innerHTML = content ? content : "" stringCell.contentEditable = true stringCell.setAttribute("placeholder", "Add a site..."); - + var typeCell = row.insertCell() var selectCell = document.createElement('select'); selectCell.innerHTML = ' \ \ ' selectCell.value = type - + typeCell.appendChild(selectCell); - + var enabledCell = row.insertCell() enabledCell.innerHTML = "" var deleteThisCell = document.createElement("a"); @@ -29,7 +29,7 @@ } enabledCell.appendChild(deleteThisCell); } - + function cutString(stringToCut) { if (stringToCut.length == 0) return "No title" @@ -37,7 +37,7 @@ return stringToCut return stringToCut.slice(0, 50) + "..." } - + function addHistoricPages(pages) { var history_table = document.getElementById("history_tbl") for(i in pages) { @@ -61,11 +61,11 @@ deletePage.appendChild(deleteButton) thisRow.appendChild(deletePage) thisRow.id = pages[i].time; - history_table.appendChild(thisRow) + history_table.appendChild(thisRow) } } - - + + function getHistory(query="") { var history_table = document.getElementById("history_tbl") history_table.innerHTML = "
" @@ -82,12 +82,12 @@ }) } - + function* nextPages(allPages){ while(true) yield allPages.splice(0, 20) } - + chrome.storage.local.get('blacklist', function(result) { var bl = result.blacklist if (Object.keys(bl).length > 0 && (bl['SITE'].length + bl['PAGE'].length + bl['REGEX'].length > 0)) { @@ -103,7 +103,7 @@ save(false); } }); - + function save(showAlert) { var showAlert = (typeof showAlert !== 'undefined') ? showAlert : true; if (showAlert) { notie.alert(4, "Saved Preferences.", 2); } @@ -115,13 +115,13 @@ indices.push(i) } } - + for (var j = indices.length-1; j > -1; j--) { tab.deleteRow(indices[j]); } - - - + + + if (tab.rows.length == 1) { chrome.runtime.sendMessage({ "msg": 'setBlacklist', @@ -137,40 +137,40 @@ for(var i = 1; i < tab.rows.length; i++) { b[tab.rows[i].cells[1].childNodes[0].value].push(tab.rows[i].cells[0].innerText) } - + chrome.runtime.sendMessage({ "msg": 'setBlacklist', "blacklist": b }) } } - + function loadMore() { addHistoricPages(allPageDisplay.next().value) } - + function clearAllData() { chrome.storage.local.clear(); notie.alert(1, 'Deleted. Restarting Falcon...', 2) setTimeout(function() { chrome.runtime.reload() - }, 2000); + }, 2000); } - + getHistory() document.getElementById("save").onclick = save; document.getElementById("add").onclick = add; document.getElementById("loadmore").onclick = loadMore; - + document.getElementById("clear").onclick = function() { notie.confirm('Are you sure you want to do that?', 'Yes', 'Cancel', function() { clearAllData() }) } - + document.getElementById("search_history").onkeyup = function () { getHistory(document.getElementById("search_history").value); } - + })();