Merge pull request #2 from JasonBarnabe/master
Update from JasonBarnabe
This commit is contained in:
commit
633b09cfbd
|
@ -1,7 +1,13 @@
|
|||
// This happens right away, sometimes so fast that the content script isn't even ready. That's
|
||||
// why the content script also asks for this stuff.
|
||||
chrome.webNavigation.onCommitted.addListener(function(data) {
|
||||
if (data.frameId !== 0) return;
|
||||
// Until Chrome 41, we can't target a frame with a message
|
||||
// (https://developer.chrome.com/extensions/tabs#method-sendMessage)
|
||||
// so a style affecting a page with an iframe will affect the main page as well.
|
||||
// Skip doing this for frames for now, which can result in flicker.
|
||||
if (data.frameId != 0) {
|
||||
return;
|
||||
}
|
||||
getStyles({matchUrl: data.url, enabled: true, asHash: true}, function(styleHash) {
|
||||
chrome.tabs.sendMessage(data.tabId, {method: "styleApply", styles: styleHash});
|
||||
// Don't show the badge for frames
|
||||
|
@ -150,23 +156,23 @@ function sectionAppliesToUrl(section, url) {
|
|||
return false;
|
||||
}
|
||||
if (!section.urls && !section.domains && !section.urlPrefixes && !section.regexps) {
|
||||
console.log(section.id + " is global");
|
||||
//console.log(section.id + " is global");
|
||||
return true;
|
||||
}
|
||||
if (section.urls && section.urls.indexOf(url) != -1) {
|
||||
console.log(section.id + " applies to " + url + " due to URL rules");
|
||||
//console.log(section.id + " applies to " + url + " due to URL rules");
|
||||
return true;
|
||||
}
|
||||
if (section.urlPrefixes && section.urlPrefixes.some(function(prefix) {
|
||||
return url.indexOf(prefix) == 0;
|
||||
})) {
|
||||
console.log(section.id + " applies to " + url + " due to URL prefix rules");
|
||||
//console.log(section.id + " applies to " + url + " due to URL prefix rules");
|
||||
return true;
|
||||
}
|
||||
if (section.domains && getDomains(url).some(function(domain) {
|
||||
return section.domains.indexOf(domain) != -1;
|
||||
})) {
|
||||
console.log(section.id + " applies due to " + url + " due to domain rules");
|
||||
//console.log(section.id + " applies due to " + url + " due to domain rules");
|
||||
return true;
|
||||
}
|
||||
if (section.regexps && section.regexps.some(function(regexp) {
|
||||
|
@ -185,10 +191,10 @@ function sectionAppliesToUrl(section, url) {
|
|||
}
|
||||
return (re).test(url);
|
||||
})) {
|
||||
console.log(section.id + " applies to " + url + " due to regexp rules");
|
||||
//console.log(section.id + " applies to " + url + " due to regexp rules");
|
||||
return true;
|
||||
}
|
||||
console.log(section.id + " does not apply due to " + url);
|
||||
//console.log(section.id + " does not apply due to " + url);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
4
edit.js
4
edit.js
|
@ -19,7 +19,7 @@ function setupCodeMirror(textarea) {
|
|||
mode: 'css',
|
||||
lineNumbers: true,
|
||||
lineWrapping: true,
|
||||
smartIndent: localStorage["smart-indent"] == null || localStorage["smart-indent"] == "true"
|
||||
smartIndent: (typeof localStorage["smart-indent"] == "undefined") || localStorage["smart-indent"] == "true"
|
||||
});
|
||||
editors.push(cm);
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ window.addEventListener("load", init, false);
|
|||
|
||||
function init() {
|
||||
tE("sections-help", "helpAlt", "alt");
|
||||
loadPrefs(["smart-indent"]);
|
||||
loadPrefs({"smart-indent": "true"});
|
||||
var params = getParams();
|
||||
if (!params.id) { // match should be 2 - one for the whole thing, one for the parentheses
|
||||
// This is an add
|
||||
|
|
|
@ -15,7 +15,7 @@ function showStyles(styles) {
|
|||
styles.map(createStyleElement).forEach(function(e) {
|
||||
installed.appendChild(e);
|
||||
});
|
||||
loadPrefs(["show-badge"]);
|
||||
loadPrefs({"show-badge": "true"});
|
||||
}
|
||||
|
||||
function createStyleElement(style) {
|
||||
|
|
|
@ -35,6 +35,10 @@
|
|||
#unavailable {
|
||||
display: none;
|
||||
}
|
||||
/* Never shown, but can be enabled with a style */
|
||||
.enable, .disable {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="localization.js"></script>
|
||||
|
|
5
popup.js
5
popup.js
|
@ -1,5 +1,5 @@
|
|||
var styleTemplate = document.createElement("div");
|
||||
styleTemplate.innerHTML = "<input class='checker' type='checkbox'><div class='style-name'></div><div class='actions'><a class='style-edit-link' href='edit.html?id='>" + t('editStyleLabel') + "</a> <a href='#' class='delete'>" + t('deleteStyleLabel') + "</a></div>";
|
||||
styleTemplate.innerHTML = "<input class='checker' type='checkbox'><div class='style-name'></div><div class='actions'><a href='#' class='enable'>" + t('enableStyleLabel') + "</a> <a href='#' class='disable'>" + t('disableStyleLabel') + "</a> <a class='style-edit-link' href='edit.html?id='>" + t('editStyleLabel') + "</a> <a href='#' class='delete'>" + t('deleteStyleLabel') + "</a></div>";
|
||||
|
||||
var writeStyleTemplate = document.createElement("a");
|
||||
writeStyleTemplate.className = "write-style-link";
|
||||
|
@ -52,6 +52,7 @@ chrome.tabs.getSelected(null, function(tab) {
|
|||
});
|
||||
|
||||
function showStyles(styles) {
|
||||
styles.sort(function(a, b) { return a.name.localeCompare(b.name)});
|
||||
var installed = document.getElementById("installed");
|
||||
if (styles.length == 0) {
|
||||
installed.innerHTML = "<div class='entry' id='no-styles'>" + t('noStylesForSite') + "</div>";
|
||||
|
@ -78,6 +79,8 @@ function createStyleElement(style) {
|
|||
styleName.addEventListener("click", function() { enable(event, !event.target.previousSibling.checked); }, false);
|
||||
// clicking the checkbox will toggle it, and this will run after that happens
|
||||
checkbox.addEventListener("click", function() { enable(event, event.target.checked); }, false);
|
||||
e.querySelector(".enable").addEventListener("click", function() { enable(event, true); }, false);
|
||||
e.querySelector(".disable").addEventListener("click", function() { enable(event, false); }, false);
|
||||
|
||||
e.querySelector(".delete").addEventListener("click", function() { doDelete(event, false); }, false);
|
||||
return e;
|
||||
|
|
|
@ -153,9 +153,10 @@ function changePref(event) {
|
|||
notifyAllTabs({method: "prefChanged", prefName: el.id, value: value});
|
||||
}
|
||||
|
||||
function loadPrefs(prefNames) {
|
||||
prefNames.forEach(function(id) {
|
||||
var value = localStorage[id];
|
||||
// Accepts a hash of pref name to default value
|
||||
function loadPrefs(prefs) {
|
||||
for (var id in prefs) {
|
||||
var value = typeof localStorage[id] == "undefined" ? prefs[id] : localStorage[id];
|
||||
var el = document.getElementById(id);
|
||||
if (isCheckbox(el)) {
|
||||
if (value == "true") {
|
||||
|
@ -165,5 +166,5 @@ function loadPrefs(prefNames) {
|
|||
el.value = value;
|
||||
}
|
||||
el.addEventListener("change", changePref);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user