Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add publish bar

  • Loading branch information...
commit e6aa3cc160d0973924b485a5caaf78e8f241590d 1 parent 4e745ec
andrews authored
86 extension/background.css
... ... @@ -1,11 +1,91 @@
  1 +#ogreddit {
  2 + font-family: Arial,Helvetica,Verdana,sans-serif;
  3 +}
  4 +
  5 +#ogreddit .publishPrompt {
  6 + background-image: url('chrome-extension://__MSG_@@extension_id__/images/texture.png');
  7 + background-repeat: repeat;
  8 + position: fixed;
  9 + width: 100%;
  10 + height: 66px;
  11 + top: -66px;
  12 + z-index: 1000;
  13 + -webkit-transition: top .3s;
  14 +}
  15 +
  16 +body.hasOGPublishPrompt #ogreddit .publishPrompt {
  17 + top: 0px;
  18 +}
  19 +
  20 +#ogreddit .publishPrompt .promptText {
  21 + font-family: verdana, sans-serif;
  22 + font-size: 18px;
  23 + color: #eee;
  24 + padding: 13px 0 13px 20px;
  25 +}
  26 +
  27 +#ogreddit .publishPrompt .publishStrip {
  28 + background-image: url('chrome-extension://__MSG_@@extension_id__/images/fbwarn.png');
  29 + background-repeat: repeat-x;
  30 + background-color: #eef;
  31 + clear: both;
  32 + height: 15px;
  33 + width: 100%;
  34 +}
  35 +
  36 +#ogreddit .publishPrompt .promptText {
  37 + float: left;
  38 +}
  39 +
  40 +#ogreddit .publishPrompt .buttonGroup {
  41 + float: right;
  42 + margin: 0 5px;
  43 +}
  44 +
  45 +#ogreddit .publishPrompt .buttonGroup button {
  46 + color: #444;
  47 + cursor: pointer;
  48 + font-weight: bold;
  49 + font-size: 13px;
  50 + margin: 10px 5px;
  51 + padding: 6px 10px;
  52 + -webkit-border-radius: 10px;
  53 +}
  54 +
  55 +#ogreddit .publishPrompt .buttonGroup .alwaysButton {
  56 + background: -webkit-linear-gradient(top, #EFE 0%, #DED 100%);
  57 + border: 1px solid #4B4;
  58 +}
  59 +
  60 +#ogreddit .publishPrompt .buttonGroup .alwaysButton:active {
  61 + background: -webkit-linear-gradient(top, #DED 0%, #EFE 100%);
  62 +}
  63 +
  64 +#ogreddit .publishPrompt .buttonGroup .yesButton {
  65 + background: -webkit-linear-gradient(top, #E6E0D4 0%, #DDD 100%);
  66 + border: 1px solid #888;
  67 +}
  68 +
  69 +#ogreddit .publishPrompt .buttonGroup .yesButton:active {
  70 + background: -webkit-linear-gradient(top, #DDD 0%, #E6E0D4 100%);
  71 +}
  72 +
  73 +#ogreddit .publishPrompt .buttonGroup .neverButton {
  74 + background: -webkit-linear-gradient(top, #F7EAEA 0%, #EDD 100%);
  75 + border: 1px solid #966;
  76 +}
  77 +
  78 +#ogreddit .publishPrompt .buttonGroup .neverButton:active {
  79 + background: -webkit-linear-gradient(top, #EDD 0%, #F7EAEA 100%);
  80 +}
  81 +
1 82 #ogreddit .settings {
2 83 position: fixed;
3   - bottom: 0px;
  84 + bottom: -214px;
4 85 height: 180px;
5 86 width: 100%;
6 87 background-image: url('chrome-extension://__MSG_@@extension_id__/images/texture.png');
7 88 background-repeat: repeat;
8   - font-family: Arial,Helvetica,Verdana,sans-serif;
9 89 padding: 15px;
10 90 border-top: 3px #333 solid;
11 91 -webkit-transition: bottom .3s;
@@ -28,7 +108,7 @@
28 108 }
29 109
30 110 #ogreddit .settings.closed {
31   - bottom: -214px;
  111 + bottom: 0px;
