Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
extension.pem
src/big-screenshot.png
extension.zip
npm-debug.log
node_modules
extension/citation-needed.js
4 changes: 0 additions & 4 deletions Makefile

This file was deleted.

32 changes: 0 additions & 32 deletions extension/citation-needed.js

This file was deleted.

27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "citation-needed",
"version": "1.0.0",
"description": "Chrome extension that highlights anonymous sources in news articles",
"scripts": {
"test": "mocha test/*.js",
"tdd": "mocha --watch test/*.js",
"dev": "webpack --watch -d --output-filename extension/citation-needed.js --entry ./src/citation-needed.js --no-output-source-map-file",
"build": "webpack -p -d --output-filename extension/citation-needed.js --entry ./src/citation-needed.js --no-output-source-map-file",
"package": "rm -f extension.zip && npm run build && zip -r extension.zip extension"
},
"repository": {
"type": "git",
"url": "git+https://github.com/gka/citation-needed.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/gka/citation-needed/issues"
},
"homepage": "https://github.com/gka/citation-needed#readme",
"devDependencies": {
"mocha": "^2.2.5",
"webpack": "^1.10.5"
}
}
38 changes: 38 additions & 0 deletions src/citation-needed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var detect = require('./detect');

var m, i, j, c, html,
ps = document.querySelectorAll('p,h1,h2,h3,h4,h5,li'),
css = 'p > span.citation-needed {' +
"background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAGCAYAAAD+Bd/7AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHFJREFUeNpUjWENgCAUhA/mfyNIJAOwqQ1soEZx0kMjGEEbSILngc9N2T72+O4AyIKLjCKCH8kxswBKMiCYHu8Kps6OmUlNPUTitLKTikwmPccbh4pZCw054cUVKlqyaoCPg82jl417p9/EPD8OtwADAOKnLmQFLo8dAAAAAElFTkSuQmCC') bottom repeat-x;" +
'background-size: 4px 3px; ' +
' }\np > span.citation-needed:hover:after {' +
' content: "[citation needed]"; font-size: 70%;'+
' position: relative; top: -0.5em; font-family: sans-serif;' +
' font-style: italic; opacity: 0.5;' +
' }',
style = document.createElement('style');

style.type = 'text/css';

if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}

document.head.appendChild(style);

for (i=0; i<ps.length; i++) {
html = ps[i].innerHTML;
c = false;

if ((m = detect(html))) {
c = true;
for (j=0; j<m.length; j++) {
html = html.replace(m[j], '<span class="citation-needed">'+m[j]+'</span>');
}
}

if (c) ps[i].innerHTML = html;
}

6 changes: 6 additions & 0 deletions src/detect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var exp = /(officials?[^\.,]*? sa(?:y|id)|according to[^\.,]*? officials?|(said) (?:an?|the)[^\.,]*? officials?|condition of anonymity)/g;

module.exports = function detect(str) {
return str.match(exp);
};

9 changes: 9 additions & 0 deletions test/detection-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var assert = require('assert');
var detect = require('../src/detect');

describe('citation needed', function() {
it('should detect anonymous citations', function() {
assert.deepEqual(detect(", officials say in the"), ["officials say"]);
assert.deepEqual(detect("said on the condition of anonymity"), ["condition of anonymity"]);
});
});