Skip to content

Commit

Permalink
Merge pull request #18 from CCEM/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
cahudson94 authored Jun 14, 2017
2 parents 2b97a2d + 3efc5e1 commit 16e68e2
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ ENV/
# mypy
.mypy_cache/

.DS_Store
*.DS_Store
8 changes: 5 additions & 3 deletions extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
}
});
34 changes: 30 additions & 4 deletions extension/inject.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
(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;
});
$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'
}
})
Expand Down
15 changes: 10 additions & 5 deletions extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
{
"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",
"background": {
"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" ]
}
],
Expand Down
39 changes: 39 additions & 0 deletions extension/options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<style>
section.options div {
margin: 5px 0;
}
</style>
<title>My Test Extension Options</title>
</head>
<body>
<section class="options">
Comment types to highlight:
<div>
<input type="checkbox" id="positive" name="positive" />
<label for="positive"><span></span>Positive</label>
</div>

<div>
<input type="checkbox" id="neutral" name="neutral" />
<label for="neutral"><span></span>Neutral</label>
</div>

<div>
<input type="checkbox" id="negative" name="negative" />
<label for="negative"><span></span>Negative</label>
</div>

<div>
<input type="checkbox" id="all" name="all" checked />
<label for="all"><span></span>All</label>
</div>
<div id="status"></div>
<button id="save">Save</button>
</section>

<script src="options.js"></script>
</body>
</html>
40 changes: 40 additions & 0 deletions extension/options.js
Original file line number Diff line number Diff line change
@@ -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);
24 changes: 9 additions & 15 deletions extension/styles.css
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 16e68e2

Please sign in to comment.