32 112 }
33 113
34 114 #ogreddit .settings h1 {
85 extension/content_script.js
@@ -28,16 +28,58 @@ $(function() {
28 28 }
29 29 }
30 30
  31 + function guardedPublish(action_name, subreddit_name, publish_function) {
  32 + settings_get_all(function(settings) {
  33 + if (settings['settings.publish.killswitch'] != 'false'
  34 + && settings['settings.publish.' + action_name] != 'false'
  35 + && settings['settings.subreddit.' + subreddit_name.toLowerCase()] != 'disabled') {
  36 + if (settings['settings.subreddit.' + subreddit_name.toLowerCase()] == 'enabled') {
  37 + // change back to publish
  38 + showPublishPrompt(subreddit_name, publish_function);
  39 + } else {
  40 + showPublishPrompt(subreddit_name, publish_function);
  41 + }
  42 + } else {
  43 + console.log('Not publishing because:');
  44 + settings['settings.publish.killswitch'] == 'false' && console.log(' - Killswitch engaged');
  45 + settings['settings.publish.' + action_name] == 'false' && console.log(' - Publishing turned off for ' + action_name);
  46 + settings['settings.subreddit.' + subreddit_name.toLowerCase()] == 'disabled' && console.log(' - Publishing turned off for /r/' + subreddit_name);
  47 + }
  48 + });
  49 + }
  50 +
  51 + function showPublishPrompt(subreddit_name, publish_function) {
  52 + var prompt = $('#ogreddit .publishPrompt');
  53 + prompt.find('.promptText').text("Publish actions for /r/" + subreddit_name + " to your timeline?");
  54 + prompt.find('button').off('click').click(function() { hidePublishPrompt(); });
  55 +
  56 + prompt.find('.yesButton').click(function() {
  57 + publish_function();
  58 + });
  59 +
  60 + prompt.find('.alwaysButton').click(function() {
  61 + settings_set('settings.subreddit.' + subreddit_name.toLowerCase(), 'enabled');
  62 + publish_function();
  63 + });
  64 +
  65 + prompt.find('.neverButton').click(function() {
  66 + settings_set('settings.subreddit.' + subreddit_name.toLowerCase(), 'disabled');
  67 + });
  68 +
  69 + $(document.body).addClass('hasOGPublishPrompt');
  70 + }
  71 +
  72 + function hidePublishPrompt() {
  73 + $(document.body).removeClass('hasOGPublishPrompt');
  74 + }
  75 +
31 76 var MAX_RETRIES = 5;
32 77 function postActionWithRetry(action, obj, retry_count) {
33   - if (!connected || !shouldPublish(action, obj.getSubreddit())) {
34   - console.error('Not publishing');
  78 + if (!connected) {
  79 + console.error('Not connected!');
35 80 return;
36 81 }
37 82
38   - console.error('Publishing');
39   - return;
40   -
41 83 if (retry_count === MAX_RETRIES) {
42 84 return;
43 85 }
@@ -63,7 +105,9 @@ $(function() {
63 105 }
64 106
65 107 function postAction(action, obj) {
66   - postActionWithRetry(action, obj, 0);
  108 + guardedPublish(action, obj.getSubreddit(), function() {
  109 + postActionWithRetry(action, obj, 0);
  110 + });
67 111 }
68 112
69 113 function upvote(button) {
@@ -111,10 +155,33 @@ $(function() {
111 155 settings_set('settings.hasRunBefore', true);
112 156 }
113 157
  158 + var prompt = $(
  159 + '<div class="publishPrompt">' +
  160 + '<div class="publishStrip" />' +
  161 + '<div class="promptText" />' +
  162 + '<div class="buttonGroup">' +
  163 + '<button class="alwaysButton">Always</button>' +
  164 + '<button class="yesButton">This once</button>' +
  165 + '<button class="neverButton">Never</button>' +
  166 + '<span class="noButton" />' +
  167 + '</div>' +
  168 + '</div>'
  169 + );
  170 +
114 171 $('body').append(
115 172 '<div id="ogreddit" class="closed">' +
116 173 '<div id="fb-root" />' +
117   - '<div class="content" />' +
  174 + '<div class="publishPrompt">' +
  175 + '<div class="publishStrip" />' +
  176 + '<div class="promptText" />' +
  177 + '<div class="buttonGroup">' +
  178 + '<button class="alwaysButton">Always</button>' +
  179 + '<button class="yesButton">This once</button>' +
  180 + '<button class="neverButton">Never</button>' +
  181 + '<span class="noButton" />' +
  182 + '</div>' +
  183 + '</div>' +
  184 + '<div id="settings_content" />' +
118 185 '</div>'
119 186 );
120 187
@@ -122,7 +189,7 @@ $(function() {
122 189 !value && firstRun();
123 190 });
124 191
125   - $('#ogreddit .content').load(chrome.extension.getURL('settings.html'), function() {
  192 + $('#ogreddit #settings_content').load(chrome.extension.getURL('settings.html'), function() {
126 193 var settings = $('#ogreddit .settings');
127 194 setupSettings(settings);
128 195 $('#ogreddit .settingsNib').click(function() {
@@ -130,6 +197,8 @@ $(function() {
130 197 });
131 198 });
132 199
  200 + $('#ogreddit').append(prompt);
  201 +
133 202 $('.arrow').click(function() {
134 203 var button = $(this);
135 204 if (button.parent().hasClass('likes')) {
BIN  extension/images/fbwarn.png
10 extension/settings.js
@@ -31,16 +31,6 @@ function settings_get_all(callback) {
31 31 });
32 32 }
33 33
34   -function guardedPublish(action_name, subreddit_name, publish_function) {
35   - settings_get_all(function(settings) {
36   - if (settings['settings.publish.killswitch'] != 'false'
37   - && settings['settings.publish.' + action_name] != 'false'
38   - && settings['settings.subreddit.' + subreddit_name.toLowerCase()] == 'enabled') {
39   - publish_function();
40   - }
41   - })
42   -}
43   -
44 34 function setupSettings(settings) {
45 35 $.each(SELECTOR_TO_SETTINGS_MAP, function(selector, setting_name) {
46 36 setupSettingsCheckbox(settings.find('input' + selector), setting_name);

0 comments on commit e6aa3cc

Please sign in to comment.
Something went wrong with that request. Please try again.