Skip to content

Commit

Permalink
v1.5.2
Browse files Browse the repository at this point in the history
[*] apply font styles in menu
  • Loading branch information
henryxrl committed Oct 20, 2024
1 parent 078d03e commit e3ccd70
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@

火狐插件:

1. [易笺正常版 (v1.5.1)](https://addons.mozilla.org/zh-CN/firefox/addon/yijian/)
1. [易笺正常版 (v1.5.2)](https://addons.mozilla.org/zh-CN/firefox/addon/yijian/)

2. [易笺无界面版 (v1.2.9.2)](https://addons.mozilla.org/zh-CN/firefox/addon/yijian_nogui/)

Chrome插件:

1. [易笺正常版 (v1.5.1)](https://chrome.google.com/webstore/detail/%E6%98%93%E7%AC%BA/dbanahlbopbjpgdkecmclbbonhpohcaf?hl=en&authuser=0)
1. [易笺正常版 (v1.5.2)](https://chrome.google.com/webstore/detail/%E6%98%93%E7%AC%BA/dbanahlbopbjpgdkecmclbbonhpohcaf?hl=en&authuser=0)

2. [易笺无界面版 (v1.2.9.2)](https://chrome.google.com/webstore/detail/%E6%98%93%E7%AC%BA%EF%BC%88%E6%97%A0%E7%95%8C%E9%9D%A2%E7%89%88%EF%BC%89/mifnkjlmnnaamfgmhmjdjiplaaladjlo?hl=en&authuser=0)

Expand Down
4 changes: 2 additions & 2 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ Support for customized settings such as font size, line height, theme colors and

Firefox:

1. [Regular (v1.5.1)](https://addons.mozilla.org/en-US/firefox/addon/yijian/)
1. [Regular (v1.5.2)](https://addons.mozilla.org/en-US/firefox/addon/yijian/)

2. [No-UI (v1.2.9.2)](https://addons.mozilla.org/en-US/firefox/addon/yijian_nogui/)

Chrome:

1. [Regular (v1.5.1)](https://chrome.google.com/webstore/detail/%E6%98%93%E7%AC%BA/dbanahlbopbjpgdkecmclbbonhpohcaf?hl=en&authuser=0)
1. [Regular (v1.5.2)](https://chrome.google.com/webstore/detail/%E6%98%93%E7%AC%BA/dbanahlbopbjpgdkecmclbbonhpohcaf?hl=en&authuser=0)

2. [No-UI (v1.2.9.2)](https://chrome.google.com/webstore/detail/%E6%98%93%E7%AC%BA%EF%BC%88%E6%97%A0%E7%95%8C%E9%9D%A2%E7%89%88%EF%BC%89/mifnkjlmnnaamfgmhmjdjiplaaladjlo?hl=en&authuser=0)

Expand Down
2 changes: 1 addition & 1 deletion manifests/Chrome/regular/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "易笺",
"description": "txt(小说)阅读器:支持秒开本地的所有txt文件,自动排版,自动分页,自动生成目录,记录阅读进度。",
"version": "1.5.1",
"version": "1.5.2",
"background": {
"service_worker": "scripts_extension/Chrome/regular/activate.js"
},
Expand Down
2 changes: 1 addition & 1 deletion manifests/Firefox/regular/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "易笺",
"description": "txt(小说)阅读器:支持秒开本地的所有txt文件,自动排版,自动分页,自动生成目录,记录阅读进度。",
"version": "1.5.1",
"version": "1.5.2",
"background": {
"scripts": [
"scripts_extension/Firefox/regular/activate.js"
Expand Down
8 changes: 6 additions & 2 deletions scripts/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function selector_init($selectElement, defaultIdx, EventListenerFunc, EventListe

// Show the default select option in the styled div
$styledSelect.text(allOptions.eq(defaultIdx).text());
$styledSelect.attr('style', allOptions.eq(defaultIdx).attr('style'));

// Insert an unordered list after the styled div and also cache the list
var $list = $('<ul />', {
Expand All @@ -47,14 +48,16 @@ function selector_init($selectElement, defaultIdx, EventListenerFunc, EventListe
$('<li />', {
text: $(this).text(),
rel: $(this).val(),
class: 'optgroup-option'
class: 'optgroup-option',
style: $(this).attr('style')
}).appendTo($list);
});
} else {
// If the current element is a regular option, add it directly
$('<li />', {
text: $(this).text(),
rel: $(this).val()
rel: $(this).val(),
style: $(this).attr('style')
}).appendTo($list);
}
});
Expand All @@ -76,6 +79,7 @@ function selector_init($selectElement, defaultIdx, EventListenerFunc, EventListe
$listItems.click(function(e) {
e.stopPropagation();
$styledSelect.text($(this).text()).removeClass('active');
$styledSelect.attr('style', $(this).attr('style'));
$this.val($(this).attr('rel'));
$list.find('li.is-selected').removeClass('is-selected');
$list.find('li[rel="' + $(this).attr('rel') + '"]').addClass('is-selected');
Expand Down
2 changes: 1 addition & 1 deletion scripts/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ async function handleSelectedFile(fileList) {
isEasternLan = getLanguage(fileContentChunks.slice(0, 50).join("\n"));
console.log("isEasternLan: ", isEasternLan);
// Change UI language based on detected language... or not?
respectUserLangSetting = (document.documentElement.getAttribute("respectUserLangSetting") === "true");
// respectUserLangSetting = (document.documentElement.getAttribute("respectUserLangSetting") === "true");
if (!respectUserLangSetting)
setLanguage((isEasternLan ? "zh" : "en"), false);

Expand Down
33 changes: 22 additions & 11 deletions scripts/ui_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ initiateSettingMenu();
// Main functions
//
function loadSettings() {
if (respectUserLangSetting)
if (respectUserLangSetting) {
ui_language = localStorage.getItem("UILang") || ui_language_default;
}
p_lineHeight = localStorage.getItem("p_lineHeight") || p_lineHeight_default;
p_fontSize = localStorage.getItem("p_fontSize") || p_fontSize_default;
light_mainColor_active = localStorage.getItem("light_mainColor_active") || light_mainColor_active_default;
Expand Down Expand Up @@ -173,8 +174,9 @@ function loadDefaultSettings() {
pagination_bottom = pagination_bottom_default;
pagination_opacity = pagination_opacity_default;

if (respectUserLangSetting)
if (respectUserLangSetting) {
setSelectorValue("setting_uilanguage", Object.keys(ui_language_mapping).indexOf(ui_language));
}
setRangeValue("setting_p_lineHeight", p_lineHeight);
setRangeValue("setting_p_fontSize", p_fontSize);
setColorValue("setting_light_mainColor_active", light_mainColor_active);
Expand All @@ -190,8 +192,9 @@ function loadDefaultSettings() {
}

function applySettings() {
if (respectUserLangSetting)
if (respectUserLangSetting) {
style.ui_LANG = ui_language;
}
style.p_lineHeight = p_lineHeight;
style.p_fontSize = p_fontSize;
style.mainColor_active = light_mainColor_active;
Expand All @@ -218,8 +221,9 @@ function applySettings() {
}

function saveSettings(toSetLanguage = false, forceSetLanguage = false) {
if (respectUserLangSetting)
if (respectUserLangSetting) {
ui_language = $("#setting_uilanguage").closest(".select").children(".select-options").children(".is-selected").attr("rel") || ui_language_default;
}
p_lineHeight = $("#setting_p_lineHeight").val() + 'em' || p_lineHeight_default;
p_fontSize = $("#setting_p_fontSize").val() + 'em' || p_fontSize_default;
light_mainColor_active = $("#setting_light_mainColor_active").val() || light_mainColor_active_default;
Expand All @@ -244,8 +248,9 @@ function saveSettings(toSetLanguage = false, forceSetLanguage = false) {
changeFontSelectorItemLanguage($("#setting_body_font"), lang);
}

if (respectUserLangSetting)
if (respectUserLangSetting) {
localStorage.setItem("UILang", ui_language);
}
localStorage.setItem("p_lineHeight", p_lineHeight);
localStorage.setItem("p_fontSize", p_fontSize);
localStorage.setItem("light_mainColor_active", light_mainColor_active);
Expand All @@ -263,8 +268,9 @@ function saveSettings(toSetLanguage = false, forceSetLanguage = false) {

applySettings();

if (typeof bookshelf !== "undefined" && isVariableDefined(bookshelf))
if (typeof bookshelf !== "undefined" && isVariableDefined(bookshelf)) {
bookshelf.updateAllBookCovers();
}
}

function initiateSettingMenu() {
Expand Down Expand Up @@ -312,8 +318,9 @@ function initiateSettingMenu() {
});

let settingUILanguage = null;
if (respectUserLangSetting)
if (respectUserLangSetting) {
settingUILanguage = createSelectorItem("setting_uilanguage", Object.keys(ui_language_mapping), Object.values(ui_language_mapping));
}
let settingLineHeight = createRangeItem("setting_p_lineHeight", parseFloat(p_lineHeight), 1, 3, 0.5, unit='em');
let settingFontSize = createRangeItem("setting_p_fontSize", parseFloat(p_fontSize), 1, 3, 0.5, unit='em');
let settingLightMainColorActive = createColorItem("setting_light_mainColor_active", light_mainColor_active, savedValues=["#2F5086"]);
Expand All @@ -331,8 +338,9 @@ function initiateSettingMenu() {
let settingPaginationBottom = createRangeItem("setting_pagination_bottom", parseFloat(pagination_bottom), 1, 30, 1, unit='px');
let settingPaginationOpacity = createRangeItem("setting_pagination_opacity", parseFloat(pagination_opacity), 0, 1, 0.1, unit='');

if (respectUserLangSetting)
if (respectUserLangSetting) {
settingsMenu.appendChild(settingUILanguage);
}
settingsMenu.appendChild(settingLineHeight);
settingsMenu.appendChild(settingFontSize);
settingsMenu.appendChild(settingLightMainColorActive);
Expand Down Expand Up @@ -484,7 +492,7 @@ function createSelectorItem(id, values, texts) {
return settingItem;
}

function createSelectorWithGroupItem(id, values, texts, groups) {
function createSelectorWithGroupItem(id, values, texts, groups, isFont=false) {
let settingItem = document.createElement('div');
settingItem.setAttribute('class', 'settingItem-wrapper');
let settingItemText = document.createElement('span');
Expand All @@ -501,6 +509,9 @@ function createSelectorWithGroupItem(id, values, texts, groups) {
let option = document.createElement('option');
option.setAttribute('value', value);
option.innerText = texts[i][j];
if (isFont) {
option.style.fontFamily = value;
}
optgroup.appendChild(option);
});
settingItemInput.appendChild(optgroup);
Expand Down Expand Up @@ -637,8 +648,8 @@ function createFontSelectorItem(id) {
font_groups_zh = [style.ui_font_group_custom_zh, style.ui_font_group_system_zh];

// Create the font selector element
let fontSelector = createSelectorWithGroupItem(id, filtered_font_names, filtered_font_labels, font_groups);
let fontSelector_zh = createSelectorWithGroupItem(id, filtered_font_names, filtered_font_labels_zh, font_groups_zh);
let fontSelector = createSelectorWithGroupItem(id, filtered_font_names, filtered_font_labels, font_groups, isFont=true);
let fontSelector_zh = createSelectorWithGroupItem(id, filtered_font_names, filtered_font_labels_zh, font_groups_zh, isFont=true);

return [fontSelector, fontSelector_zh];
}
Expand Down

0 comments on commit e3ccd70

Please sign in to comment.