What I want to achieve is to make the user define specific stylesheets to be processed by a JavaScript file i wrote and here is the code i used to get the specified stylesheets :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="sheet-1.css">
<link rel="stylesheet" href="sheet-2.css">
<link rel="stylesheet" href="sheet-3.css">
<!-- other css files -->
<style>
/* inline styles */
</style>
</head>
<body>
<script src="jquery-2.1.1.min.js"></script>
<!-- some plugins -->
<script>
jQuery(document).ready(function($) {
// user specified stylesheets
var watchedStyleSheetsNames = [ 'sheet-1.css', 'sheet-2.css', 'sheet-3.css' ]
var allSheets = document.styleSheets,
targetSheets = [];
for ( var i = watchedStyleSheetsNames.length - 1; i >= 0; i--) {
Object.keys( allSheets ).forEach ( function (j) {
if( allSheets[j].href && allSheets[j].href.indexOf( watchedStyleSheetsNames[i] ) !== -1 ) {
targetSheets.push(allSheets[j]);
}
});
};
// result
console.log( 'Watched Stylesheets Array : ' + targetSheets );
});
</script>
</body>
</html>
The problem is everything works just fine with the first time page load and then after 3 to 5 refreshes the array of targetSheets
returns empty value which obviously ruins everything done after that then after refreshing another time I get the expected value and so on. I tried with all browsers, cleared my cache the same thing happens again and again. here is an image of what i get in my console:
https://www.dropbox.com/s/ipnc20hcdr3d6wl/01.png?dl=0
I tested my code online & locally using wamp server with the latest versions of all browsers. So what causes this problem and how can I fix it ?
Thanks for your time.
Edit
I found the answer it was because implementing prefixfree plugin which remove the link nodes and then reinsert the processed css in style tags.