Fix pop-up when dealing with newtab #80
This commit is contained in:
parent
d092cc7553
commit
d74dd20931
3
apply.js
3
apply.js
|
@ -21,6 +21,9 @@ chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
|
||||||
case "styleReplaceAll":
|
case "styleReplaceAll":
|
||||||
replaceAll(request.styles, document);
|
replaceAll(request.styles, document);
|
||||||
break;
|
break;
|
||||||
|
case "realURL":
|
||||||
|
sendResponse(location.href);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
29
popup.js
29
popup.js
|
@ -8,16 +8,27 @@ if (!prefs.getPref("popup.stylesFirst")) {
|
||||||
document.body.insertBefore(document.querySelector("body > .actions"), document.getElementById("installed"));
|
document.body.insertBefore(document.querySelector("body > .actions"), document.getElementById("installed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.tabs.getSelected(null, function(tab) {
|
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
|
||||||
var urlWillWork = /^(file|http|https|chrome\-extension):/.exec(tab.url);
|
// Only one is active, I hope
|
||||||
|
var tab = tabs[0];
|
||||||
|
|
||||||
|
// The new tab lies about what it is.
|
||||||
|
if (tab.url == "chrome://newtab/") {
|
||||||
|
chrome.tabs.sendMessage(tab.id, {method: "realURL"}, null, updatePopUp);
|
||||||
|
} else {
|
||||||
|
updatePopUp(tab.url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function updatePopUp(url) {
|
||||||
|
var urlWillWork = /^(file|http|https|chrome\-extension):/.exec(url);
|
||||||
if (!urlWillWork) {
|
if (!urlWillWork) {
|
||||||
document.body.classList.add("blocked");
|
document.body.classList.add("blocked");
|
||||||
tE("unavailable", "stylishUnavailableForURL");
|
tE("unavailable", "stylishUnavailableForURL");
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.extension.sendMessage({method: "getStyles", matchUrl: tab.url}, showStyles);
|
chrome.extension.sendMessage({method: "getStyles", matchUrl: url}, showStyles);
|
||||||
document.querySelector("#find-styles a").href = "https://userstyles.org/styles/browse/all/" + encodeURIComponent("file" === urlWillWork[1] ? "file:" : tab.url);
|
document.querySelector("#find-styles a").href = "https://userstyles.org/styles/browse/all/" + encodeURIComponent("file" === urlWillWork[1] ? "file:" : url);
|
||||||
|
|
||||||
// Write new style links
|
// Write new style links
|
||||||
var writeStyleLinks = [],
|
var writeStyleLinks = [],
|
||||||
|
@ -26,13 +37,13 @@ chrome.tabs.getSelected(null, function(tab) {
|
||||||
|
|
||||||
// For this URL
|
// For this URL
|
||||||
var urlLink = writeStyleTemplate.cloneNode(true);
|
var urlLink = writeStyleTemplate.cloneNode(true);
|
||||||
urlLink.href = "edit.html?url-prefix=" + encodeURIComponent(tab.url);
|
urlLink.href = "edit.html?url-prefix=" + encodeURIComponent(url);
|
||||||
urlLink.appendChild(document.createTextNode( // switchable; default="this URL"
|
urlLink.appendChild(document.createTextNode( // switchable; default="this URL"
|
||||||
!prefs.getPref("popup.breadcrumbs.usePath")
|
!prefs.getPref("popup.breadcrumbs.usePath")
|
||||||
? t("writeStyleForURL").replace(/ /g, "\u00a0")
|
? t("writeStyleForURL").replace(/ /g, "\u00a0")
|
||||||
: /\/\/[^/]+\/(.*)/.exec(tab.url)[1]
|
: /\/\/[^/]+\/(.*)/.exec(url)[1]
|
||||||
));
|
));
|
||||||
urlLink.title = "url-prefix(\"$\")".replace("$", tab.url);
|
urlLink.title = "url-prefix(\"$\")".replace("$", url);
|
||||||
writeStyleLinks.push(urlLink);
|
writeStyleLinks.push(urlLink);
|
||||||
document.querySelector("#write-style").appendChild(urlLink)
|
document.querySelector("#write-style").appendChild(urlLink)
|
||||||
if (prefs.getPref("popup.breadcrumbs")) { // switchable; default=enabled
|
if (prefs.getPref("popup.breadcrumbs")) { // switchable; default=enabled
|
||||||
|
@ -43,7 +54,7 @@ chrome.tabs.getSelected(null, function(tab) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// For domain
|
// For domain
|
||||||
var domains = getDomains(tab.url)
|
var domains = getDomains(url)
|
||||||
domains.forEach(function(domain) {
|
domains.forEach(function(domain) {
|
||||||
// Don't include TLD
|
// Don't include TLD
|
||||||
if (domains.length > 1 && domain.indexOf(".") == -1) {
|
if (domains.length > 1 && domain.indexOf(".") == -1) {
|
||||||
|
@ -67,7 +78,7 @@ chrome.tabs.getSelected(null, function(tab) {
|
||||||
container.appendChild(container.removeChild(container.firstChild));
|
container.appendChild(container.removeChild(container.firstChild));
|
||||||
}
|
}
|
||||||
writeStyle.appendChild(container);
|
writeStyle.appendChild(container);
|
||||||
});
|
}
|
||||||
|
|
||||||
function showStyles(styles) {
|
function showStyles(styles) {
|
||||||
var enabledFirst = prefs.getPref("popup.enabledFirst");
|
var enabledFirst = prefs.getPref("popup.enabledFirst");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user