Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ key.pem
build/*
/build
.settings
node_modules/
node_modules/
todo.md
33 changes: 33 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,39 @@ function saveOptions(o) {
}
}

// This does not require "permissions":["tabs"] becuase it only acts on its
// current tab.
chrome.contextMenus.create({
title:"Add site to SA blacklist",
contexts:["all"],
type:"normal",
onclick:function(info, tab) {
// 'document.location.hostname' here is a string containing our app ID.
// info.pageUrl and tab.url are both the full URL of this page, we only
// want the hostname, so use a dummy object (instead of requiring another
// library to parse the URL)
var dummy = document.createElement('a')
dummy.href = tab.url

// Use dummy.hostname for now; If @davidparsson agrees on issue #68, then
// this should change to use dummy.host as well.
blacklist = localStorage["blacklist"].split('\n')

for (var i = blacklist.length - 1; i >= 0; i--) {
var blacklistEntry = blacklist[i].trim();
if (dummy.hostname === blacklistEntry) {
// no need to check subdomains when adding to list
console.log(dummy.hostname,'already in blacklist')
return
}
}
console.log('pushing',dummy.hostname,'to blacklist')
blacklist.push(dummy.hostname)
localStorage['blacklist'] = blacklist.join('\n')
saveOptions({o:'blacklist'})
}
})

// Inject content script into all existing tabs (doesn't work)
// This functionality requires
// "permissions": ["tabs"]
Expand Down
3 changes: 3 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"background": {
"scripts": ["background.js"]
},
"permissions": [
"contextMenus"
],
"options_page": "options.html",
"manifest_version": 2,
"minimum_chrome_version": "49"
Expand Down