diff --git a/.gitignore b/.gitignore index 42a12ac..d400ac3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ extension.pem src/big-screenshot.png extension.zip +npm-debug.log +node_modules +extension/citation-needed.js \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 6f6e6b8..0000000 --- a/Makefile +++ /dev/null @@ -1,4 +0,0 @@ - -all: - @rm extension.zip - zip -r extension.zip extension \ No newline at end of file diff --git a/extension/citation-needed.js b/extension/citation-needed.js deleted file mode 100755 index 89d19e6..0000000 --- a/extension/citation-needed.js +++ /dev/null @@ -1,32 +0,0 @@ -(function() { - var m, i, j, c, html, - ps = document.querySelectorAll('p,h1,h2,h3,h4,h5,li'), - reg = /(officials?[^\.,]*? sa(?:y|id)|according to[^\.,]*? officials?|(said) (?:an?|the)[^\.,]*? officials?|condition of anonymity)/g, - 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'+m[j]+''); - } - } - if (c) ps[i].innerHTML = html; - } -})(); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..56b0125 --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/src/citation-needed.js b/src/citation-needed.js new file mode 100755 index 0000000..47626f1 --- /dev/null +++ b/src/citation-needed.js @@ -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'+m[j]+''); + } + } + + if (c) ps[i].innerHTML = html; +} + diff --git a/src/detect.js b/src/detect.js new file mode 100644 index 0000000..5cbc4f5 --- /dev/null +++ b/src/detect.js @@ -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); +}; + diff --git a/test/detection-test.js b/test/detection-test.js new file mode 100644 index 0000000..12baf47 --- /dev/null +++ b/test/detection-test.js @@ -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"]); + }); +}); \ No newline at end of file