Created
December 29, 2022 08:59
-
-
Save whiteball/7107168e123380009caef4b9a7fa9278 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name AIのべりすと ローカル作品リストで全文検索 | |
// @namespace https://ai-novelist-share.geo.jp/ | |
// @version 0.1 | |
// @description AIのべりすとの作品リスト(ローカル)で、インクリメンタルサーチの対象をタイトルのみから全文(本文・メモリ・脚注・キャラクターブック・禁止ワード・タイトル)に変更できるチェックボックスを追加します。リモートのリストでは無効です。 | |
// @author しらたま | |
// @match https://ai-novel.com/works.php | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=ai-novel.com | |
// @updateURL https://gist.github.com/whiteball/7107168e123380009caef4b9a7fa9278/raw/ai_novelist_works_full_text_search.user.js | |
// @downloadURL https://gist.github.com/whiteball/7107168e123380009caef4b9a7fa9278/raw/ai_novelist_works_full_text_search.user.js | |
// @supportURL https://gist.github.com/whiteball/7107168e123380009caef4b9a7fa9278 | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const works_find_text = document.getElementById('works_find_text') | |
if (!works_find_text) { | |
return | |
} | |
const works_find_text_full = works_find_text.cloneNode() | |
works_find_text_full.id = 'works_find_text_full' | |
works_find_text_full.style.display = 'none' | |
works_find_text_full.placeholder += '(全文)' | |
works_find_text.insertAdjacentElement('afterend', works_find_text_full) | |
works_find_text_full.insertAdjacentHTML('afterend', ` <label id="mod_search_full_label" title="全文検索を有効にすると動作が重くなる可能性があります"><input type="checkbox" id="mod_search_full"> 全文</label>`) | |
const changeDisplay = function (state) { | |
if (state) { | |
works_find_text.style.display = 'none' | |
works_find_text_full.style.display = '' | |
works_find_text_full.value = works_find_text.value | |
works_find_text_full.dispatchEvent(new Event('input')) | |
} else { | |
works_find_text.style.display = '' | |
works_find_text_full.style.display = 'none' | |
works_find_text.value = works_find_text_full.value | |
works_find_text.dispatchEvent(new Event('input')) | |
} | |
} | |
const mod_search_full = document.getElementById('mod_search_full') | |
if (mod_search_full) { | |
mod_search_full.addEventListener('change', function (event) { | |
changeDisplay(event.target.checked) | |
}) | |
} | |
const worksFinderFull = function () { | |
const mod_search_full_label = document.getElementById('mod_search_full_label') | |
if ( ! mod_search_full_label || mod_search_full_label.style.display === 'none') { | |
works_find_text.value = works_find_text_full.value | |
works_find_text.dispatchEvent(new Event('input')) | |
return | |
} | |
var css_target | |
const $ = window.jQuery | |
if( window.style_num == 3 ){ // グリッドリスト | |
css_target = $('.works_item_flex'); | |
} else { // それ以外 | |
css_target = $('.work_load'); | |
} | |
const needle = works_find_text_full.value ? works_find_text_full.value.toLowerCase() : undefined | |
css_target.each( function(index, item) { | |
var temp_id; | |
temp_id = item.innerHTML.substr(item.innerHTML.indexOf('loadprompt')); | |
temp_id = temp_id.substr(temp_id.indexOf('(') + 1); | |
temp_id = Number(temp_id.substr(0,temp_id.indexOf(')'))); | |
if ( needle === undefined ) { | |
$(this).css('display', ""); | |
$("#works_section"+temp_id).css('display', ""); | |
$("#works_section_remote"+temp_id).css('display', ""); | |
return; | |
} | |
let target_text = localStorage['works' + temp_id] | |
if (target_text) { | |
const parts = target_text.split('<|endofsection|>') | |
target_text = parts[0].replace(/<[^>]+>/g, '') + '\u0001' + parts[1].replace(/<[^>]+>/g, '') + '\u0001' + | |
parts[2].replace(/<[^>]+>/g, '') + '\u0001' + parts[4].replace(/<[^>]+>/g, '') + '\u0001' + | |
parts[5].replace(/<[^>]+>/g, '') + '\u0001' + parts[6].replace(/<[^>]+>/g, '') | |
target_text = target_text.toLowerCase() | |
} | |
if ( item.innerHTML.indexOf('works_current_title') >= 1 || (target_text && target_text.indexOf(needle) >= 0) ) { | |
$(this).css('display', ""); | |
$("#works_section"+temp_id).css('display', ""); | |
$("#works_section_remote"+temp_id).css('display', ""); | |
} else { | |
$(this).css('display', "none"); | |
$("#works_section"+temp_id).css('display', "none"); | |
$("#works_section_remote"+temp_id).css('display', "none"); | |
} | |
}); | |
} | |
works_find_text_full.addEventListener('input', worksFinderFull); | |
const refreshlist_remote_orig = window.refreshlist_remote | |
window.refreshlist_remote = function (iterpos = 0, force_refresh = false) { | |
refreshlist_remote_orig(iterpos, force_refresh) | |
const mod_search_full_label = document.getElementById('mod_search_full_label') | |
if (mod_search_full_label) { | |
mod_search_full_label.style.display = 'none' | |
} | |
changeDisplay(mod_search_full.checked) | |
} | |
const refreshlist_orig = window.refreshlist | |
window.refreshlist = function () { | |
refreshlist_orig() | |
const mod_search_full_label = document.getElementById('mod_search_full_label') | |
if (mod_search_full_label) { | |
mod_search_full_label.style.display = '' | |
} | |
changeDisplay(mod_search_full.checked) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment