+ initial commit
This commit is contained in:
commit
45b9c4c4b7
BIN
gplusblacklist.crx
Normal file
BIN
gplusblacklist.crx
Normal file
Binary file not shown.
BIN
gplusblacklist.png
Normal file
BIN
gplusblacklist.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
gplusblacklist_screenshot.png
Normal file
BIN
gplusblacklist_screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
7
src/background.js
Normal file
7
src/background.js
Normal file
@ -0,0 +1,7 @@
|
||||
chrome.extension.onRequest.addListener(
|
||||
function(request, sender, sendResponse) {
|
||||
if (request.method == "getBlacklist") {
|
||||
sendResponse({blacklist: JSON.parse(localStorage["blacklist"])});
|
||||
}
|
||||
}
|
||||
);
|
72
src/content.js
Normal file
72
src/content.js
Normal file
@ -0,0 +1,72 @@
|
||||
blacklistFilter = function(blacklist) {
|
||||
if (blacklist) {
|
||||
var nodes = document.getElementsByClassName("Tg");
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var hideBtn = nodes[i].getElementsByClassName("hidden");
|
||||
if (hideBtn[0]) {
|
||||
var contents = nodes[i].getElementsByClassName("qf");
|
||||
if (contents[0]) {
|
||||
contents[0].style.display = "block";
|
||||
}
|
||||
nodes[i].removeChild(hideBtn[0]);
|
||||
}
|
||||
for (var j = 0; j < blacklist.length; j++) {
|
||||
if (nodes[i].innerHTML.toLowerCase().indexOf(blacklist[j].toLowerCase()) != -1) {
|
||||
var contents = nodes[i].getElementsByClassName("qf");
|
||||
if (contents[0]) {
|
||||
contents[0].style.display = "none";
|
||||
}
|
||||
|
||||
var newdiv = document.createElement("div");
|
||||
newdiv.setAttribute("id", "blacklist_item_" + i);
|
||||
newdiv.setAttribute("class", "hidden");
|
||||
newdiv.innerHTML = "Hidden: \"" + blacklist[j] + "\"";
|
||||
|
||||
var newbtn = document.createElement("input");
|
||||
newbtn.setAttribute("type", "button");
|
||||
newbtn.setAttribute("id", "blacklist_btn_" + i);
|
||||
newbtn.setAttribute("value", "Unhide");
|
||||
newbtn.removeId = i;
|
||||
removeFunc = function(event) {
|
||||
var hiddenContents = nodes[event.target.removeId].getElementsByClassName("qf");
|
||||
hiddenContents[0].style.display = "block";
|
||||
var unhideBtn = nodes[event.target.removeId].getElementsByClassName("hidden")[0];
|
||||
|
||||
nodes[event.target.removeId].removeChild(unhideBtn);
|
||||
}
|
||||
newbtn.addEventListener("click", removeFunc, false);
|
||||
newdiv.appendChild(newbtn);
|
||||
|
||||
nodes[i].appendChild(newdiv);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
blacklist = function() {
|
||||
chrome.extension.sendRequest({method: "getBlacklist"}, function(response) {
|
||||
if (response.blacklist) {
|
||||
blacklistFilter(response.blacklist);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
chrome.extension.onMessage.addListener(function (request, sender, sendResponse) {
|
||||
blacklistFilter(request.blacklist);
|
||||
});
|
||||
|
||||
blacklist();
|
||||
document.getElementsByClassName("ow")[0].addEventListener("DOMNodeInserted",
|
||||
function(event) {
|
||||
if (event.target.children
|
||||
&& event.target.children[0]
|
||||
&& event.target.children[0].firstChild
|
||||
&& event.target.children[0].firstChild.className
|
||||
&& event.target.children[0].firstChild.className == "ii"
|
||||
) {
|
||||
blacklist();
|
||||
}
|
||||
},
|
||||
false
|
||||
);
|
BIN
src/gplusblacklist_128.png
Normal file
BIN
src/gplusblacklist_128.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.1 KiB |
BIN
src/gplusblacklist_16.png
Normal file
BIN
src/gplusblacklist_16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 820 B |
BIN
src/gplusblacklist_48.png
Normal file
BIN
src/gplusblacklist_48.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
src/gplusblacklist_64.png
Normal file
BIN
src/gplusblacklist_64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
29
src/manifest.json
Normal file
29
src/manifest.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "G+ Blacklist",
|
||||
"version": "0.1",
|
||||
"manifest_version": 2,
|
||||
"description": "Blacklist for Google+",
|
||||
"browser_action": {
|
||||
"default_title": "Blacklist for Google+",
|
||||
"default_popup": "popup.html",
|
||||
"default_icon": "gplusblacklist_48.png"
|
||||
},
|
||||
"permissions": [
|
||||
"tabs", "https://plus.google.com/*"
|
||||
],
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["https://plus.google.com/*"],
|
||||
"js": ["content.js"],
|
||||
"run_at": "document_end"
|
||||
}],
|
||||
"background": {
|
||||
"scripts": ["background.js"]
|
||||
},
|
||||
"icons": {
|
||||
"16": "gplusblacklist_16.png",
|
||||
"48": "gplusblacklist_48.png",
|
||||
"64": "gplusblacklist_64.png",
|
||||
"128": "gplusblacklist_128.png"
|
||||
}
|
||||
}
|
47
src/popup.css
Normal file
47
src/popup.css
Normal file
@ -0,0 +1,47 @@
|
||||
body {
|
||||
min-width: 300px;
|
||||
overflow-x: hidden;
|
||||
font-family: sans;
|
||||
font-size: smaller;
|
||||
}
|
||||
#headline {
|
||||
font-weight: bold;
|
||||
padding: 3px;
|
||||
}
|
||||
#blacklist_items {
|
||||
max-height: 500px;
|
||||
overflow: auto;
|
||||
}
|
||||
#blacklist_add {
|
||||
padding: 3px;
|
||||
}
|
||||
#addword_text {
|
||||
width: 200px;
|
||||
}
|
||||
#addword_btn {
|
||||
float: right;
|
||||
clear: right;
|
||||
}
|
||||
.blacklist_item {
|
||||
height: 25px;
|
||||
padding: 3px;
|
||||
border: 1px solid #f5eeff;
|
||||
font-family: monospace;
|
||||
}
|
||||
.blacklist_item div {
|
||||
float: left;
|
||||
width: 225px;
|
||||
margin: 5px 0px 0px 5px;
|
||||
}
|
||||
.blacklist_item input{
|
||||
float: right;
|
||||
clear: right;
|
||||
width: 60px;
|
||||
height: 25px;
|
||||
}
|
||||
.light {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
.dark {
|
||||
background-color: #f5eeff;
|
||||
}
|
19
src/popup.html
Normal file
19
src/popup.html
Normal file
@ -0,0 +1,19 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Google+ Blacklist</title>
|
||||
<link href="popup.css" rel="stylesheet" />
|
||||
<script type="text/javascript" src="popup.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="headline">Blacklist for Google+</div>
|
||||
<div id="blacklist">
|
||||
<div id="blacklist_items">
|
||||
</div>
|
||||
<div id="blacklist_add">
|
||||
Add:
|
||||
<input type="text" name="blacklist_word" id="addword_text" />
|
||||
<input type="button" value="Add" id="addword_btn" />
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
96
src/popup.js
Normal file
96
src/popup.js
Normal file
@ -0,0 +1,96 @@
|
||||
readBlacklist = function() {
|
||||
var needles = JSON.parse(localStorage.getItem("blacklist"));
|
||||
var blacklistItemsDiv = document.getElementById("blacklist_items");
|
||||
blacklistItemsDiv.innerHTML = "";
|
||||
if (needles) {
|
||||
for ( var i = 0; i < needles.length; i++ ) {
|
||||
var color = "light";
|
||||
if ( i % 2 != 0 ) {
|
||||
color = "dark";
|
||||
}
|
||||
var newdiv = document.createElement("div");
|
||||
newdiv.setAttribute("id", "blacklist_item_" + i);
|
||||
newdiv.setAttribute("class", "blacklist_item " + color);
|
||||
newdiv.innerHTML = "<div>" + needles[i] + "</div>";
|
||||
|
||||
var newbtn = document.createElement("input");
|
||||
newbtn.setAttribute("type", "button");
|
||||
newbtn.setAttribute("id", "blacklist_btn_" + i);
|
||||
newbtn.setAttribute("value", "Delete");
|
||||
newbtn.removeId = i;
|
||||
removeFunc = function(event) {
|
||||
removeBlacklistItem(event.target.removeId);
|
||||
}
|
||||
newbtn.addEventListener("click", removeFunc, false);
|
||||
newdiv.appendChild(newbtn);
|
||||
blacklistItemsDiv.appendChild(newdiv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
removeBlacklistItem = function(id) {
|
||||
console.log("try remove: " + id);
|
||||
var needles = JSON.parse(localStorage.getItem("blacklist"));
|
||||
if (needles[id]) {
|
||||
console.log("remove: " + id);
|
||||
needles.splice(id, 1);
|
||||
localStorage.setItem("blacklist", JSON.stringify(needles));
|
||||
}
|
||||
document.getElementById("addword_text").value = "";
|
||||
readBlacklist();
|
||||
renewBlacklist();
|
||||
}
|
||||
|
||||
addBlacklistItem = function(value) {
|
||||
var needles = JSON.parse(localStorage.getItem("blacklist"));
|
||||
if (needles) {
|
||||
for ( var i = 0; i < needles.length; i++ ) {
|
||||
if (needles[i] == value) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
needles.push(value);
|
||||
} else {
|
||||
needles = new Array(value);
|
||||
}
|
||||
localStorage.setItem("blacklist", JSON.stringify(needles));
|
||||
document.getElementById("addword_text").value = "";
|
||||
document.getElementById("addword_text").focus();
|
||||
readBlacklist();
|
||||
renewBlacklist();
|
||||
}
|
||||
|
||||
renewBlacklist = function() {
|
||||
var needles = JSON.parse(localStorage.getItem("blacklist"));
|
||||
if (!needles) {
|
||||
needles = new Array();
|
||||
}
|
||||
chrome.tabs.getSelected(null, function (tab) {
|
||||
chrome.tabs.sendMessage(tab.id,
|
||||
{ blacklist: needles},
|
||||
function (response) {}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
addEventListener("load", function() {
|
||||
var addwordBtn = document.getElementById("addword_btn");
|
||||
var addwordTxt = document.getElementById("addword_text");
|
||||
var currentUrlDiv = document.getElementById("current_url");
|
||||
|
||||
addwordBtn.addEventListener("click",
|
||||
function() { addBlacklistItem(addwordTxt.value); }, false
|
||||
);
|
||||
|
||||
addwordTxt.addEventListener("keydown",
|
||||
function(e) {
|
||||
if (e.keyCode == 13) {
|
||||
addBlacklistItem(addwordTxt.value);
|
||||
}
|
||||
}, false
|
||||
);
|
||||
|
||||
addwordTxt.focus();
|
||||
|
||||
readBlacklist();
|
||||
}, false);
|
Reference in New Issue
Block a user