Skip to content

Instantly share code, notes, and snippets.

@johan
Created November 22, 2016 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johan/197f3c8bde5b2180392e280935af79b4 to your computer and use it in GitHub Desktop.
Save johan/197f3c8bde5b2180392e280935af79b4 to your computer and use it in GitHub Desktop.
Somewhat improved version of Fake News Alert extension 0.1.2 from https://chrome.google.com/webstore/detail/fake-news-alert/aickfmgnhocegpdbfnpfnedpeionfkbh/related – to mark links directly at Facebook before you even click through them.
// alert.js
const stripes = document.createElement('div');
stripes.style.cssText = `
height: 20px;
width: 100%;
position: fixed;
z-index: 99999;
opacity: 0.7;
pointer-events: none;
background-image: repeating-linear-gradient(
-45deg, #000, #000 20px, #df0 20px, #df0 40px
);
`;
const banner = document.createElement('span');
banner.textContent = `Claims on this site are often false or misleading!`;
banner.style.cssText = `
font-family: 'Lucida Console', Monaco, monospace;
color: white;
margin: auto;
background: black;
display: block;
width: 500px;
height: 20px;
line-height: 20px;
text-align: center;
font-size: 14px;
`;
stripes.appendChild(banner);
document.body.insertBefore(stripes, document.body.firstChild);
// facebook.js
const normalize = (domain) => domain.toLowerCase().replace(/^www\./, '');
const isMatch = (domain) => {
if (!isMatch.domains) {
const manifest = chrome.runtime.getManifest();
isMatch.domains = manifest.content_scripts[0].matches.map(s =>
normalize(s.replace(/^\*:\/\/(?:\*\.)?([^/]*).*/, '$1'))
);
}
return isMatch.domains.indexOf(domain) !== -1;
};
const flag = (div) => {
div.classList.add('fake-news-checked'); // only check each link once
let domain = div.firstChild.nodeValue;
if (!domain) { // also handle <span class="highlightNode">domain</span>:
domain = div.firstElementChild.firstChild.nodeValue;
}
if (!isMatch(normalize(domain))) {
// console.info(`skipped ${domain}`);
return;
}
// console.info(`flagged ${domain}`);
const root = div.parentNode.parentNode.parentNode.parentNode;
const stripes = document.createElement('div');
stripes.style.cssText = `
position: absolute;
height: 28px;
bottom: 0px;
right: 0;
left: 0;
pointer-events: none;
background: repeating-linear-gradient(
-45deg, #000, #000 20px, #df0 20px, #df0 40px
);
`;
const warn = document.createElement('div');
warn.textContent = 'SITE OFTEN FALSE OR MISLEADING';
warn.style.cssText = `
right: 8px;
bottom: 8px;
text-align: right;
position: absolute;
font-size: 11px;
color: red;
text-shadow:
-1px -1px 0 #000,
-1px 0 0 #000,
-1px 1px 0 #000,
0 -1px 0 #000,
0 1px 0 #000,
1px -1px 0 #000,
1px 0 0 #000,
1px 1px 0 #000;
`;
stripes.appendChild(warn);
root.insertBefore(stripes, root.firstChild);
};
flagNew = () => {
document.querySelectorAll('._6lz._6mb:not(.fake-news-checked)').forEach(flag);
};
// initial page sweep
flagNew();
// capture infinite-scroll-added content, too
setInterval(flagNew, 1e3);
{ "browser_action":
{ "default_icon": "icons/icon48.png"
}
, "content_scripts":
[ { "js":
[ "alert.js"
]
, "matches":
[ "*://*.100percentfedup.com/*"
, "*://*.21stcenturywire.com/*"
, "*://*.70news.wordpress.com/*"
, "*://*.abcnews.com.co/*"
, "*://*.activistpost.com/*"
, "*://*.addictinginfo.org/*"
, "*://*.americannewsx.com/*"
, "*://*.samericannews.com/*"
, "*://*.anonnews.co/*"
, "*://*.associatedmediacoverage.com/*"
, "*://*.beforeitsnews.com/*"
, "*://*.beingliberal.org/*"
, "*://*.bigamericannews.com/*"
, "*://*.bigpzone.com/*"
, "*://*.bipartisanreport.com/*"
, "*://*.www.bizpacreview.com/*"
, "*://*.bluenationreview.com/*"
, "*://*.www.breitbart.com/*"
, "*://*.thebostontribune.com/*"
, "*://*.cap-news.com/*"
, "*://*.christwire.org/*"
, "*://*.chronicle.su/*"
, "*://*.civictribune.com/*"
, "*://*.coasttocoastam.com/*"
, "*://*.collectiveevolution/*"
, "*://*.consciouslifenews.com/*"
, "*://*.conservativeoutfitters.com/*"
, "*://*.wideawakeamerica.com/*"
, "*://*.countdowntozerotime.com/*"
, "*://*.counterpsyops.com/*"
, "*://*.creambmp.com/*"
, "*://*.dailybuzzlive.com/*"
, "*://*.dailycurrant.com/*"
, "*://*.dailywire.com/*"
, "*://*.dcclothesline.com/*"
, "*://*.dcgazette.com/*"
, "*://*.denverguardian.com/*"
, "*://*.derfmagazine.com/*"
, "*://*.disclose.tv/*"
, "*://*.drudgereport.com.co/*"
, "*://*.duffleblog.com/*"
, "*://*.duhprogressive.com/*"
, "*://*.embols.com/*"
, "*://*.empireherald.com/*"
, "*://*.empirenews.com/*"
, "*://*.endingthefed.com/*"
, "*://*.enduringvision.com/*"
, "*://*.fprnradio.com/*"
, "*://*.thefreethoughtproject.com/*"
, "*://*.geoengineeringwatch.org/*"
, "*://*.govtslaves.info/"
, "*://*.gulagbound.com/"
, "*://*.hangthebankers.com/*"
, "*://*.humansarefree.com/*"
, "*://*.huzlers.com/*"
, "*://*.ifyouonlynews.com/*"
, "*://*.infowars.com/*"
, "*://*.intellihub.com/*"
, "*://*.inquisitor.com/*"
, "*://*.jonesreport.com/*"
, "*://*.lewrockwell.com/*"
, "*://*.liberalamerica.org/*"
, "*://*.libertytalk.fm/*"
, "*://*.libertyunyielding.com/*"
, "*://*.libertyvideos.org/*"
, "*://*.mediamass.net/*"
, "*://*.megynkelly.us/*"
, "*://*.msnbc.com.co/*"
, "*://*.msnbc.website/*"
, "*://*.nahadaily.com/*"
, "*://*.nationalreport.net/*"
, "*://*.naturalnews.com/*"
, "*://*.nbc-news.net/*"
, "*://*.ncscooper.com/*"
, "*://*.newcenturytimes.com/*"
, "*://*.newsexaminer.net/*"
, "*://*.news-hound.com/*"
, "*://*.newsbiscuit.com/*"
, "*://*.newsbuzzdaily.com/*"
, "*://*.newslo.com/*"
, "*://*.newsmutiny.com/*"
, "*://*.newswatch28.com/*"
, "*://*.opposingviews.com/*"
, "*://*.newswire-24.com/*"
, "*://*.now8news.com/*"
, "*://*.nowtheendbegins.com/*"
, "*://*.occupydemocrats.com/*"
, "*://*.www.pakalertpress.com/*"
, "*://*.politicalblindspot.com/*"
, "*://*.politicalears.com/*"
, "*://*.politicalo.com/*"
, "*://*.politicususa.com/*"
, "*://*.prisonplanet.com/*"
, "*://*.private-eye.co.uk/*"
, "*://*.projectveritas.com/*"
, "*://*.react365.com/*"
, "*://*.realfarmacy.com/*"
, "*://*.realnewsrightnow.com/*"
, "*://*.redflagnews.com/*"
, "*://*.redstate.com/*"
, "*://*.rilenews.com/*"
, "*://*.satiratribune.com/*"
, "*://*.theblaze.com/*"
, "*://*.thefreethoughtproject.com/*"
, "*://*.newyorker.com/humor/borowitz-report/*"
, "*://*.other98.com/*"
, "*://*.www.reporter.bz/*"
, "*://*.www.thestatelyharold.com/*"
, "*://*.www.thedailysheeple.com/*"
, "*://*.www.thenewsnerd.com/*"
, "*://*.therundownlive.com/*"
, "*://*.theuspatriot.com/*"
, "*://*.truthfrequencyradio.com/*"
, "*://*.twitchy.com/*"
, "*://*.unconfirmedsources.com/*"
, "*://*.usasupreme.com/*"
, "*://*.blastingnews.com/*"
, "*://*.usuncut.com/*"
, "*://*.www.veteranstoday.com/*"
, "*://*.wakingupwisconsin.com/*"
, "*://*.winningdemocrats.com/*"
, "*://*.witscience.org/*"
, "*://*.www.wnd.com/*"
, "*://*.worldnewsdailyreport.com/*"
, "*://*.worldtruth.tv/*"
, "*://*.zerohedge.com/*"
]
}
, { "js":
[ "facebook.js"
]
, "matches":
[ "*://*.facebook.com/*"
]
}
]
, "default_locale": "en"
, "description": "Alerts you if you are viewing a fake news site"
, "homepage_url": "http://nymag.com/"
, "icons":
{ "128": "icons/icon128.png"
}
, "manifest_version": 2
, "minimum_chrome_version": "22.0.0.0"
, "name": "Fake News Alert"
, "version": "0.2.0"
}
@johan
Copy link
Author

johan commented Nov 22, 2016

Subsequent better update in https://github.com/bfeldman/fake-site-alert/pull/19 – now that I found the extension's origin source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment