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 @@ + + +
+ +