Skip to content

Commit

Permalink
fix live2d toggle switch
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-husky committed Feb 14, 2024
1 parent 7ac563e commit 7f4817e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 52 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pypdf2==2.12.1
zhipuai>=2
tiktoken>=0.3.3
requests[socks]
pydantic
pydantic==2.5.2
protobuf==3.18
transformers>=4.27.1
scipdf_parser>=0.52
Expand Down
73 changes: 45 additions & 28 deletions themes/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,35 +746,61 @@ function loadLive2D() {
} catch (err) { console.log("[Error] JQuery is not defined.") }
}

function set_checkbox(key, bool) {
set_success = false;
document.getElementById("cbsc").querySelector('[data-testid="checkbox-group"]').querySelectorAll('label').forEach(label => {
function get_checkbox_selected_items(elem_id){
display_panel_arr = [];
document.getElementById(elem_id).querySelector('[data-testid="checkbox-group"]').querySelectorAll('label').forEach(label => {
// Get the span text
const spanText = label.querySelector('span').textContent;
if (spanText === key) {
label.classList.add('selected');
label.querySelector('input').checked = bool;
set_success = true;
return
// Get the input value
const checked = label.querySelector('input').checked;
if (checked) {
display_panel_arr.push(spanText)
}
});
document.getElementById("cbs").querySelector('[data-testid="checkbox-group"]').querySelectorAll('label').forEach(label => {
// Get the span text
const spanText = label.querySelector('span').textContent;
if (spanText === key) {
label.classList.add('selected');
label.querySelector('input').checked = bool;
set_success = true;
return
}
return display_panel_arr;
}

function set_checkbox(key, bool, set_twice=false) {
set_success = false;
elem_ids = ["cbsc", "cbs"]
elem_ids.forEach(id => {
document.getElementById(id).querySelector('[data-testid="checkbox-group"]').querySelectorAll('label').forEach(label => {
// Get the span text
const spanText = label.querySelector('span').textContent;
if (spanText === key) {
if (bool){
label.classList.add('selected');
} else {
if (label.classList.contains('selected')) {
label.classList.remove('selected');
}
}
if (set_twice){
setTimeout(() => {
if (bool){
label.classList.add('selected');
} else {
if (label.classList.contains('selected')) {
label.classList.remove('selected');
}
}
}, 5000);
}

label.querySelector('input').checked = bool;
set_success = true;
return
}
});
});

if (!set_success){
console.log("设置checkbox失败,没有找到对应的key")
}
}

function apply_cookie_for_checkbox(dark) {
console.log("apply_cookie_for_checkboxes")
// console.log("apply_cookie_for_checkboxes")
let searchString = "输入清除键";
let bool_value = "False";

Expand Down Expand Up @@ -831,16 +857,7 @@ function apply_cookie_for_checkbox(dark) {
} else {
// do not have cookie
// get conf
display_panel_arr = []
document.getElementById("cbsc").querySelector('[data-testid="checkbox-group"]').querySelectorAll('label').forEach(label => {
// Get the span text
const spanText = label.querySelector('span').textContent;
// Get the input value
const inputValue = label.querySelector('input').value;
if (label.classList.contains('selected')) {
display_panel_arr.push(spanText)
}
});
display_panel_arr = get_checkbox_selected_items("cbsc");
searchString = "添加Live2D形象";
if (display_panel_arr.includes(searchString)) {
loadLive2D();
Expand Down
24 changes: 3 additions & 21 deletions themes/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,7 @@ def from_cookie_str(c):
(display_panel_arr)=>{
setTimeout(() => {
// get conf
display_panel_arr = []
document.getElementById("cbs").querySelector('[data-testid="checkbox-group"]').querySelectorAll('label').forEach(label => {
// Get the span text
const spanText = label.querySelector('span').textContent;
// Get the input value
const inputValue = label.querySelector('input').value;
if (label.classList.contains('selected')){
display_panel_arr.push(spanText)
}
});
display_panel_arr = get_checkbox_selected_items("cbs");
////////////////////// 输入清除键 ///////////////////////////
let searchString = "输入清除键";
Expand Down Expand Up @@ -185,18 +176,9 @@ def from_cookie_str(c):
js_code_show_or_hide_group2 = """
(display_panel_arr)=>{
setTimeout(() => {
// console.log("display_panel_arr");
// get conf
display_panel_arr = []
document.getElementById("cbsc").querySelector('[data-testid="checkbox-group"]').querySelectorAll('label').forEach(label => {
// Get the span text
const spanText = label.querySelector('span').textContent;
// Get the input value
const inputValue = label.querySelector('input').value;
if (label.classList.contains('selected')){
display_panel_arr.push(spanText)
}
});
display_panel_arr = get_checkbox_selected_items("cbsc");
////////////////////// 添加Live2D形象 ///////////////////////////
let searchString = "添加Live2D形象";
Expand Down
4 changes: 2 additions & 2 deletions themes/waifu_plugin/waifu-tips.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ String.prototype.render = function(context) {
};

var re = /x/;
console.log(re);
// console.log(re);

function empty(obj) {return typeof obj=="undefined"||obj==null||obj==""?true:false}
function getRandText(text) {return Array.isArray(text) ? text[Math.floor(Math.random() * text.length + 1)-1] : text}
Expand Down Expand Up @@ -120,7 +120,7 @@ function hideMessage(timeout) {

function initModel(waifuPath, type) {
/* console welcome message */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('8.d(" ");8.d("\\U,.\\y\\5.\\1\\1\\1\\1/\\1,\\u\\2 \\H\\n\\1\\1\\1\\1\\1\\b \', !-\\r\\j-i\\1/\\1/\\g\\n\\1\\1\\1 \\1 \\a\\4\\f\'\\1\\1\\1 L/\\a\\4\\5\\2\\n\\1\\1 \\1 /\\1 \\a,\\1 /|\\1 ,\\1 ,\\1\\1\\1 \',\\n\\1\\1\\1\\q \\1/ /-\\j/\\1\\h\\E \\9 \\5!\\1 i\\n\\1\\1\\1 \\3 \\6 7\\q\\4\\c\\1 \\3\'\\s-\\c\\2!\\t|\\1 |\\n\\1\\1\\1\\1 !,/7 \'0\'\\1\\1 \\X\\w| \\1 |\\1\\1\\1\\n\\1\\1\\1\\1 |.\\x\\"\\1\\l\\1\\1 ,,,, / |./ \\1 |\\n\\1\\1\\1\\1 \\3\'| i\\z.\\2,,A\\l,.\\B / \\1.i \\1|\\n\\1\\1\\1\\1\\1 \\3\'| | / C\\D/\\3\'\\5,\\1\\9.\\1|\\n\\1\\1\\1\\1\\1\\1 | |/i \\m|/\\1 i\\1,.\\6 |\\F\\1|\\n\\1\\1\\1\\1\\1\\1.|/ /\\1\\h\\G \\1 \\6!\\1\\1\\b\\1|\\n\\1\\1\\1 \\1 \\1 k\\5>\\2\\9 \\1 o,.\\6\\2 \\1 /\\2!\\n\\1\\1\\1\\1\\1\\1 !\'\\m//\\4\\I\\g\', \\b \\4\'7\'\\J\'\\n\\1\\1\\1\\1\\1\\1 \\3\'\\K|M,p,\\O\\3|\\P\\n\\1\\1\\1\\1\\1 \\1\\1\\1\\c-,/\\1|p./\\n\\1\\1\\1\\1\\1 \\1\\1\\1\'\\f\'\\1\\1!o,.:\\Q \\R\\S\\T v"+e.V+" / W "+e.N);8.d(" ");',60,60,'|u3000|uff64|uff9a|uff40|u30fd|uff8d||console|uff8a|uff0f|uff3c|uff84|log|live2d_settings|uff70|u00b4|uff49||u2010||u3000_|u3008||_|___|uff72|u2500|uff67|u30cf|u30fc||u30bd|u4ece|u30d8|uff1e|__|u30a4|k_|uff17_|u3000L_|u3000i|uff1a|u3009|uff34|uff70r|u30fdL__||___i|l2dVerDate|u30f3|u30ce|nLive2D|u770b|u677f|u5a18|u304f__|l2dVersion|FGHRSH|u00b40i'.split('|'),0,{}));
// eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('8.d(" ");8.d("\\U,.\\y\\5.\\1\\1\\1\\1/\\1,\\u\\2 \\H\\n\\1\\1\\1\\1\\1\\b \', !-\\r\\j-i\\1/\\1/\\g\\n\\1\\1\\1 \\1 \\a\\4\\f\'\\1\\1\\1 L/\\a\\4\\5\\2\\n\\1\\1 \\1 /\\1 \\a,\\1 /|\\1 ,\\1 ,\\1\\1\\1 \',\\n\\1\\1\\1\\q \\1/ /-\\j/\\1\\h\\E \\9 \\5!\\1 i\\n\\1\\1\\1 \\3 \\6 7\\q\\4\\c\\1 \\3\'\\s-\\c\\2!\\t|\\1 |\\n\\1\\1\\1\\1 !,/7 \'0\'\\1\\1 \\X\\w| \\1 |\\1\\1\\1\\n\\1\\1\\1\\1 |.\\x\\"\\1\\l\\1\\1 ,,,, / |./ \\1 |\\n\\1\\1\\1\\1 \\3\'| i\\z.\\2,,A\\l,.\\B / \\1.i \\1|\\n\\1\\1\\1\\1\\1 \\3\'| | / C\\D/\\3\'\\5,\\1\\9.\\1|\\n\\1\\1\\1\\1\\1\\1 | |/i \\m|/\\1 i\\1,.\\6 |\\F\\1|\\n\\1\\1\\1\\1\\1\\1.|/ /\\1\\h\\G \\1 \\6!\\1\\1\\b\\1|\\n\\1\\1\\1 \\1 \\1 k\\5>\\2\\9 \\1 o,.\\6\\2 \\1 /\\2!\\n\\1\\1\\1\\1\\1\\1 !\'\\m//\\4\\I\\g\', \\b \\4\'7\'\\J\'\\n\\1\\1\\1\\1\\1\\1 \\3\'\\K|M,p,\\O\\3|\\P\\n\\1\\1\\1\\1\\1 \\1\\1\\1\\c-,/\\1|p./\\n\\1\\1\\1\\1\\1 \\1\\1\\1\'\\f\'\\1\\1!o,.:\\Q \\R\\S\\T v"+e.V+" / W "+e.N);8.d(" ");',60,60,'|u3000|uff64|uff9a|uff40|u30fd|uff8d||console|uff8a|uff0f|uff3c|uff84|log|live2d_settings|uff70|u00b4|uff49||u2010||u3000_|u3008||_|___|uff72|u2500|uff67|u30cf|u30fc||u30bd|u4ece|u30d8|uff1e|__|u30a4|k_|uff17_|u3000L_|u3000i|uff1a|u3009|uff34|uff70r|u30fdL__||___i|l2dVerDate|u30f3|u30ce|nLive2D|u770b|u677f|u5a18|u304f__|l2dVersion|FGHRSH|u00b40i'.split('|'),0,{}));

/* 判断 JQuery */
if (typeof($.ajax) != 'function') typeof(jQuery.ajax) == 'function' ? window.$ = jQuery : console.log('[Error] JQuery is not defined.');
Expand Down

0 comments on commit 7f4817e

Please sign in to comment.