Skip to content

Commit

Permalink
Merge pull request #51 from morris-jason/master
Browse files Browse the repository at this point in the history
Quick Blacklist feature
  • Loading branch information
andrewilyas committed Sep 26, 2016
2 parents eaf0108 + 39db72c commit fd2554e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 43 deletions.
22 changes: 15 additions & 7 deletions extension/assets/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
margin: 0px;
padding: 0px;
}

a, .fakelink {
font-family: 'Lato', sans-serif;
text-decoration: none;
Expand All @@ -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;
}
</style>
</head>
<body>
<p class="fakelink">Falcon</a>
<hr style="color: #999;" />
<hr style="color: #999;" />
<a id="quick-blacklist">Quick Blacklist</a>
<a href="preferences.html">Preferences</a>
<a href="https://github.com/lengstrom/falcon-js">Github</a>
</body>
<script type="text/javascript" src="../js/popup.js"></script>
</html>
</html>
2 changes: 1 addition & 1 deletion extension/assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ a.delete:hover {

#clear {
margin-bottom: 30px;
}
}
16 changes: 7 additions & 9 deletions extension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function init() {
} else {
window.blacklist = obj;
}

var obj = items['preferences'];
if (obj === undefined) {
window.preferences = {};
Expand Down Expand Up @@ -143,7 +143,6 @@ function handleMessage(data, sender, sendRespones) {
}
}


function omnibarHandler(text, suggest) {
dispatchSuggestions(text, suggestionsComplete, suggest);
}
Expand Down Expand Up @@ -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 += ':: <match>' + escape(fmt + " " + hour) + '</match> ';
} else {
description += ':: ' + escape(fmt) + ' ';
}

description += '- ' + escape(elem.title);
res.push({content:elem.url, description:description});
}
Expand All @@ -197,19 +196,18 @@ 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];
}
}
}
}

function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}

// shouldArchive
function shouldArchive(data) {
// blacklist = {"REGEX", "PAGE", "SITE"}
// custom / regex, DEFAULT_BLACKLIST
Expand Down Expand Up @@ -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]);
Expand All @@ -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)) {
Expand Down
30 changes: 28 additions & 2 deletions extension/js/popup.js
Original file line number Diff line number Diff line change
@@ -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})
}
});
});

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);
48 changes: 24 additions & 24 deletions extension/js/preferences.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
(function() {
var allPageDisplay = null;

var add = function(type, content) {
var tab = document.getElementById("blacklist_tbl")
var row = tab.insertRow()
var stringCell = row.insertCell()
stringCell.innerHTML = content ? content : ""
stringCell.contentEditable = true
stringCell.setAttribute("placeholder", "Add a site...");

var typeCell = row.insertCell()
var selectCell = document.createElement('select');
selectCell.innerHTML = '<option value="PAGE">Specific Page</option> \
<option value="SITE">Entire Website</option> \
<option value="REGEX">Regex</option>'
selectCell.value = type

typeCell.appendChild(selectCell);

var enabledCell = row.insertCell()
enabledCell.innerHTML = "<input type='checkbox' checked></input>"
var deleteThisCell = document.createElement("a");
Expand All @@ -29,15 +29,15 @@
}
enabledCell.appendChild(deleteThisCell);
}

function cutString(stringToCut) {
if (stringToCut.length == 0)
return "<em>No title</em>"
if (stringToCut.length <= 50)
return stringToCut
return stringToCut.slice(0, 50) + "..."
}

function addHistoricPages(pages) {
var history_table = document.getElementById("history_tbl")
for(i in pages) {
Expand All @@ -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 = "<table class='ui table' id='history_tbl'></table>"
Expand All @@ -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)) {
Expand All @@ -103,7 +103,7 @@
save(false);
}
});

function save(showAlert) {
var showAlert = (typeof showAlert !== 'undefined') ? showAlert : true;
if (showAlert) { notie.alert(4, "Saved Preferences.", 2); }
Expand All @@ -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',
Expand All @@ -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);
}


})();

0 comments on commit fd2554e

Please sign in to comment.