Permalink
Browse files

add publish bar

  • Loading branch information...
1 parent 4e745ec commit e6aa3cc160d0973924b485a5caaf78e8f241590d @astreet committed Mar 21, 2012
Showing with 160 additions and 21 deletions.
  1. +83 −3 extension/background.css
  2. +77 −8 extension/content_script.js
  3. BIN extension/images/fbwarn.png
  4. +0 −10 extension/settings.js
View
@@ -1,11 +1,91 @@
+#ogreddit {
+ font-family: Arial,Helvetica,Verdana,sans-serif;
+}
+
+#ogreddit .publishPrompt {
+ background-image: url('chrome-extension://__MSG_@@extension_id__/images/texture.png');
+ background-repeat: repeat;
+ position: fixed;
+ width: 100%;
+ height: 66px;
+ top: -66px;
+ z-index: 1000;
+ -webkit-transition: top .3s;
+}
+
+body.hasOGPublishPrompt #ogreddit .publishPrompt {
+ top: 0px;
+}
+
+#ogreddit .publishPrompt .promptText {
+ font-family: verdana, sans-serif;
+ font-size: 18px;
+ color: #eee;
+ padding: 13px 0 13px 20px;
+}
+
+#ogreddit .publishPrompt .publishStrip {
+ background-image: url('chrome-extension://__MSG_@@extension_id__/images/fbwarn.png');
+ background-repeat: repeat-x;
+ background-color: #eef;
+ clear: both;
+ height: 15px;
+ width: 100%;
+}
+
+#ogreddit .publishPrompt .promptText {
+ float: left;
+}
+
+#ogreddit .publishPrompt .buttonGroup {
+ float: right;
+ margin: 0 5px;
+}
+
+#ogreddit .publishPrompt .buttonGroup button {
+ color: #444;
+ cursor: pointer;
+ font-weight: bold;
+ font-size: 13px;
+ margin: 10px 5px;
+ padding: 6px 10px;
+ -webkit-border-radius: 10px;
+}
+
+#ogreddit .publishPrompt .buttonGroup .alwaysButton {
+ background: -webkit-linear-gradient(top, #EFE 0%, #DED 100%);
+ border: 1px solid #4B4;
+}
+
+#ogreddit .publishPrompt .buttonGroup .alwaysButton:active {
+ background: -webkit-linear-gradient(top, #DED 0%, #EFE 100%);
+}
+
+#ogreddit .publishPrompt .buttonGroup .yesButton {
+ background: -webkit-linear-gradient(top, #E6E0D4 0%, #DDD 100%);
+ border: 1px solid #888;
+}
+
+#ogreddit .publishPrompt .buttonGroup .yesButton:active {
+ background: -webkit-linear-gradient(top, #DDD 0%, #E6E0D4 100%);
+}
+
+#ogreddit .publishPrompt .buttonGroup .neverButton {
+ background: -webkit-linear-gradient(top, #F7EAEA 0%, #EDD 100%);
+ border: 1px solid #966;
+}
+
+#ogreddit .publishPrompt .buttonGroup .neverButton:active {
+ background: -webkit-linear-gradient(top, #EDD 0%, #F7EAEA 100%);
+}
+
#ogreddit .settings {
position: fixed;
- bottom: 0px;
+ bottom: -214px;
height: 180px;
width: 100%;
background-image: url('chrome-extension://__MSG_@@extension_id__/images/texture.png');
background-repeat: repeat;
- font-family: Arial,Helvetica,Verdana,sans-serif;
padding: 15px;
border-top: 3px #333 solid;
-webkit-transition: bottom .3s;
@@ -28,7 +108,7 @@
}
#ogreddit .settings.closed {
- bottom: -214px;
+ bottom: 0px;
}
#ogreddit .settings h1 {
@@ -28,16 +28,58 @@ $(function() {
}
}
+ function guardedPublish(action_name, subreddit_name, publish_function) {
+ settings_get_all(function(settings) {
+ if (settings['settings.publish.killswitch'] != 'false'
+ && settings['settings.publish.' + action_name] != 'false'
+ && settings['settings.subreddit.' + subreddit_name.toLowerCase()] != 'disabled') {
+ if (settings['settings.subreddit.' + subreddit_name.toLowerCase()] == 'enabled') {
+ // change back to publish
+ showPublishPrompt(subreddit_name, publish_function);
+ } else {
+ showPublishPrompt(subreddit_name, publish_function);
+ }
+ } else {
+ console.log('Not publishing because:');
+ settings['settings.publish.killswitch'] == 'false' && console.log(' - Killswitch engaged');
+ settings['settings.publish.' + action_name] == 'false' && console.log(' - Publishing turned off for ' + action_name);
+ settings['settings.subreddit.' + subreddit_name.toLowerCase()] == 'disabled' && console.log(' - Publishing turned off for /r/' + subreddit_name);
+ }
+ });
+ }
+
+ function showPublishPrompt(subreddit_name, publish_function) {
+ var prompt = $('#ogreddit .publishPrompt');
+ prompt.find('.promptText').text("Publish actions for /r/" + subreddit_name + " to your timeline?");
+ prompt.find('button').off('click').click(function() { hidePublishPrompt(); });
+
+ prompt.find('.yesButton').click(function() {
+ publish_function();
+ });
+
+ prompt.find('.alwaysButton').click(function() {
+ settings_set('settings.subreddit.' + subreddit_name.toLowerCase(), 'enabled');
+ publish_function();
+ });
+
+ prompt.find('.neverButton').click(function() {
+ settings_set('settings.subreddit.' + subreddit_name.toLowerCase(), 'disabled');
+ });
+
+ $(document.body).addClass('hasOGPublishPrompt');
+ }
+
+ function hidePublishPrompt() {
+ $(document.body).removeClass('hasOGPublishPrompt');
+ }
+
var MAX_RETRIES = 5;
function postActionWithRetry(action, obj, retry_count) {
- if (!connected || !shouldPublish(action, obj.getSubreddit())) {
- console.error('Not publishing');
+ if (!connected) {
+ console.error('Not connected!');
return;
}
- console.error('Publishing');
- return;
-
if (retry_count === MAX_RETRIES) {
return;
}
@@ -63,7 +105,9 @@ $(function() {
}
function postAction(action, obj) {
- postActionWithRetry(action, obj, 0);
+ guardedPublish(action, obj.getSubreddit(), function() {
+ postActionWithRetry(action, obj, 0);
+ });
}
function upvote(button) {
@@ -111,25 +155,50 @@ $(function() {
settings_set('settings.hasRunBefore', true);
}
+ var prompt = $(
+ '<div class="publishPrompt">' +
+ '<div class="publishStrip" />' +
+ '<div class="promptText" />' +
+ '<div class="buttonGroup">' +
+ '<button class="alwaysButton">Always</button>' +
+ '<button class="yesButton">This once</button>' +
+ '<button class="neverButton">Never</button>' +
+ '<span class="noButton" />' +
+ '</div>' +
+ '</div>'
+ );
+
$('body').append(
'<div id="ogreddit" class="closed">' +
'<div id="fb-root" />' +
- '<div class="content" />' +
+ '<div class="publishPrompt">' +
+ '<div class="publishStrip" />' +
+ '<div class="promptText" />' +
+ '<div class="buttonGroup">' +
+ '<button class="alwaysButton">Always</button>' +
+ '<button class="yesButton">This once</button>' +
+ '<button class="neverButton">Never</button>' +
+ '<span class="noButton" />' +
+ '</div>' +
+ '</div>' +
+ '<div id="settings_content" />' +
'</div>'
);
settings_get('settings.hasRunBefore', function(value) {
!value && firstRun();
});
- $('#ogreddit .content').load(chrome.extension.getURL('settings.html'), function() {
+ $('#ogreddit #settings_content').load(chrome.extension.getURL('settings.html'), function() {
var settings = $('#ogreddit .settings');
setupSettings(settings);
$('#ogreddit .settingsNib').click(function() {
settings.toggleClass('closed');
});
});
+ $('#ogreddit').append(prompt);
+
$('.arrow').click(function() {
var button = $(this);
if (button.parent().hasClass('likes')) {
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -31,16 +31,6 @@ function settings_get_all(callback) {
});
}
-function guardedPublish(action_name, subreddit_name, publish_function) {
- settings_get_all(function(settings) {
- if (settings['settings.publish.killswitch'] != 'false'
- && settings['settings.publish.' + action_name] != 'false'
- && settings['settings.subreddit.' + subreddit_name.toLowerCase()] == 'enabled') {
- publish_function();
- }
- })
-}
-
function setupSettings(settings) {
$.each(SELECTOR_TO_SETTINGS_MAP, function(selector, setting_name) {
setupSettingsCheckbox(settings.find('input' + selector), setting_name);

0 comments on commit e6aa3cc

Please sign in to comment.