Last active
December 11, 2015 02:29
-
-
Save mattslack/4531130 to your computer and use it in GitHub Desktop.
A handy Chrome user script that clears out a bunch of visual crap (including some ads) from the Holland Sentinel website.
This file contains hidden or 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
// ==UserScript== | |
// @name Sentinel Cleaner | |
// @version 1.4.14 | |
// @author Matt Slack | |
// @description Depaginates articles, and clears out a bunch of visual crap (including most ads) from the Holland Sentinel website. | |
// @match http://www.hollandsentinel.com/* | |
// ==/UserScript== | |
(function () { | |
"use strict"; | |
var addJQuery, addStylesheetRules, cleanup, init, rules, removeJunk; | |
rules = [ | |
['ins, .ads_header, .float_r, #s_ndn, #top_header, #atfLeader, #popular-stories', | |
['display', 'none'] | |
], | |
['.story', | |
['clear', 'both'], | |
['font-family', '"Adobe Garamond Pro", Garamond, Georgia, serif'], | |
['text-rendering', 'optimizeLegibility'], | |
['font-size', '20px'], | |
['line-height', '1.6'] | |
], | |
['#right_block, .right_block, #left_block', | |
['float', 'none'], | |
['width', 'auto'] | |
], | |
['#searchdiv', | |
['background', '#000'] | |
], | |
['#search_form', | |
['width', '950px'], | |
['margin', '0 auto'] | |
] | |
]; | |
addJQuery = function (callback) { | |
var script = document.createElement("script"); | |
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"); | |
script.addEventListener('load', function () { | |
var script = document.createElement("script"); | |
script.textContent = "(" + callback.toString() + ")();"; | |
document.body.appendChild(script); | |
}, false); | |
document.body.appendChild(script); | |
}; | |
addStylesheetRules = function (decls, style_id) { | |
var style, s, i, j, dl, decl, selector, rulesStr, rl, rule; | |
style = document.createElement('style'); | |
style.id = style_id; | |
document.getElementsByTagName('head')[0].appendChild(style); | |
if (!window.createPopup) { /* For Safari */ | |
style.appendChild(document.createTextNode('')); | |
} | |
s = document.styleSheets[document.styleSheets.length - 1]; | |
for (i = 0, dl = decls.length; i < dl; i++) { | |
j = 1; | |
decl = decls[i]; | |
selector = decl[0]; | |
rulesStr = ''; | |
if (Object.prototype.toString.call(decl[1][0]) === '[object Array]') { | |
decl = decl[1]; | |
j = 0; | |
} | |
for (rl = decl.length; j < rl; j++) { | |
rule = decl[j]; | |
rulesStr += rule[0] + ':' + rule[1] + (rule[2] ? ' !important' : '') + ';\n'; | |
} | |
if (s.insertRule) { | |
s.insertRule(selector + '{' + rulesStr + '}', s.cssRules.length); | |
} | |
else { /* IE */ | |
s.addRule(selector, rulesStr, -1); | |
} | |
} | |
}; | |
removeJunk = function () { | |
var content; | |
$('iframe, ins, #sub_nav, #dyn_street_content, #s_tool, #hot_links, #takeover') | |
.remove(); | |
$('#searchdiv') | |
.insertBefore('#masthead'); | |
if ($('.entry-content-pagination').length && $('.entry-content-print').length ) { | |
$('.entry-content-pagination, #page_nav_container').hide(); | |
$('.entry-content-print').show(); | |
content = $('.entry-content-print').text().replace(/\s+/, ' ').split(/\n/); | |
$('.entry-content-print').empty(); | |
for (i = 0; i < content.length; i++){ | |
if (!content[i].match(/^\s+$/)){ | |
$('<p>' + content[i] + '</p>').appendTo('.entry-content-print'); | |
} | |
} | |
} | |
}; | |
cleanup = function () { | |
if ( document.readyState === "complete" ) { | |
document.removeEventListener('readystatechange', init); | |
if ( typeof(jQuery) == "undefined" ) { | |
addJQuery(removeJunk); | |
} else { | |
removeJunk(); | |
} | |
} | |
}; | |
init = function () { | |
var frames, i; | |
document.addEventListener('readystatechange', cleanup); | |
addStylesheetRules(rules, 'cleaner_style'); | |
frames = document.getElementsByTagName('iframe'); | |
for (i = 0; i < frames.length; i++ ){ frames[i].parentNode.removeChild(frames[i]); } | |
}; | |
init(); | |
}()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment