Browse Source

修复颜色未能转换的问题

tags/v29.0
枫谷剑仙 3 years ago
parent
commit
b04341aaa0
3 changed files with 64 additions and 21 deletions
  1. +18
    -0
      script-universal_function.js
  2. +25
    -5
      script.js
  3. +21
    -16
      style.css

+ 18
- 0
script-universal_function.js View File

@@ -858,6 +858,24 @@ function searchCollab(event) {
showSearch(Cards.filter(card => card.collabId == collabId)); showSearch(Cards.filter(card => card.collabId == collabId));
return false; return false;
} }
function rgbToHex(str) { //RGB(A)颜色转换为HEX十六进制的颜色值
let res = /rgba?\((\d{1,3}),(\d{1,3}),(\d{1,3})(,([.\d]+))?\)/ig.exec(str.replace(/\s/g,''));
if (res) {
let [,r,g,b,a] = res;
let rgb = [r,g,b].map(s=>parseInt(s,10));
if (a) {
rgb.push(Math.round(Number(a) * 255));
}
return rgb.map(n=>n.toString(16).padStart(2,'0')).join('');
}
else if (res = /#([a-fA-F0-9]{6,8})/i.exec(str))
{
return res[1];
}
else {
return '000000';
}
}
//创建序号类图标 //创建序号类图标
function createIndexedIcon(type, index) { function createIndexedIcon(type, index) {
if (type == 'card') {//卡片头像 if (type == 'card') {//卡片头像


+ 25
- 5
script.js View File

@@ -2243,7 +2243,7 @@ function initialize() {
const docObj = range.extractContents(); //移动了Range 中的内容从文档树到DocumentFragment(文档片段对象)。 const docObj = range.extractContents(); //移动了Range 中的内容从文档树到DocumentFragment(文档片段对象)。
let dom let dom
if (color === "#000000") { if (color === "#000000") {
dom = document.createTextNode(docObj);
dom = document.createTextNode(docObj.textContent);
} else { } else {
dom = document.createElement('span'); dom = document.createElement('span');
dom.style.color = color; dom.style.color = color;
@@ -2323,13 +2323,11 @@ function initialize() {
} }
const range = docSelection.getRangeAt(0); const range = docSelection.getRangeAt(0);
let target; let target;
console.log(range);
if (target = (txtTitleDisplay.contains(range.commonAncestorContainer) && txtTitleDisplay) if (target = (txtTitleDisplay.contains(range.commonAncestorContainer) && txtTitleDisplay)
|| (txtDetailDisplay.contains(range.commonAncestorContainer) && txtDetailDisplay)) || (txtDetailDisplay.contains(range.commonAncestorContainer) && txtDetailDisplay))
{ {
let dom = createIndexedIcon(type, id); let dom = createIndexedIcon(type, id);
range.insertNode(dom); range.insertNode(dom);
console.log(target);
target.onblur(); target.onblur();
} else if (target = (txtTitle.contains(range.commonAncestorContainer) && txtTitle) } else if (target = (txtTitle.contains(range.commonAncestorContainer) && txtTitle)
|| (txtDetail.contains(range.commonAncestorContainer) && txtDetail)) || (txtDetail.contains(range.commonAncestorContainer) && txtDetail))
@@ -2361,9 +2359,19 @@ function initialize() {
function richTextToCode(parentElement){ function richTextToCode(parentElement){
let code = []; let code = [];
for (let node of parentElement.childNodes) { for (let node of parentElement.childNodes) {
if (node.nodeName == "#text"){
if (node.nodeName == "#text"){ //纯文本
code.push(node.nodeValue); code.push(node.nodeValue);
continue; continue;
} else if (node.nodeName == "SPAN" && node.style.color) { //文字颜色
let colorStr = rgbToHex(node.style.color);
code.push(`^${colorStr}^${node.textContent}^p`);
continue;
} else if (node.nodeName == "DIV") {
code.push(richTextToCode(node)+'\n');
continue;
} else if (node.nodeName == "BR") {
code.push('\n');
continue;
} }
let type, id; let type, id;
if(node.classList.contains("detail-mon")) { //卡片头像 if(node.classList.contains("detail-mon")) { //卡片头像
@@ -2397,7 +2405,17 @@ function initialize() {
formationBox.refreshDocumentTitle(); formationBox.refreshDocumentTitle();
creatNewUrl(); creatNewUrl();
} }
//标题凡是输入就删除所有的换行
txtTitleDisplay.oninput = function(){
for (let node of this.children) {
if (node.nodeName == "BR") node.remove();
}
}
txtDetailDisplay.onblur = function(){ txtDetailDisplay.onblur = function(){
//没有内容或者只有一个换行时,清空内容
if (this.textContent.length == 0 || this.textContent == "\n") {
this.innerHTML = '';
}
formation.detail = txtDetail.value = richTextToCode(this); formation.detail = txtDetail.value = richTextToCode(this);
creatNewUrl(); creatNewUrl();
} }
@@ -5633,9 +5651,11 @@ function fastShowSkill(event) {
function localisation($tra) { function localisation($tra) {
if (!$tra) return; if (!$tra) return;
document.title = $tra.webpage_title; document.title = $tra.webpage_title;
controlBox.querySelector(".datasource-updatetime").title = $tra.force_reload_data;
formationBox.querySelector(".title-box .title-code").placeholder = $tra.title_blank; formationBox.querySelector(".title-box .title-code").placeholder = $tra.title_blank;
formationBox.querySelector(".title-box .title-display").dataset.placeholder = $tra.title_blank;
formationBox.querySelector(".detail-box .detail-code").placeholder = $tra.detail_blank; formationBox.querySelector(".detail-box .detail-code").placeholder = $tra.detail_blank;
controlBox.querySelector(".datasource-updatetime").title = $tra.force_reload_data;
formationBox.querySelector(".detail-box .detail-display").dataset.placeholder = $tra.detail_blank;


const s_sortList = editBox.querySelector(".search-box .sort-div .sort-list"); const s_sortList = editBox.querySelector(".search-box .sort-div .sort-list");
const sortOptions = Array.from(s_sortList.options); const sortOptions = Array.from(s_sortList.options);


+ 21
- 16
style.css View File

@@ -91,7 +91,12 @@ details>summary {
} }
#rich-text-tools button #rich-text-tools button
{ {
height: 32px;
min-width: 64px;
}
#rich-text-tools button,
#rich-text-tools input
{
height: 40px;
vertical-align: middle; vertical-align: middle;
text-align: center; text-align: center;
} }
@@ -115,42 +120,37 @@ label[for="siwtch-code-mode"] {
margin: 0 0 0 5px; margin: 0 0 0 5px;
} }
label[for="siwtch-code-mode"]::after { label[for="siwtch-code-mode"]::after {
font-size: 1.5em;
font-size: 1.7em;
font-family: var(--icon-font-family); font-family: var(--icon-font-family);
content: "\f121"; content: "\f121";
vertical-align: middle; vertical-align: middle;
} }
#set-font-color::before { #set-font-color::before {
content: "A"; content: "A";
font-size: 1.5em;
font-size: 1.7em;
} }
#color-chooser { #color-chooser {
width: 20px;
vertical-align: middle;
width: 30px;
} }
#insert-card-avatar::before { #insert-card-avatar::before {
width: 100px; width: 100px;
height: 100px; height: 100px;
background-image: url(images/CARDFRAME2.PNG), url(images/CARDFRAME2.PNG); background-image: url(images/CARDFRAME2.PNG), url(images/CARDFRAME2.PNG);
background-position: -102px -104px, 0 0; background-position: -102px -104px, 0 0;
transform: scale(calc(25 / 100));
margin: calc(-100px * (1 - (25 / 100)) / 2);
transform: scale(calc(32 / 100));
margin: calc(-100px * (1 - (32 / 100)) / 2);
} }
#insert-type-icon::before { #insert-type-icon::before {
width: 32px; width: 32px;
height: 32px; height: 32px;
background-image: url(images/type.png); background-image: url(images/type.png);
background-position-y: calc(-32px * 4); background-position-y: calc(-32px * 4);
transform: scale(calc(25 / 32));
margin: calc(-32px * (1 - (25 / 32)) / 2);
} }
#insert-awoken-icon::before { #insert-awoken-icon::before {
width: 32px; width: 32px;
height: 32px; height: 32px;
background-image: url(images/awoken.png); background-image: url(images/awoken.png);
background-position-y: calc(-32px * 43); background-position-y: calc(-32px * 43);
transform: scale(calc(25 / 32));
margin: calc(-32px * (1 - (25 / 32)) / 2);
} }
#insert-latent-icon::before { #insert-latent-icon::before {
width: 32px; width: 32px;
@@ -163,15 +163,13 @@ label[for="siwtch-code-mode"]::after {
background-image: url(images/icon-latent.png); background-image: url(images/icon-latent.png);
background-position-x: -2px; background-position-x: -2px;
background-position-y: calc(-32px * 11 - 2px); background-position-y: calc(-32px * 11 - 2px);
transform: scale(calc(25 / 32));
margin: calc(-32px * (1 - (25 / 32)) / 2);
} }
#insert-orb-icon::before { #insert-orb-icon::before {
width: 36px; width: 36px;
height: 36px; height: 36px;
background-image: url(images/icon-orbs.png); background-image: url(images/icon-orbs.png);
transform: scale(calc(25 / 36));
margin: calc(-36px * (1 - (25 / 36)) / 2);
transform: scale(calc(32 / 36));
margin: calc(-36px * (1 - (32 / 36)) / 2);
} }
#rich-text-tools>ul icon { #rich-text-tools>ul icon {
cursor: pointer; cursor: pointer;
@@ -217,7 +215,14 @@ label[for="siwtch-code-mode"]::after {
margin: 0; margin: 0;
white-space: break-spaces; white-space: break-spaces;
} }

:where(
.title-display,
.detail-display,
):empty::before{
color: grey;
position: absolute;
content: attr(data-placeholder);
}
.guide-mod .control-box>div.status .guide-mod .control-box>div.status
{ {
display: block; display: block;


Loading…
Cancel
Save