mirror of
https://github.com/zombieFox/nightTab.git
synced 2025-06-26 04:21:38 +02:00
[refactor] improve theme font if display and ui font is the same
This commit is contained in:
parent
977f966021
commit
ac8b56c838
@ -2563,6 +2563,7 @@ var control = (function() {
|
||||
type: "text",
|
||||
func: function() {
|
||||
theme.render.font.delay.display();
|
||||
theme.render.font.delay.ui();
|
||||
}
|
||||
}, {
|
||||
element: helper.e(".control-theme-font-display-name-default"),
|
||||
@ -2619,6 +2620,7 @@ var control = (function() {
|
||||
path: "theme.font.ui.name",
|
||||
type: "text",
|
||||
func: function() {
|
||||
theme.render.font.delay.display();
|
||||
theme.render.font.delay.ui();
|
||||
}
|
||||
}, {
|
||||
|
102
src/js/theme.js
102
src/js/theme.js
@ -859,31 +859,37 @@ var theme = (function() {
|
||||
},
|
||||
display: {
|
||||
name: function() {
|
||||
var name = state.get.current().theme.font.display.name.trim().replace(/\s+/g, "+");
|
||||
var html = helper.e("html");
|
||||
var link = helper.e(".theme-font-display-name-link");
|
||||
if (link) {
|
||||
link.remove();
|
||||
var removeLink = function() {
|
||||
var link = helper.e(".theme-font-display-name");
|
||||
if (link) {
|
||||
link.remove();
|
||||
};
|
||||
html.style.removeProperty("--theme-font-display-name");
|
||||
};
|
||||
html.style.removeProperty("--theme-font-display-name");
|
||||
if (name != "") {
|
||||
var head = helper.e("head");
|
||||
var link = helper.makeNode({
|
||||
tag: "link",
|
||||
attr: [{
|
||||
key: "class",
|
||||
value: "theme-font-display-name-link"
|
||||
}, {
|
||||
key: "href",
|
||||
value: "https://fonts.googleapis.com/css?family=" + name + ":100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&display=swap"
|
||||
}, {
|
||||
key: "rel",
|
||||
value: "stylesheet"
|
||||
}]
|
||||
});
|
||||
head.appendChild(link);
|
||||
html.style.setProperty("--theme-font-display-name", "\"" + state.get.current().theme.font.display.name.trim().replace(/\s\s+/g, " ") + "\"" + ", \"Fjalla One\", sans-serif");
|
||||
var addLink = function() {
|
||||
var name = state.get.current().theme.font.display.name.trim().replace(/\s+/g, "+");
|
||||
if (name != "") {
|
||||
var head = helper.e("head");
|
||||
var link = helper.makeNode({
|
||||
tag: "link",
|
||||
attr: [{
|
||||
key: "class",
|
||||
value: "theme-font-display-name"
|
||||
}, {
|
||||
key: "href",
|
||||
value: "https://fonts.googleapis.com/css?family=" + name + ":100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&display=swap"
|
||||
}, {
|
||||
key: "rel",
|
||||
value: "stylesheet"
|
||||
}]
|
||||
});
|
||||
head.appendChild(link);
|
||||
html.style.setProperty("--theme-font-display-name", "\"" + state.get.current().theme.font.display.name.trim().replace(/\s\s+/g, " ") + "\"" + ", \"Fjalla One\", sans-serif");
|
||||
};
|
||||
};
|
||||
removeLink();
|
||||
addLink();
|
||||
},
|
||||
weight: function() {
|
||||
var html = helper.e("html");
|
||||
@ -897,33 +903,39 @@ var theme = (function() {
|
||||
},
|
||||
ui: {
|
||||
name: function() {
|
||||
var name = state.get.current().theme.font.ui.name.trim().replace(/\s+/g, "+");
|
||||
var html = helper.e("html");
|
||||
var link = helper.eA(".theme-font-ui-name-link");
|
||||
if (link.length > 0) {
|
||||
link.forEach(function(arrayItem, item) {
|
||||
arrayItem.remove();
|
||||
});
|
||||
var removeLink = function() {
|
||||
var link = helper.e(".theme-font-ui-name");
|
||||
if (link) {
|
||||
link.remove();
|
||||
};
|
||||
html.style.removeProperty("--theme-font-ui-name");
|
||||
};
|
||||
if (name != "") {
|
||||
var head = helper.e("head");
|
||||
var link = helper.makeNode({
|
||||
tag: "link",
|
||||
attr: [{
|
||||
key: "class",
|
||||
value: "theme-font-ui-name-link"
|
||||
}, {
|
||||
key: "href",
|
||||
value: "https://fonts.googleapis.com/css?family=" + name + ":100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&display=swap"
|
||||
}, {
|
||||
key: "rel",
|
||||
value: "stylesheet"
|
||||
}]
|
||||
});
|
||||
head.appendChild(link);
|
||||
html.style.setProperty("--theme-font-ui-name", "\"" + state.get.current().theme.font.ui.name.trim().replace(/\s\s+/g, " ") + "\"" + ", \"Open Sans\", sans-serif");
|
||||
var addLink = function() {
|
||||
var name = state.get.current().theme.font.ui.name.trim().replace(/\s+/g, "+");
|
||||
if (name != "") {
|
||||
if (name != state.get.current().theme.font.display.name) {
|
||||
var head = helper.e("head");
|
||||
var link = helper.makeNode({
|
||||
tag: "link",
|
||||
attr: [{
|
||||
key: "class",
|
||||
value: "theme-font-ui-name"
|
||||
}, {
|
||||
key: "href",
|
||||
value: "https://fonts.googleapis.com/css?family=" + name + ":100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&display=swap"
|
||||
}, {
|
||||
key: "rel",
|
||||
value: "stylesheet"
|
||||
}]
|
||||
});
|
||||
head.appendChild(link);
|
||||
};
|
||||
html.style.setProperty("--theme-font-ui-name", "\"" + state.get.current().theme.font.ui.name.trim().replace(/\s\s+/g, " ") + "\"" + ", \"Open Sans\", sans-serif");
|
||||
};
|
||||
};
|
||||
removeLink();
|
||||
addLink();
|
||||
},
|
||||
weight: function() {
|
||||
var html = helper.e("html");
|
||||
|
Loading…
x
Reference in New Issue
Block a user