Permalink
Browse files

ロジックだけ

  • Loading branch information...
1 parent e38b097 commit f8b2d37dc34a766cf28befaf1fdb6b9e7df20b04 @Cside committed Jul 8, 2012
View
@@ -1,21 +0,0 @@
-<html>
-<head>
-<script>
-chrome.extension.onRequest.addListener(function(url, sender, callback) {
- var xhr = new XMLHttpRequest();
- xhr.open('GET', url, true);
- xhr.onreadystatechange = function (e) {
- if (xhr.readyState == 4 && xhr.status == 200) {
- callback(xhr.responseText);
- } else {
- //console.log(xhr);
- return;
- }
- };
- xhr.send(null);
-
-});
-</script>
-</head>
-<body></body>
-</html>
View
@@ -0,0 +1,10 @@
+window.addEventListener('load', function () {
+ chrome.extension.onMessage.addListener(function(req, sender, callback) {
+ if (req.name == 'getContent') {
+ callback({
+ name : 'getContent',
+ responseText: document.documentElement.innerHTML
+ });
+ }
+ });
+}, false);
View
@@ -0,0 +1,36 @@
+chrome.tabs.getSelected(function (tab) {
+ chrome.tabs.sendMessage(tab.id, {name: 'getContent'}, function(res) {
+ if (res.name == 'getContent') {
+ var content = $(res.responseText);
+ var cssUrls = content.filter('link').filter(function () {
+ var link = $(this);
+ return link.attr('type') == 'text/css' ||
+ link.attr('rel') == 'stylesheet';
+ }).map(function () {
+ return $(this).attr('href');
+ });
+ var results = [];
+ $.each(cssUrls, function () {
+ var cssUrl = this;
+ var result = {
+ url : cssUrl,
+ used : [],
+ unused: []
+ };
+ $.get(cssUrl, function (cssContent) {
+ var parser = new CSSParser();
+ var styles = parser.parse(cssContent, false, true).cssRules;
+ $.each(styles, function () {
+ var selector = this.mSelectorText;
+ if (selector && $(selector, content).length) {
+ result.used.push(selector);
+ } else {
+ result.unused.push(selector);
+ }
+ });
+ });
+ console.log(result);
+ });
+ }
+ });
+});
View
Oops, something went wrong.
File renamed without changes.
@@ -0,0 +1,84 @@
+/*
+ * JSDeferred Integration for GoogleChrome.
+ * writtern By Yuichi Tateno <http://github.com/hotchpotch>.
+ *
+ * MIT License.
+ *
+ * examples:
+ * Deferred.chrome.bookmarks.search('Google').next(function(r) {
+ * console.log(r); // BookmarkTreeNode
+ * });
+ *
+ * Deferred.chrome.tabs.create({url: 'http://www.google.com/'}).next(function(tab) {
+ * console.log(tab); // Tab instance
+ * });
+ */
+
+if (typeof Deferred.chrome == 'undefined')
+(function(Deferred) {
+ Deferred.chrome = {};
+
+ Deferred.chrome.registers = function(name, hash) {
+ var chromeTarget = chrome[name];
+ if (!chromeTarget) return console.log('chrome.' + name + ' is not found.');
+ if (typeof Deferred.chrome[name] == 'undefined') Deferred.chrome[name] = {};
+
+ var target = Deferred.chrome[name];
+ for (var key in hash) {
+ if (!chromeTarget[key]) {
+ console.log('chrome.' + name + '.' + key + ' is not found.');
+ continue;
+ }
+ var t = hash[key];
+ target[key] = Deferred.connect(chromeTarget[key], { target: chromeTarget, ok: t[0], ng: t[1] });
+ }
+ }
+
+ Deferred.chrome.registers('tabs', {
+ captureVisibleTab : [1],
+ create : [1],
+ detectLanguage : [1],
+ executeScript : [2],
+ get : [1],
+ getAllInWindow : [1],
+ getSelected : [1],
+ insertCSS : [2],
+ move : [2],
+ remove : [1],
+ update : [2],
+ });
+
+ Deferred.chrome.registers('bookmarks', {
+ create : [1],
+ get : [1],
+ getChildren : [1],
+ getTree : [0],
+ move : [2],
+ remove : [1],
+ removeTree : [0],
+ search : [1],
+ update : [2],
+ });
+
+ Deferred.chrome.registers('windows', {
+ create : [1],
+ get : [1],
+ getAll : [1],
+ getCurrent : [0],
+ getLastFocused : [0],
+ remove : [1],
+ update : [2],
+ });
+
+ Deferred.chrome.registers('i18n', {
+ getAcceptLanguages : [0],
+ });
+
+ Deferred.chrome.registers('toolstrip', {
+ collapse : [1],
+ expand : [1],
+ });
+
+})(Deferred);
+
+
File renamed without changes.
File renamed without changes.
View
@@ -2,10 +2,26 @@
"name": "Unused CSS Class",
"description": "Inspect CSS",
"version": "0.1",
+ "browser_action": {
+ "popup": "popup.html"
+ },
"permissions": [
+ "tabs",
"http://*/*",
"https://*/*"
],
- "background_page": "background.html",
- "option_page": "option.html"
+ "content_scripts": [
+ {
+ "js": [ "content-script.js" ],
+ "run_at": "document_end",
+ "matches": [
+ "http://*/*",
+ "https://*/*"
+ ]
+ }
+ ]
+ //"icons": {
+ // "128": "icon128.png"
+ //},
+ //"background_page": "background.html"
}
View
@@ -1,36 +0,0 @@
-<!DOCTYPE HTML>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
- <title></title>
-</head>
-<body>
- <form action="">
- <input type="text" id="url"/>
- <input type="submit">
- </form>
- <script type="text/javascript" src="./js/underscore.js"></script>
- <script type="text/javascript" src="./js/jquery-1.7.2.min.js"></script>
- <script type="text/javascript" src="./js/jsdeferred.jquery.js"></script>
- <script>
- $(function(){
- $('input[type="submit"]').click(function(){
- var url = $('#url').val();
- if (! /^http/.test(url)) {
- alert('Not a url: ' + url);
- return;
- }
- chrome.extension.sendRequest(url, function(content){
- var css = $(content).filter('link');
- //.filter(function(i, elem){
- // return $(elem).attr('type') == 'text/css'
- // || $(elem).attr('rel') == 'stylesheet';
- //});
- });
-
- return false;
- });
- });
- </script>
-</body>
-</html>
View
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <script type="text/javascript" src="./lib/underscore.js"></script>
+ <script type="text/javascript" src="./lib/jquery-1.7.2.min.js"></script>
+ <script type="text/javascript" src="./lib/jsdeferred.jquery.js"></script>
+ <script type="text/javascript" src="./lib/jsdeferred-googlechrome.js"></script>
+ <script type="text/javascript" src="./lib/cssParser.js"></script>
+ <script type="text/javascript" src="./js/popup.js"></script>
+</head>
+<body>
+ <p>popup</p>
+</body>
+</html>

0 comments on commit f8b2d37

Please sign in to comment.