-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d71b717
Showing
9 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
A Better Place | ||
============== | ||
|
||
Reading Twitter in the morning can be awful - an endless stream of bad news, anger, and depression. It sets the tone for your day. | ||
|
||
Researchers at Facebook conducted unethical research proving the attitude of social media seriously affects mood for extended periods of time. | ||
|
||
A Better Place is a positivity filter bubble. It uses terrible sentiment analysis to strip out negative Twitter posts from your timeline; hopefully leaving you with a few morsels that make your day tolerable. | ||
|
||
It comes in both [Chrome extension](https://chrome.google.com/webstore/detail/a-better-place/ajihembjdmpchmpcocjlagkfcobmdaog) and bookmarklet flavours, however only the Chrome extension will automatically kick in between the hours of 7am and 11am every day. You can use the bookmarklet whenever you need it. | ||
|
||
Have a nice day. | ||
|
||
Bookmarklet | ||
========= | ||
|
||
Github is terrible and won't let you embed bookmarklets. Create a new bookmark and add the following as the link. | ||
``` | ||
javascript:(function(){ document.body.appendChild(document.createElement('script')).src='https://raw.githack.com/Jonty/abetterplace/master/src/load.js'; })(); | ||
``` | ||
Alternatively there's a draggable link [over on the main site](http://jonty.co.uk/abetterplace). | ||
|
||
Developers | ||
======== | ||
|
||
This is using [AFIN-111](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6010) sentiment analysis, which is awful, but still better than everything else when using twitter. A small amount of the code is taken from [sentiment](https://github.com/thisandagain/sentiment) by [thisandagain](https://github.com/thisandagain). Thanks. | ||
|
||
If you want to play around with this you can see debug logging in the JS console, however Twitter disable it - you can re-enable it by issuing `delete console.log` in the console. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "A Better Place", | ||
"version": "0.0.1", | ||
"manifest_version": 2, | ||
"description": "Hides all negative tweets on twitter.com between the hours of 7am and 11am.", | ||
"homepage_url": "http://jonty.co.uk/abetterplace", | ||
"content_scripts": [ | ||
{ | ||
"matches": [ | ||
"https://twitter.com/*" | ||
], | ||
"js": [ | ||
"src/inject.js" | ||
] | ||
} | ||
], | ||
"web_accessible_resources": ["src/afinn.js", "src/abp.js", "src/run.js"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../src/abp.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../src/afinn.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
chrome.extension.sendMessage({}, function(response) { | ||
var readyStateCheckInterval = setInterval(function() { | ||
if (document.readyState === "complete") { | ||
clearInterval(readyStateCheckInterval); | ||
|
||
var date = new Date(); | ||
var currentHour = date.getHours(); | ||
|
||
if (currentHour >= 7 && currentHour < 11) { | ||
['afinn.js', 'abp.js', 'run.js'].map(function(script) { | ||
var s = document.createElement('script'); | ||
s.src = chrome.extension.getURL('src/' + script); | ||
s.onload = function() { | ||
this.parentNode.removeChild(this); | ||
}; | ||
(document.head||document.documentElement).appendChild(s); | ||
}); | ||
} | ||
|
||
} | ||
}, 10); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
console.log("Load complete, starting ABP..."); | ||
document.styleSheets[0].insertRule("[tweet-is-negative=true]{display:none}", 0); | ||
setInterval(abp_process_tweets, 200); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function abp_tokenise (input) { | ||
return input | ||
.replace(/[^a-zA-Z ]+/g, '') | ||
.replace('/ {2,}/',' ') | ||
.toLowerCase() | ||
.split(' '); | ||
} | ||
|
||
function abp_sentiment (phrase) { | ||
var tokens = abp_tokenise(phrase), | ||
score = 0; | ||
|
||
var len = tokens.length; | ||
while (len--) { | ||
var obj = tokens[len]; | ||
var item = afinn[obj]; | ||
if (typeof item === 'undefined') continue; | ||
|
||
score += item; | ||
} | ||
|
||
return score; | ||
} | ||
|
||
function abp_process_tweets() { | ||
$('.tweet-text').not('.abp_processed').each(function(i, node) { | ||
var score = abp_sentiment(node.textContent); | ||
if (score <= 0) { | ||
console.log('Removing: ' + node.textContent + '(Score: ' + score + ')'); | ||
node.parentNode.parentNode.setAttribute('tweet-is-negative', 'true'); | ||
} else { | ||
console.log('Leaving: ' + node.textContent + '(Score: ' + score + ')'); | ||
} | ||
|
||
node.className = node.className + 'abp_processed'; | ||
}) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(function() { | ||
var scripts = document.getElementsByTagName("script"); | ||
var CurrentScript = scripts[scripts.length-1].src; | ||
|
||
var PathIndex = CurrentScript.lastIndexOf("/") + 1; | ||
var Filepath = CurrentScript.substr(0, PathIndex); | ||
|
||
var d = new Date(); | ||
var n = d.getTime(); | ||
|
||
$.getScript(Filepath + 'afinn.js?' + n).done(function(script, status) { | ||
$.getScript(Filepath + 'abp.js?' + n).done(function(script, status) { | ||
console.log("Load complete, starting ABP..."); | ||
document.styleSheets[0].insertRule("[tweet-is-negative=true]{display:none}", 0); | ||
setInterval(abp_process_tweets, 200); | ||
}) | ||
}) | ||
|
||
})(); |