Skip to content

Commit

Permalink
v1.2: Click the page action icon to toggle the banner.
Browse files Browse the repository at this point in the history
Also, record how many of those we have removed across all the wikimedia sites.
  • Loading branch information
johan committed Dec 29, 2010
1 parent 6d90457 commit a09b1c8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
23 changes: 22 additions & 1 deletion crx/background.html
@@ -1,6 +1,27 @@
<!DOCTYPE html><html><head><script>
// documents with Wikimedia banners notify us to turn on their page action icon
chrome.extension.onRequest.addListener(function show(req, from, sendResponse) {
chrome.pageAction.show(from.tab.id);
var tab = from.tab, host = hostname(tab.url), title =
'Click to toggle the Wikimedia banner.\n' +
'Removed so far: '+ inc('Σ') +' ('+ inc(host) +' at '+ host +')';
chrome.pageAction.setTitle({ tabId: tab.id, title: title });
chrome.pageAction.show(tab.id); // show the page action icon
sendResponse({});
});

// and when the user clicks that icon, have the content script toggle the banner
chrome.pageAction.onClicked.addListener(function toggle(tab) {
chrome.tabs.sendRequest(tab.id, {}, function(response) {});
});

// add 1 to this couter in localStorage
function inc(id) {
return localStorage[id] = 1 + Number(localStorage[id] || 0);
}

function hostname(url) {
var a = document.createElement('a');
a.href = url;
return a.hostname;
}
</script></head></html>
4 changes: 2 additions & 2 deletions crx/manifest.json
Expand Up @@ -22,7 +22,7 @@
]
, "description": "This extension removes all the site annoying site banners (featuring Jimmy Wales, or any other random encounter among the Wikipedia editors, founders or otherwise) from all Wikipedia and other Wikimedia sites. This extension is licensed under the Creative Commons Attribution ShareAlike 3.0 Unported License, as is the picture of Jimbo in its icon."
, "name": "Banner free Wikipedia"
, "version": "1.1"
, "version": "1.2"
, "license": "Creative Commons Attribution ShareAlike 3.0 Unported License"
, "icons":
{ "128": "128.png"
Expand All @@ -32,6 +32,6 @@
, "background_page": "background.html"
, "page_action":
{ "default_icon": "19.png"
, "default_title": "There was a Wikimedia banner in this page!"
, "default_title": "Click to toggle the Wikimedia banner."
}
}
13 changes: 12 additions & 1 deletion crx/presence-page-action.js
Expand Up @@ -2,11 +2,22 @@ var site_notice = document.getElementById('siteNotice');
if (site_notice)
site_notice.addEventListener('DOMSubtreeModified', changed, false);

// await the banner's jQuery-mediated insertion, and then:
function changed(e) {
function toggle() {
banner.style.display = banner.style.display ? '' : 'block !important';
}

function pageActionClick(req, from, sendResponse) {
if (!from.tab) toggle(); // only react to the background page
}

var banner = site_notice.querySelector('*[id*=Banner]');
// console.warn('Site notice changed; banner:', banner);
if (banner) {

if (banner) { // banner confirmed; stop waiting and pop the page action icon
site_notice.removeEventListener('DOMSubtreeModified', changed, false);
chrome.extension.sendRequest({}, function(response) {});
chrome.extension.onRequest.addListener(pageActionClick);
}
}

0 comments on commit a09b1c8

Please sign in to comment.