import experimental code
This commit is contained in:
parent
99742fb2d4
commit
0605fae012
BIN
icon128.xcf
Normal file
BIN
icon128.xcf
Normal file
Binary file not shown.
0
src/background.html
Normal file
0
src/background.html
Normal file
15
src/background.js
Normal file
15
src/background.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
chrome.browserAction.onClicked.addListener(function(tab) {
|
||||
var url = chrome.extension.getURL("printScreen.js");
|
||||
var code = injectScript(url);
|
||||
|
||||
chrome.tabs.executeScript(tab.id, {
|
||||
code: code,
|
||||
allFrames: true
|
||||
});
|
||||
});
|
||||
|
||||
function injectScript(url) {
|
||||
return 'var script = document.createElement("script");' +
|
||||
'script.src = "' + url + '";' +
|
||||
'(document.head||document.documentElement).appendChild(script);'
|
||||
}
|
BIN
src/images/icon128.png
Normal file
BIN
src/images/icon128.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
BIN
src/images/icon19.png
Normal file
BIN
src/images/icon19.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 799 B |
BIN
src/images/icon38.png
Normal file
BIN
src/images/icon38.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
25
src/manifest.json
Normal file
25
src/manifest.json
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"manifest_version": 2,
|
||||
|
||||
"name": "PrintScreen",
|
||||
"description": "PrintScreen for Chrome. Print what you see.",
|
||||
"version": "1.0.0",
|
||||
"permissions": [ "tabs", "http://*/*", "https://*/*" ],
|
||||
|
||||
"icons": {
|
||||
"128": "images/icon128.png"
|
||||
},
|
||||
|
||||
"background": {
|
||||
"scripts": ["background.js"]
|
||||
},
|
||||
|
||||
"browser_action": {
|
||||
"default_icon": {
|
||||
"19": "images/icon19.png",
|
||||
"38": "images/icon38.png"
|
||||
},
|
||||
"default_title": "Print Screen"
|
||||
},
|
||||
"web_accessible_resources": [ "printScreen.js" ]
|
||||
}
|
36
src/printScreen.js
Normal file
36
src/printScreen.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
function __PrintScreen__removePrintMedia() {
|
||||
function isPrintQuery(mediaText) {
|
||||
var media = mediaText.toLowerCase();
|
||||
// not the greatest logic, but basically look for print rules that do not also include screen
|
||||
return media.indexOf('print') >= 0 && !isScreenQuery(media);
|
||||
}
|
||||
|
||||
function isScreenQuery(mediaText) {
|
||||
var media = mediaText.toLowerCase();
|
||||
return media.indexOf('screen') >= 0;
|
||||
}
|
||||
|
||||
function convertMedia(media) {
|
||||
if(media && media.mediaText) {
|
||||
if(isPrintQuery(media.mediaText)) {
|
||||
media.mediaText = media.mediaText.replace(/print/i, "not all");
|
||||
}else if(isScreenQuery(media.mediaText)) {
|
||||
media.mediaText = media.mediaText.replace(/screen/i, "all");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function convertStyleSheet(stylesheet) {
|
||||
convertMedia(stylesheet.media);
|
||||
for(var i=0; i<stylesheet.rules.length; i++) {
|
||||
convertMedia(stylesheet.rules[i].media);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var stylesheets = document.styleSheets;
|
||||
for(var i=0; i<stylesheets.length; i++) {
|
||||
convertStyleSheet(stylesheets[i]);
|
||||
}
|
||||
}
|
||||
__PrintScreen__removePrintMedia();
|
1
test/.gemrc
Normal file
1
test/.gemrc
Normal file
|
@ -0,0 +1 @@
|
|||
gem: --no-ri --no-rdoc
|
1
test/config.ru
Normal file
1
test/config.ru
Normal file
|
@ -0,0 +1 @@
|
|||
run Rack::File.new("./")
|
24
test/test.html
Normal file
24
test/test.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="testScreen.css" media="screen" />
|
||||
<link rel="stylesheet" href="testPrint.css" media="print" />
|
||||
<link rel="stylesheet" href="testAll.css" media="screen,print" />
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
|
||||
<style>
|
||||
div { display: none; }
|
||||
</style>
|
||||
<script>
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div class="screen-media">Screen Only Text</div>
|
||||
<div class="print-media">Print Only Text</div>
|
||||
<div class="anymedia">Any Media Text</div>
|
||||
<div class="any-screen-media">Included as any, but media query in css</div>
|
||||
<div class="any-print-media">Included as any, but print query in css</div>
|
||||
<div class="any-screen-sized-media">Included as any, but screen query in css, also a size query as part of the screen query</div>
|
||||
</body>
|
||||
</html>
|
29
test/testAll.css
Normal file
29
test/testAll.css
Normal file
|
@ -0,0 +1,29 @@
|
|||
.anymedia {
|
||||
display: block;
|
||||
color: red;
|
||||
}
|
||||
|
||||
.second-any-media-rule {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media screen {
|
||||
.any-screen-media {
|
||||
display: block;
|
||||
color: green;
|
||||
}
|
||||
}
|
||||
|
||||
@media print {
|
||||
.any-print-media {
|
||||
display: block;
|
||||
color: orange;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 400px) and (max-width: 2700px) {
|
||||
.any-screen-sized-media {
|
||||
display: block;
|
||||
color: aqua;
|
||||
}
|
||||
}
|
8
test/testPrint.css
Normal file
8
test/testPrint.css
Normal file
|
@ -0,0 +1,8 @@
|
|||
.print-media {
|
||||
color: black;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.second-print-media-rule {
|
||||
display:none;
|
||||
}
|
6
test/testScreen.css
Normal file
6
test/testScreen.css
Normal file
|
@ -0,0 +1,6 @@
|
|||
.screen-media {
|
||||
display: block;
|
||||
color: blue;
|
||||
}
|
||||
|
||||
.second-screen-media-rule { display: none; }
|
Loading…
Reference in New Issue
Block a user