From 40b92a38d0d1da76003ac205c4e1aa02a9102eaa Mon Sep 17 00:00:00 2001 From: Kerrick Long Date: Sat, 16 Jul 2011 12:16:32 -0500 Subject: [PATCH] Added shameless plug (off by default) --- .gitignore | 4 +- fancy-settings/custom.css | 5 +- fancy-settings/manifest.js | 114 +++++++++++++++++++++---------------- js/common.js | 8 ++- 4 files changed, 75 insertions(+), 56 deletions(-) diff --git a/.gitignore b/.gitignore index e6f09da..2292512 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -# Ignore the files needed to deploy to the Chrome Web Store. -deploy/**/* \ No newline at end of file +deploy/ +resources/ \ No newline at end of file diff --git a/fancy-settings/custom.css b/fancy-settings/custom.css index 8404e6a..fc35046 100755 --- a/fancy-settings/custom.css +++ b/fancy-settings/custom.css @@ -10,4 +10,7 @@ } textarea { font-family: Consolas, "Lucida Console", Monaco, monospace -} \ No newline at end of file +} +.setting.label.checkbox { + color: #666; +} diff --git a/fancy-settings/manifest.js b/fancy-settings/manifest.js index 488ede8..94e0127 100755 --- a/fancy-settings/manifest.js +++ b/fancy-settings/manifest.js @@ -3,6 +3,70 @@ this.manifest = { "name": "Mostly Harmless", "icon": "/pix/alien.png", "settings": [ + { + "tab": "Preferences", + "group": "Fresh Content", + "name": "freshCutoff", + "type": "slider", + "label": "", + "max": 91, + "min": 1, + "step": 1, + "display": true, + "displayModifier": function(value) { + if(value === 1) + return "Show posts less than " + value.toString() + " day old"; + if(value <= 2 * 7) + return "Show posts less than " + value.toString() + " days old"; + if(value > 2 * 7 && value < 7 * 7) + return "Show posts less than " + Math.floor(value / 7).toString() + " weeks old"; + if(value >= 7 * 7 && value < 91) + return "Show posts less than " + Math.ceil(value / 30).toString() + " months old"; + return "Show posts from all time"; + } + }, + { + "tab": "Preferences", + "group": "Fresh Content", + "name": "freshCutoffDescription", + "type": "description", + "text": "

This setting allows you to choose the oldest reddit posts you’d like to see. Anything posted before the value you’ve chosen will be indicated in the browser button's total, but will not be shown in the popup." + }, + { + "tab": "Preferences", + "group": "Popup Width", + "name": "popupWidth", + "type": "slider", + "label": "", + "max": 784, + "min": 480, + "step": 1, + "display": true, + "displayModifier": function(value) { + return value.toString() + "px"; + } + }, + { + "tab": "Preferences", + "group": "Popup Width", + "name": "popupWidthDescription", + "type": "description", + "text": "

This setting allows you to set the width of the browser action popup." + }, + { + "tab": "Preferences", + "group": "Shameless Plug", + "name": "shamelessPlug", + "type": "checkbox", + "label": "Show the shameless plug", + }, + { + "tab": "Preferences", + "group": "Shameless Plug", + "name": "shamelessPlugDescription", + "type": "description", + "text": "

When checked, this will add the following to each commment you post from within Mostly Harmless:

Posted from Mostly Harmless, a Google Chrome extension for awesome redditors.

" + }, { "tab": "Performance", "group": "Cache Time", @@ -87,56 +151,6 @@ this.manifest = { "name": "excludedRegexDescription", "type": "description", "text": "

Put regular expressions, one per line, in the above text box. Please do not use the \\n character, because there should be no newlines in a URL. Any page that matches the listed regular expressions will not activate Mostly Harmless." - }, - { - "tab": "Preferences", - "group": "Fresh Content", - "name": "freshCutoff", - "type": "slider", - "label": "", - "max": 91, - "min": 1, - "step": 1, - "display": true, - "displayModifier": function(value) { - if(value === 1) - return "Show posts less than " + value.toString() + " day old"; - if(value <= 2 * 7) - return "Show posts less than " + value.toString() + " days old"; - if(value > 2 * 7 && value < 7 * 7) - return "Show posts less than " + Math.floor(value / 7).toString() + " weeks old"; - if(value >= 7 * 7 && value < 91) - return "Show posts less than " + Math.ceil(value / 30).toString() + " months old"; - return "Show posts from all time"; - } - }, - { - "tab": "Preferences", - "group": "Fresh Content", - "name": "freshCutoffDescription", - "type": "description", - "text": "

This setting allows you to choose the oldest reddit posts you’d like to see. Anything posted before the value you’ve chosen will be indicated in the browser button's total, but will not be shown in the popup." - }, - { - "tab": "Preferences", - "group": "Popup Width", - "name": "popupWidth", - "type": "slider", - "label": "", - "max": 784, - "min": 480, - "step": 1, - "display": true, - "displayModifier": function(value) { - return value.toString() + "px"; - } - }, - { - "tab": "Preferences", - "group": "Popup Width", - "name": "popupWidthDescription", - "type": "description", - "text": "

This setting allows you to set the width of the browser action popup." } ] }; diff --git a/js/common.js b/js/common.js index a9a695b..c7e24b7 100644 --- a/js/common.js +++ b/js/common.js @@ -4,7 +4,8 @@ settings = new Store('settings', { 'cacheTime': 3, 'timeoutLength': 5, 'freshCutoff': 7, - 'popupWidth': 640 + 'popupWidth': 640, + 'shamelessPlug': false }); cache = new Store('cache'); @@ -634,7 +635,7 @@ RedditAPI.prototype.reportPost = function (e) { * @method */ RedditAPI.prototype.submitComment = function (e) { - var listItem, fullName, status, submitButton, cancelButton, textarea, formData; + var listItem, fullName, status, submitButton, cancelButton, textarea, comment, formData; function afterSubmission (response) { var url, oldCache; @@ -659,13 +660,14 @@ RedditAPI.prototype.submitComment = function (e) { status = submitButton.parentNode.getElementsByClassName('status')[0]; cancelButton = submitButton.parentNode.getElementsByClassName('cancel')[0]; textarea = e.srcElement.parentNode.getElementsByTagName('textarea')[0]; + comment = settings.get('shamelessPlug') ? textarea.value + '\n\n*Posted from [Mostly Harmless](http://kerrick.github.com/Mostly-Harmless), a Google Chrome extension for awesome redditors.*' : textarea.value; if (textarea.value === '') { status.innerHTML = 'There needs to be something here.'; } else { formData = new FormData(); formData.append('thing_id', fullName); - formData.append('text', textarea.value); + formData.append('text', comment); formData.append('uh', cache.get('modhash')); status.innerHTML = 'submitting...'; try {