Created
November 24, 2012 22:11
-
-
Save NV/4141606 to your computer and use it in GitHub Desktop.
Append style rules created in elements panel to last included CSS file
This file contains 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
<script src="devtools.js"></script> |
This file contains 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
var styleSheets = []; | |
function addStyleSheet(resource) { | |
if (resource.type === 'stylesheet' && resource.url.lastIndexOf('inspector://', 0) === -1) { | |
console.log('Add', resource.url); | |
styleSheets.push(resource); | |
} | |
} | |
chrome.devtools.inspectedWindow.getResources(function(resources) { | |
console.log('getResources'); | |
resources.forEach(addStyleSheet); | |
}); | |
chrome.devtools.inspectedWindow.onResourceAdded.addListener(function(resource) { | |
console.log('onResourceAdded', resource.url); | |
addStyleSheet(resource); | |
}); | |
chrome.devtools.inspectedWindow.onResourceContentCommitted.addListener(function(resource, content) { | |
if (resource.url.lastIndexOf('inspector://', 0) === -1) | |
return; | |
if (styleSheets.length === 0) | |
return; | |
var lastStyleSheet = styleSheets[styleSheets.length - 1]; | |
lastStyleSheet.getContent(function(oldContent) { | |
lastStyleSheet.setContent(oldContent + '\n\n' + content, true); | |
resource.setContent('', false); | |
}); | |
}); | |
chrome.devtools.network.onNavigated.addListener(function() { | |
console.log('onNavigated'); | |
styleSheets = []; | |
}); |
This file contains 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
{ | |
"name": "New styles pipe", | |
"version": "1.0.0", | |
"description": "Pipe newly created styles to last included CSS file", | |
"devtools_page": "devtools.html", | |
"manifest_version": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment