Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added custom CSS Selector option; Fixed some issues

  • Loading branch information...
commit dd6d7c78db8f8f7ac4c978988b41685cf32be852 1 parent 4268aa5
@overra authored
View
6 extension/background.js
@@ -1,6 +1,7 @@
var raw_url = 'https://raw.github.com/subtlepatterns/SubtlePatterns/master/',
patterns = [],
- page = 0;
+ page = 0,
+ selector;
chrome.extension.onMessage.addListener(function(message, info, cb) {
if (message == 'getPatterns') {
@@ -10,8 +11,9 @@ chrome.extension.onMessage.addListener(function(message, info, cb) {
});
}
else if (message.pattern) {
+ selector = message.selector||'body';
chrome.tabs.insertCSS({
- code: 'body { background-image: url(' + raw_url + message.pattern + ') !important; }'
+ code: selector + ' { background-image: url(' + raw_url + message.pattern + ') !important; }'
});
}
else if (message.page) {
View
17 extension/popup.css
@@ -2,14 +2,24 @@ body {
background: #f0f0f0;
font-family: Helvetica, sans-serif;
font-size: 10pt;
- height: 215px;
+ height: 245px;
margin: 5px;
padding: 0px;
- width: 255px;
+ width: 265px;
+}
+
+.target {
+ height: 25px;
+}
+
+.target #target {
+ outline: none;
+ width: 167px;
}
#patterns {
height: 195px;
+ position: relative;
}
.pattern {
@@ -33,13 +43,14 @@ body {
#details {
position: relative;
- height: 20px;
+ height: 25px;
}
#details button,
#details div {
outline: none;
position: absolute;
+ top: 4px;
}
#details #prev {
View
4 extension/popup.html
@@ -4,6 +4,10 @@
<link rel="stylesheet" href="popup.css">
</head>
<body>
+ <div class="target">
+ <label for="target">CSS Selector:</label>
+ <input type="text" id="target" placeholder="body">
+ </div>
<div id="patterns">
</div>
<div id="details">
View
16 extension/popup.js
@@ -1,8 +1,9 @@
var raw_url = 'https://raw.github.com/subtlepatterns/SubtlePatterns/master/',
patterns_div = document.getElementById('patterns'),
- name_div = document.getElementById('name'),
- next_btn = document.getElementById('next'),
- prev_btn = document.getElementById('prev'),
+ name_div = document.getElementById('name'),
+ next_btn = document.getElementById('next'),
+ prev_btn = document.getElementById('prev'),
+ target_div = document.getElementById('target'),
patterns,
page;
@@ -30,8 +31,8 @@ function loadPatterns() {
pattern = document.createElement('div');
pattern.className = 'pattern';
pattern.style.backgroundImage = 'url(' + raw_url + file.name + ')';
- pattern.style.top = ((x - x%4) / 4) * 65;
- pattern.style.left = (x%4) * 65;
+ pattern.style.top = ((x - x%4) / 4) * 65 + 'px';
+ pattern.style.left = (x%4) * 65 + 'px';
pattern.setAttribute('data-name', file.name);
pattern.onmouseover = function() {
name_div.innerText = this.getAttribute('data-name');
@@ -40,7 +41,10 @@ function loadPatterns() {
name_div.innerText = '';
};
pattern.onclick = function() {
- chrome.extension.sendMessage({pattern: this.getAttribute('data-name')});
+ chrome.extension.sendMessage({
+ pattern: this.getAttribute('data-name'),
+ selector: target_div.value
+ });
};
patterns_div.appendChild(pattern);
}
Please sign in to comment.
Something went wrong with that request. Please try again.