commit
c7e7bbe5d1
27
popup.js
27
popup.js
|
@ -122,12 +122,12 @@ function createStyleElement(style) {
|
||||||
var styleName = e.querySelector(".style-name");
|
var styleName = e.querySelector(".style-name");
|
||||||
styleName.appendChild(document.createTextNode(style.name));
|
styleName.appendChild(document.createTextNode(style.name));
|
||||||
styleName.setAttribute("for", "style-" + style.id);
|
styleName.setAttribute("for", "style-" + style.id);
|
||||||
|
styleName.checkbox = checkbox;
|
||||||
var editLink = e.querySelector(".style-edit-link");
|
var editLink = e.querySelector(".style-edit-link");
|
||||||
editLink.setAttribute("href", editLink.getAttribute("href") + style.id);
|
editLink.setAttribute("href", editLink.getAttribute("href") + style.id);
|
||||||
editLink.addEventListener("click", openLinkInTabOrWindow, false);
|
editLink.addEventListener("click", openLinkInTabOrWindow, false);
|
||||||
|
|
||||||
// the checkbox will not toggle itself after clicking the name, but calling enable will regenerate it
|
styleName.addEventListener("click", function() { this.checkbox.click(); event.preventDefault(); });
|
||||||
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(".enable").addEventListener("click", function() { enable(event, true); }, false);
|
||||||
|
@ -181,6 +181,7 @@ function openLinkInTabOrWindow(event) {
|
||||||
} else {
|
} else {
|
||||||
openLink(event);
|
openLink(event);
|
||||||
}
|
}
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
function openLink(event) {
|
function openLink(event) {
|
||||||
|
@ -193,10 +194,14 @@ function handleUpdate(style) {
|
||||||
var styleElement = installed.querySelector("[style-id='" + style.id + "']");
|
var styleElement = installed.querySelector("[style-id='" + style.id + "']");
|
||||||
if (styleElement) {
|
if (styleElement) {
|
||||||
installed.replaceChild(createStyleElement(style), styleElement);
|
installed.replaceChild(createStyleElement(style), styleElement);
|
||||||
} else if (chrome.extension.getBackgroundPage().getApplicableSections(style, location.href).length) {
|
} else {
|
||||||
// a new style for the current url is installed
|
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
|
||||||
document.getElementById("unavailable").style.display = "none";
|
if (tabs.length && chrome.extension.getBackgroundPage().getApplicableSections(style, tabs[0].url).length) {
|
||||||
installed.appendChild(createStyleElement(style));
|
// a new style for the current url is installed
|
||||||
|
document.getElementById("unavailable").style.display = "none";
|
||||||
|
installed.appendChild(createStyleElement(style));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,15 +219,18 @@ function handleDisableAll(disableAll) {
|
||||||
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
|
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
|
||||||
if (request.method == "updatePopup") {
|
if (request.method == "updatePopup") {
|
||||||
switch (request.reason) {
|
switch (request.reason) {
|
||||||
|
case "styleAdded":
|
||||||
case "styleUpdated":
|
case "styleUpdated":
|
||||||
handleUpdate(request.style);
|
handleUpdate(request.style);
|
||||||
break;
|
break;
|
||||||
case "styleDeleted":
|
case "styleDeleted":
|
||||||
handleDelete(request.id);
|
handleDelete(request.id);
|
||||||
break;
|
break;
|
||||||
case "styleDisableAll":
|
case "prefChanged":
|
||||||
document.getElementById("disableAll").checked = request.disableAll;
|
if (request.prefName == "disableAll") {
|
||||||
handleDisableAll(request.disableAll);
|
document.getElementById("disableAll").checked = request.value;
|
||||||
|
handleDisableAll(request.value);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,4 +244,5 @@ loadPrefs({"disableAll": false});
|
||||||
handleDisableAll(prefs.getPref("disableAll"));
|
handleDisableAll(prefs.getPref("disableAll"));
|
||||||
document.getElementById("disableAll").addEventListener("change", function(event) {
|
document.getElementById("disableAll").addEventListener("change", function(event) {
|
||||||
notifyAllTabs({method: "styleDisableAll", disableAll: event.target.checked});
|
notifyAllTabs({method: "styleDisableAll", disableAll: event.target.checked});
|
||||||
|
handleDisableAll(event.target.checked);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user