Permalink
Browse files

Add preference for display on https pages.

Merged with help from Justin Paupore <jpaupore@blueshiftlabs.net>.
  • Loading branch information...
1 parent 4213f24 commit e8c6b029f8de050a5ba448b0f3387036f21a330b @mhweaver mhweaver committed with chromakode Mar 7, 2012
Showing with 34 additions and 23 deletions.
  1. +32 −22 src/background.js
  2. +1 −1 src/manifest.json
  3. +1 −0 src/options.html
View
@@ -4,6 +4,7 @@ function initOptions() {
'autoShowSelf': true,
'showTooltips': true,
'checkMail': true,
+ 'allowHttps': false
}
for (key in defaultOptions) {
@@ -433,16 +434,14 @@ mailChecker = {
}
}
-function setPageActionIcon(tab) {
- if (/^http:\/\/.*/.test(tab.url)) {
- var info = redditInfo.getURL(tab.url)
- if (info) {
- chrome.pageAction.setIcon({tabId:tab.id, path:'/images/reddit.png'})
- } else {
- chrome.pageAction.setIcon({tabId:tab.id, path:'/images/reddit-inactive.png'})
- }
+function setPageActionIcon(tab, info) {
+ var pattern = (localStorage['allowHttps'] == 'true') ? /^https?:\/\/.*/ : /^http:\/\/.*/
+ if (pattern.test(tab.url)) {
+ var iconPath = info ? '/images/reddit.png' : '/images/reddit-inactive.png'
+ chrome.pageAction.setIcon({tabId:tab.id, path:iconPath})
chrome.pageAction.show(tab.id)
- return info
+ } else {
+ chrome.pageAction.hide(tab.id)
}
}
@@ -463,7 +462,7 @@ function onActionClicked(tab) {
redditInfo.lookupURL(tab.url, true, function(info) {
window.clearInterval(workingAnimation)
- setPageActionIcon(tab)
+ setPageActionIcon(tab, info)
delete workingPageActions[tab.id]
if (info) {
@@ -494,12 +493,15 @@ chrome.extension.onConnect.addListener(function(port) {
case 'overlay':
tabStatus.add(port)
var tab = port.sender.tab,
- info = setPageActionIcon(tab)
+ info = redditInfo.getURL(tab.url)
+ setPageActionIcon(tab, info)
if (info) {
if (localStorage['autoShow'] == 'false') {
console.log('Auto-show disabled. Ignoring reddit page', info)
} else if (localStorage['autoShowSelf'] == 'false' && info.is_self) {
console.log('Ignoring self post', info)
+ } else if (localStorage['allowHttps'] == 'false' && /^https:\/\/.*/.test(tab.url)) {
+ console.log('Https page. Ignoring', info)
} else if (barStatus.hidden[info.name]) {
console.log('Bar was closed on this page. Ignoring.', info)
} else {
@@ -515,27 +517,35 @@ chrome.extension.onConnect.addListener(function(port) {
})
window.addEventListener('storage', function(e) {
- if (e.key == 'checkMail') {
- if (e.newValue == 'true') {
- mailChecker.start()
- } else {
- mailChecker.stop()
- }
+ switch (e.key) {
+ case 'checkMail':
+ if (e.newValue == 'true') {
+ mailChecker.start()
+ } else {
+ mailChecker.stop()
+ }
+ break
+ case 'allowHttps':
+ setAllPageActionIcons()
+ break
}
}, false)
// Show page action for existing tabs.
-chrome.windows.getAll({populate:true}, function(wins) {
- wins.forEach(function(win) {
- win.tabs.forEach(function(tab) {
- setPageActionIcon(tab)
+function setAllPageActionIcons() {
+ chrome.windows.getAll({populate:true}, function(wins) {
+ wins.forEach(function(win) {
+ win.tabs.forEach(function(tab) {
+ setPageActionIcon(tab, redditInfo.getURL(tab.url))
+ })
})
})
-})
+}
initOptions()
console.log('Shine loaded.')
redditInfo.init()
+setAllPageActionIcons()
if (localStorage['checkMail'] == 'true') {
mailChecker.start()
} else {
View
@@ -25,7 +25,7 @@
"js": ["debug.js", "redditContent.js"]
},
{
- "matches": ["http://*/*"],
+ "matches": ["http://*/*", "https://*/*"],
"run_at": "document_start",
"js": ["debug.js", "pageOverlay.js"],
"css": ["pageOverlay.css"]
View
@@ -19,6 +19,7 @@ <h1><img src="/images/shine.svg" alt="logo"/>reddit companion options</h1>
<li><input type="checkbox" id="autoShow"> <label for="autoShow">display automatically after clicking links on reddit</label></li>
<li><input type="checkbox" id="autoShowSelf"> <label for="autoShowSelf">display when viewing self posts</label></li>
<li><input type="checkbox" id="showTooltips"> <label for="showTooltips">show tooltips on buttons</label></li>
+ <li><input type="checkbox" id="allowHttps"> <label for="allowHttps">enable companion on https pages</label>
</ul>
</div>
</section>

0 comments on commit e8c6b02

Please sign in to comment.