Created
March 6, 2010 13:45
-
-
Save mowen/323679 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* SiteFocus, an enhanced version of the Blacklist Sites - Page Mods Demo. | |
* Recommended for anyone who has this problem: http://xkcd.com/477/ | |
* Martin Owen - martinowenuk@gmail.com | |
*/ | |
jetpack.future.import("storage.simple"); | |
jetpack.future.import('menu'); | |
function SiteFocus() { | |
this.storage = jetpack.storage.simple; | |
var defaults = [ "youtube.com", "facebook.com", "twitter.com", "last.fm", "digg.com" ]; | |
this.bannedSites = this.storage.bannedSites || defaults; | |
this.updateMenu(); | |
} | |
SiteFocus.prototype = { | |
updateMenu: function() { | |
var addCurrentSiteMenuItem = { | |
label: "Add current site", | |
command: this.addCurrentSite | |
}; | |
var clearBannedSitesMenuItem = { | |
label: "Clear banned sites", | |
command: this.clearBannedSites | |
}; | |
var bannedSitesMenuItem = { | |
label: "Banned Sites", | |
menu: new jetpack.Menu(this.bannedSites) | |
}; | |
jetpack.menu.set({ | |
label: "Site Focus", | |
menu: new jetpack.Menu([ | |
addCurrentSiteMenuItem, | |
clearBannedSitesMenuItem, | |
bannedSitesMenuItem | |
]) | |
}); | |
}, | |
isBannedSite: function(url) { | |
for (var i=0; i<this.bannedSites.length; i++) { | |
if (url.match(this.bannedSites[i])) { | |
return true; | |
} | |
} | |
return false; | |
}, | |
addCurrentSite: function() { | |
var currentURL = jetpack.tabs.focused.url; | |
siteFocus.storage.bannedSites.push(currentURL); | |
this.updateMenu(); | |
}, | |
clearBannedSites: function() { | |
this.storage.bannedSites = []; | |
this.updateMenu(); | |
}, | |
splatContent: function() { | |
var doc = jetpack.tabs.focused.contentDocument; | |
var win = jetpack.tabs.focused.contentWindow; | |
// Modal window from http://www.queness.com/post/77/simple-jquery-modal-window-tutorial | |
$(doc).find("body").prepend( | |
'<div id="site-focus-modal"> \ | |
<div id="site-focus-banned-window" class="site-focus-window"> \ | |
<p>This site is banned by SiteFocus.</p> \ | |
</div> \ | |
<div id="site-focus-mask"></div> \ | |
</div>'); | |
$(doc).find("#site-focus-mask").css( | |
{ | |
"position": "absolute", | |
"z-index": "9000", | |
"background-color": "#000", | |
"display": "none" | |
} | |
); | |
$(doc).find(".site-focus-window").css( | |
{ | |
"position": "absolute", | |
"width": "440px", | |
"height": "200px", | |
"display": "none", | |
"z-index": "9999", | |
"padding": "20px" | |
} | |
); | |
$(doc).find("#site-focus-banned-window").css( | |
{ | |
"width": "375px", | |
"height": "203px" | |
} | |
).find("p").css( | |
{ | |
"font-size": "1.5em", | |
"font-weight": "bold", | |
"color": "#fff", | |
"text-align": "center" | |
} | |
); | |
//Get the screen height and width | |
var maskHeight = $(doc).height(); | |
var maskWidth = $(win).width(); | |
//Set height and width to mask to fill up the whole screen | |
$(doc).find('#site-focus-mask').css({'width':maskWidth,'height':maskHeight}); | |
//transition effect | |
$(doc).find('#site-focus-mask').fadeIn(1000); | |
$(doc).find('#site-focus-mask').fadeTo("slow",0.8); | |
//Get the window height and width | |
var winH = $(win).height(); | |
var winW = $(win).width(); | |
//Set the popup window to center | |
$('#site-focus-banned-window').css('top', winH/2-$(id).height()/2); | |
$('#site-focus-banned-window').css('left', winW/2-$(id).width()/2); | |
//transition effect | |
$('#site-focus-banned-window').fadeIn(2000); | |
} | |
}; | |
var siteFocus = new SiteFocus(); | |
jetpack.tabs.onReady(function(){ | |
if (siteFocus.isBannedSite(this.url)) { | |
siteFocus.splatContent(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment