commit 45b9c4c4b7e8f7712d7a469f03000e95bcb778f8 Author: Ryad El-Dajani Date: Fri Nov 23 12:16:17 2012 +0100 + initial commit diff --git a/gplusblacklist.crx b/gplusblacklist.crx new file mode 100644 index 0000000..1c05d89 Binary files /dev/null and b/gplusblacklist.crx differ diff --git a/gplusblacklist.png b/gplusblacklist.png new file mode 100644 index 0000000..26e1465 Binary files /dev/null and b/gplusblacklist.png differ diff --git a/gplusblacklist_screenshot.png b/gplusblacklist_screenshot.png new file mode 100644 index 0000000..be60d8f Binary files /dev/null and b/gplusblacklist_screenshot.png differ diff --git a/src/background.js b/src/background.js new file mode 100644 index 0000000..7881042 --- /dev/null +++ b/src/background.js @@ -0,0 +1,7 @@ +chrome.extension.onRequest.addListener( + function(request, sender, sendResponse) { + if (request.method == "getBlacklist") { + sendResponse({blacklist: JSON.parse(localStorage["blacklist"])}); + } + } +); \ No newline at end of file diff --git a/src/content.js b/src/content.js new file mode 100644 index 0000000..e7c567a --- /dev/null +++ b/src/content.js @@ -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 +); \ No newline at end of file diff --git a/src/gplusblacklist_128.png b/src/gplusblacklist_128.png new file mode 100644 index 0000000..b797be0 Binary files /dev/null and b/src/gplusblacklist_128.png differ diff --git a/src/gplusblacklist_16.png b/src/gplusblacklist_16.png new file mode 100644 index 0000000..e492edc Binary files /dev/null and b/src/gplusblacklist_16.png differ diff --git a/src/gplusblacklist_48.png b/src/gplusblacklist_48.png new file mode 100644 index 0000000..9cdf8f1 Binary files /dev/null and b/src/gplusblacklist_48.png differ diff --git a/src/gplusblacklist_64.png b/src/gplusblacklist_64.png new file mode 100644 index 0000000..cb00bba Binary files /dev/null and b/src/gplusblacklist_64.png differ diff --git a/src/manifest.json b/src/manifest.json new file mode 100644 index 0000000..6905ffd --- /dev/null +++ b/src/manifest.json @@ -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" + } +} \ No newline at end of file diff --git a/src/popup.css b/src/popup.css new file mode 100644 index 0000000..50d4415 --- /dev/null +++ b/src/popup.css @@ -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; +} \ No newline at end of file diff --git a/src/popup.html b/src/popup.html new file mode 100644 index 0000000..f876e53 --- /dev/null +++ b/src/popup.html @@ -0,0 +1,19 @@ + + + Google+ Blacklist + + + + +
Blacklist for Google+
+
+
+
+
+ Add: + + +
+
+ + diff --git a/src/popup.js b/src/popup.js new file mode 100644 index 0000000..252560a --- /dev/null +++ b/src/popup.js @@ -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 = "
" + needles[i] + "
"; + + 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); \ No newline at end of file