I have successfully developed a script that accomplishes exactly what you requested: it conceals screen-only styles and converts print-only styles to be screen-only.
To implement this functionality, you will need to inject the following JavaScript using Selenium:
(function simulatePrint() {
//Function to check if a style is specified for a particular media
function hasMedia(list, media) {
if (!list) return false;
var i = list.length;
while (i--) {
if (list[i] === media) {
return true;
}
}
return false;
}
//Iterate through all the stylesheets
for (var sheetNumber = 0; sheetNumber < document.styleSheets.length; sheetNumber++) {
//Current stylesheet being processed
var currentSheet = document.styleSheets[sheetNumber];
//Output debug information
console.info("Stylesheet #" + sheetNumber + ":");
console.log(currentSheet);
//First, verify if any media queries are defined on the <style> / <link> tag
//Disable screen-only stylesheets
if (hasMedia(currentSheet.media, "screen") && !hasMedia(currentSheet.media, "print")) {
currentSheet.disabled = true;
}
//Show "print" stylesheets
if (!hasMedia(currentSheet.media, "screen") && hasMedia(currentSheet.media, "print")) {
//Add "screen" media query to display on screen
currentSheet.media.appendMedium("screen");
}
// Obtain the CSS rules in a cross-browser compatible manner
var cssRules;
try {
cssRules = currentSheet.cssRules;
} catch (error) {
console.log(error);
}
try {
cssRules = currentSheet.rules;
} catch (error) {
console.log(error);
}
// Handle cases where currentSheet.rules is null
if (!cssRules) {
continue;
}
//Secondly, iterate through all the rules in a stylesheet
for (var ruleIndex = 0; ruleIndex < cssRules.length; ruleIndex++) {
//Current rule being inspected
var currentRule = cssRules[ruleIndex];
//Hide screen-only rules
if (hasMedia(currentRule.media, "screen") && !hasMedia(currentRule.media, "print")) {
//Since Rule.disabled doesn't work, we manipulate the media type to remove "screen" and add "print" so it remains hidden
console.info('Rule.media:');
console.log(currentRule.media)
currentRule.media.appendMedium(':not(screen)');
currentRule.media.deleteMedium('screen');
console.info('Modified Rule.media:');
console.log(currentRule.media)
}
//Display "print" rules
if (!hasMedia(currentRule.media, "screen") && hasMedia(currentRule.media, "print")) {
//Add "screen" media to show on screen
currentRule.media.appendMedium("screen");
}
}
}
})()
You can view a live demonstration of this script on JSFiddle.
Bookmarklet Feature
You also have the option to install it as a bookmarklet.
Additional Resources:
Please Note: This script has only been tested on Google Chrome and Mozilla Firefox. Compatibility with other browsers may vary.