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
|
// 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.
|
// why the content script also asks for this stuff.
|
||||||
chrome.webNavigation.onCommitted.addListener(function(data) {
|
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) {
|
getStyles({matchUrl: data.url, enabled: true, asHash: true}, function(styleHash) {
|
||||||
chrome.tabs.sendMessage(data.tabId, {method: "styleApply", styles: styleHash});
|
chrome.tabs.sendMessage(data.tabId, {method: "styleApply", styles: styleHash});
|
||||||
// Don't show the badge for frames
|
// Don't show the badge for frames
|
||||||
|
@ -150,23 +156,23 @@ function sectionAppliesToUrl(section, url) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!section.urls && !section.domains && !section.urlPrefixes && !section.regexps) {
|
if (!section.urls && !section.domains && !section.urlPrefixes && !section.regexps) {
|
||||||
console.log(section.id + " is global");
|
//console.log(section.id + " is global");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (section.urls && section.urls.indexOf(url) != -1) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
if (section.urlPrefixes && section.urlPrefixes.some(function(prefix) {
|
if (section.urlPrefixes && section.urlPrefixes.some(function(prefix) {
|
||||||
return url.indexOf(prefix) == 0;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
if (section.domains && getDomains(url).some(function(domain) {
|
if (section.domains && getDomains(url).some(function(domain) {
|
||||||
return section.domains.indexOf(domain) != -1;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
if (section.regexps && section.regexps.some(function(regexp) {
|
if (section.regexps && section.regexps.some(function(regexp) {
|
||||||
|
@ -185,10 +191,10 @@ function sectionAppliesToUrl(section, url) {
|
||||||
}
|
}
|
||||||
return (re).test(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;
|
return true;
|
||||||
}
|
}
|
||||||
console.log(section.id + " does not apply due to " + url);
|
//console.log(section.id + " does not apply due to " + url);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
edit.js
4
edit.js
|
@ -19,7 +19,7 @@ function setupCodeMirror(textarea) {
|
||||||
mode: 'css',
|
mode: 'css',
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
lineWrapping: 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);
|
editors.push(cm);
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ window.addEventListener("load", init, false);
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
tE("sections-help", "helpAlt", "alt");
|
tE("sections-help", "helpAlt", "alt");
|
||||||
loadPrefs(["smart-indent"]);
|
loadPrefs({"smart-indent": "true"});
|
||||||
var params = getParams();
|
var params = getParams();
|
||||||
if (!params.id) { // match should be 2 - one for the whole thing, one for the parentheses
|
if (!params.id) { // match should be 2 - one for the whole thing, one for the parentheses
|
||||||
// This is an add
|
// This is an add
|
||||||
|
|
|
@ -15,7 +15,7 @@ function showStyles(styles) {
|
||||||
styles.map(createStyleElement).forEach(function(e) {
|
styles.map(createStyleElement).forEach(function(e) {
|
||||||
installed.appendChild(e);
|
installed.appendChild(e);
|
||||||
});
|
});
|
||||||
loadPrefs(["show-badge"]);
|
loadPrefs({"show-badge": "true"});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createStyleElement(style) {
|
function createStyleElement(style) {
|
||||||
|
|
|
@ -35,6 +35,10 @@
|
||||||
#unavailable {
|
#unavailable {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
/* Never shown, but can be enabled with a style */
|
||||||
|
.enable, .disable {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script src="localization.js"></script>
|
<script src="localization.js"></script>
|
||||||
|
|
5
popup.js
5
popup.js
|
@ -1,5 +1,5 @@
|
||||||
var styleTemplate = document.createElement("div");
|
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");
|
var writeStyleTemplate = document.createElement("a");
|
||||||
writeStyleTemplate.className = "write-style-link";
|
writeStyleTemplate.className = "write-style-link";
|
||||||
|
@ -52,6 +52,7 @@ chrome.tabs.getSelected(null, function(tab) {
|
||||||
});
|
});
|
||||||
|
|
||||||
function showStyles(styles) {
|
function showStyles(styles) {
|
||||||
|
styles.sort(function(a, b) { return a.name.localeCompare(b.name)});
|
||||||
var installed = document.getElementById("installed");
|
var installed = document.getElementById("installed");
|
||||||
if (styles.length == 0) {
|
if (styles.length == 0) {
|
||||||
installed.innerHTML = "<div class='entry' id='no-styles'>" + t('noStylesForSite') + "</div>";
|
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);
|
styleName.addEventListener("click", function() { enable(event, !event.target.previousSibling.checked); }, false);
|
||||||
// clicking the checkbox will toggle it, and this will run after that happens
|
// clicking the checkbox will toggle it, and this will run after that happens
|
||||||
checkbox.addEventListener("click", function() { enable(event, event.target.checked); }, false);
|
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);
|
e.querySelector(".delete").addEventListener("click", function() { doDelete(event, false); }, false);
|
||||||
return e;
|
return e;
|
||||||
|
|
|
@ -153,9 +153,10 @@ function changePref(event) {
|
||||||
notifyAllTabs({method: "prefChanged", prefName: el.id, value: value});
|
notifyAllTabs({method: "prefChanged", prefName: el.id, value: value});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadPrefs(prefNames) {
|
// Accepts a hash of pref name to default value
|
||||||
prefNames.forEach(function(id) {
|
function loadPrefs(prefs) {
|
||||||
var value = localStorage[id];
|
for (var id in prefs) {
|
||||||
|
var value = typeof localStorage[id] == "undefined" ? prefs[id] : localStorage[id];
|
||||||
var el = document.getElementById(id);
|
var el = document.getElementById(id);
|
||||||
if (isCheckbox(el)) {
|
if (isCheckbox(el)) {
|
||||||
if (value == "true") {
|
if (value == "true") {
|
||||||
|
@ -165,5 +166,5 @@ function loadPrefs(prefNames) {
|
||||||
el.value = value;
|
el.value = value;
|
||||||
}
|
}
|
||||||
el.addEventListener("change", changePref);
|
el.addEventListener("change", changePref);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user