diff --git a/.gitignore b/.gitignore index 4f61b8c..ca85ffa 100644 --- a/.gitignore +++ b/.gitignore @@ -100,4 +100,4 @@ ENV/ # mypy .mypy_cache/ -.DS_Store +*.DS_Store diff --git a/extension/background.js b/extension/background.js index 3ab316b..b99c8fc 100644 --- a/extension/background.js +++ b/extension/background.js @@ -2,8 +2,10 @@ // listen for our browserAction to be clicked chrome.browserAction.onClicked.addListener(function (tab) { - // for the current tab, inject the "inject.js" file & execute it - chrome.tabs.executeScript(tab.ib, { - file: 'inject.js' + // for the current tab, inject the "inject.js" file & execute it + if (tab.url.indexOf('/comments/') != -1) { + chrome.tabs.executeScript(tab.ib, { + file: 'inject.js' }); + } }); diff --git a/extension/inject.js b/extension/inject.js index d80a53b..27d982f 100644 --- a/extension/inject.js +++ b/extension/inject.js @@ -1,5 +1,19 @@ (function() { + settings = {} + chrome.storage.sync.get({ + showPositive: false, + showNeutral: false, + showNegative: false, + showAll: true + }, function(items) { + settings.positive = items.showPositive; + settings.neutral = items.showNeutral; + settings.negative = items.showNegative; + settings.showall = items.showAll; + }); + console.log(settings) let $grabFromPage = $('div.commentarea div.md') + let $url = window.location.pathname; let textToEval = {}; $grabFromPage.addClass(function(index){ return 'reddex' + index; @@ -7,18 +21,30 @@ $grabFromPage.each(function(index){ textToEval[$grabFromPage[index].className.split(' ')[1]] = $grabFromPage[index].innerText; }); + textToEval.url = $url.split('/')[2] console.log(textToEval) - $.post('https://reddex.herokuapp.com/inbound', textToEval, function(response){ + $.ajax({ + url: 'https://reddex.herokuapp.com/inbound', + method: 'POST', + data: textToEval + }) + .then(function(response){ console.log(response) for(key in response){ $('.' + key).addClass(function(index){ - if(response[key] <= -.3){ + if((response[key] <= -0.65) && (settings.showall === true || settings.negative === true)){ + return 'neg2' + } + else if((response[key] <= -0.35) && (settings.showall === true || settings.negative === true)) { return 'neg1' } - else if(response[key] > 0.3){ + else if((response[key] > 0.65) && (settings.showall === true || settings.positive === true)) { + return 'pos2' + } + else if((response[key] > 0.35) && (settings.showall === true || settings.positive === true)){ return 'pos1' } - else{ + else if((response[key] > -0.35 && response[key] <= 0.35) && (settings.showall === true || settings.neutral === true)){ return 'neu' } }) diff --git a/extension/manifest.json b/extension/manifest.json index 3f809a3..c1ebaa2 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,6 +1,6 @@ { "name": "Reddex", - "version": "0.0.1", + "version": "0.0.2", "manifest_version": 2, "description": "Evaluate Reddit comments for tone and biases", "homepage_url": "https://reddex.herokuapp.com", @@ -8,18 +8,23 @@ "scripts": [ "background.js" ], - "persistent": true + "persistent": false + }, + "options_ui":{ + "page": "options.html", + "chrome_style": true }, "browser_action": { "default_title": "Evaluate comments" }, "permissions": [ - "activeTab" + "https://www.reddit.com/r/*/comments/*", + "storage" ], "content_scripts": [ { - "matches": [ "https://*.reddit.com/r/*" ], - "js": [ "jquery-3.2.1.min.js", "inject.js" ], + "matches": [ "https://*.reddit.com/r/*/comments/*" ], + "js": [ "jquery-3.2.1.min.js" ], "css": [ "styles.css" ] } ], diff --git a/extension/options.html b/extension/options.html new file mode 100644 index 0000000..a84dc8c --- /dev/null +++ b/extension/options.html @@ -0,0 +1,39 @@ + + + + + My Test Extension Options + + +
+ Comment types to highlight: +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+ +
+ + + + \ No newline at end of file diff --git a/extension/options.js b/extension/options.js new file mode 100644 index 0000000..e00de7f --- /dev/null +++ b/extension/options.js @@ -0,0 +1,40 @@ +// Saves options to chrome.storage +function save_options() { + var positive = document.getElementById('positive').checked; + var neutral = document.getElementById('neutral').checked; + var negative = document.getElementById('negative').checked; + var all = document.getElementById('all').checked; + console.log(positive, neutral, negative, all); + // var color = document.getElementById('color').value; + // var likesColor = document.getElementById('like').checked; + chrome.storage.sync.set({ + showPositive: positive, + showNeutral: neutral, + showNegative: negative, + showAll: all + }, function() { + // Update status to let user know options were saved. + var status = document.getElementById('status'); + status.textContent = 'Options saved.'; + }); +} + +// Restores select box and checkbox state using the preferences +// stored in chrome.storage. +function restore_options() { + // Use default value of show all. + chrome.storage.sync.get({ + showPositive: false, + showNeutral: false, + showNegative: false, + showAll: true + }, function(items) { + document.getElementById('positive').checked = items.showPositive; + document.getElementById('neutral').checked = items.showNeutral; + document.getElementById('negative').checked = items.showNegative; + document.getElementById('all').checked = items.showAll; + }); +} +document.addEventListener('DOMContentLoaded', restore_options); +document.getElementById('save').addEventListener('click', + save_options); \ No newline at end of file diff --git a/extension/styles.css b/extension/styles.css index 338aaff..b6f11ef 100644 --- a/extension/styles.css +++ b/extension/styles.css @@ -1,26 +1,20 @@ /*styles*/ div.neg1 { - border-style: solid !important; - border-width: 2px !important; - border-color: rgba(255, 0, 0, 0.5) !important; + background-color: #ffeef0 !important; } + div.neg2 { - border-style: solid !important; - border-width: 2px !important; - border-color: rgba(255, 0, 0, 0.7) !important; + background-color: #FFD5DA !important; } + div.pos1 { - border-style: solid !important; - border-width: 2px !important; - border-color: rgba(0, 245, 33, 0.5) !important; + background-color: #e6ffed !important; } + div.pos2 { - border-style: solid !important; - border-width: 2px !important; - border-color: rgba(0, 245, 33, 0.7) !important; + background-color: #BEFECC !important; } + div.neu { - border-style: solid !important; - border-width: 2px !important; - border-color: rgba(0, 78, 245, 0.7) !important; + background-color: #F2F2F2 !important; }