이전에 jQuery에서 스타일을 모두 (특정 부분이 아님) 검색 할 수있는 무언가를 만들었습니다. .css 파일, 스타일 태그 및 특정 페이지의 내부 스타일. 나는 그것으로 무엇을해야할지 몰랐다. 어쩌면이 스크립트를 어떻게 든 사용할 수있을 것이다. 그것은 모든 시나리오에서 작동하지 않으며 때로는 충분히 테스트하지 않았기 때문에 때로는 약간 버그가 될 것입니다. StackOverflow에는이 코드 조각을 계속 사용할 수있는 다른 사람들이 있을지도 모릅니다. ;)
var all_css = {stylesheets:[], inner_head_styles:[], body_styles:[]};
$(function(){
$.ajaxSetup({
async: true,
crossDomain: true,
dataType: "text",
type: "GET"
});
var calls = [];
/*every non-cross-domain .css file*/
$("head link[rel='stylesheet']").each(function(a, stylesheet){
if($(stylesheet).attr("href").match(/((ftp|http|https):\/\/)?/)[0] == ""){
var css_source = $(stylesheet).attr("href");
var css_call = $.ajax({
url: css_source,
success: function(data){
all_css.stylesheets.push(data);
},
error: function(e, f){
alert(e, f);
}
});
calls.push(css_call);
}
else{
console.log("CSS SOLVER: Cross domain CSS's aren't going to be loaded!");
}
});
/*every head style*/
$("style").each(function(b, style){
all_css.inner_head_styles.push($(this).text());
});
/*every element in the body that has a style attribute*/
$("body[style], body *[style]").each(function(c, style){
var css_html_node = $(style).context.nodeName;
var css_class = typeof($(style).attr("class")) != "undefined" ? "."+$(style).attr("class") : "";
var css_id = typeof($(style).attr("id")) != "undefined" ? "#"+$(style).attr("id") : "";
css_class = css_class.replace(/\s/g, ".");
var css_string = css_html_node + css_id + css_class + "{" + $(style).attr("style") + "}";
all_css.body_styles.push(css_string);
});
$.when.apply(null, calls).done(function(){
console.log(all_css);
});
});
흥미 롭군요. 내가 보는 문제는 스크립트에 의해 삽입 된 스타일이 아닌 스타일 속성 만 검색한다는 것입니다. 대신 계산 된 스타일을 사용하기 위해 약간 수정할 수 있다고 생각합니다. – Christophe
예, 페이지로드 만 검사합니다. 나는 CSS와 함께 존재하는 모든 크로스 브라우저 문제를 제거 할 수있는 하나의 자바 스크립트 파일을 만들려고했다. 일부 자동 CSS 작성기. – Biketire