轻小说文库++的脚本设置界面
Version vom
Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.org/scripts/450210/1085803/wk-settings.js
/* eslint-disable no-multi-spaces */
/* eslint-disable no-implicit-globals */
/* eslint-disable userscripts/no-invalid-headers */
/* eslint-disable userscripts/no-invalid-grant */
// ==UserScript==
// @name wk-settings
// @displayname 设置界面
// @namespace Wenku8++
// @version 0.1.2
// @description 轻小说文库++的脚本设置界面
// @author PY-DNG
// @license GPL-v3
// @regurl https?://www\.wenku8\.net/.*
// @require https://greasyfork.org/scripts/449412-basic-functions/code/Basic%20Functions.js?version=1085783
// @require https://greasyfork.org/scripts/449583-configmanager/code/ConfigManager.js?version=1085356
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_listValues
// @grant ML_listModules
// @grant ML_disableModule
// @grant ML_enableModule
// @grant ML_uninstallModule
// @grant ML_moduleLoaded
// @protect
// ==/UserScript==
(function __MAIN__() {
const ASSETS = require('assets');
const alertify = require('alertify');
const SPanel = require('SidePanel');
const SettingPanel = require('SettingPanel');
const CONST = {
Text: {
Button: '设置',
Title: '脚本设置',
ModuleManage: '模块管理',
OpenModuleDialog: '点此打开管理面板',
ModuleSettings: '模块设置',
Module: '模块',
Operation: '操作',
DisableModule: '禁用模块',
EnableModule: '启用模块',
UninstallModule: '卸载模块',
AlertTitle: '模块设置界面',
NoLoadNoSettings: '模块并未在此页面上运行,无法获取设置',
NoSettings: '该模块当前并没有提供设置选项',
},
Config_Ruleset: {
'version-key': 'config-version',
'ignores': ["LOCAL-CDN"],
'defaultValues': {
//'config-key': {},
},
'updaters': {
/*'config-key': [
function() {
// This function contains updater for config['config-key'] from v0 to v1
},
function() {
// This function contains updater for config['config-key'] from v1 to v2
}
]*/
}
}
};
SPanel.Add({
faicon: 'fa-solid fa-gear',
tip: CONST.Text.Button,
onclick: function() {
const win = window.open('https://www.wenku8.net/userdetail.php');
setPageUrl(win, 'https://www.wenku8.net/userdetail.php?tosettings=true');
}
});
const UMManager = new UserModuleManager();
isSettingPage(main);
exports = {
isSettingPage: isSettingPage,
insertLines: insertLines,
registerSettings: UMManager.registerModuleSettings
};
function main() {
// Get elements
const content = $('#content');
// Insert settings
const title = [
[{html: CONST.Text.Title, colSpan: 3, class: 'foot', key: 'settitle'}],
[{html: CONST.Text.ModuleManage, colSpan: 1}, {html: CONST.Text.OpenModuleDialog, colSpan: 2, onclick: UMManager.show}],
//[{html: CONST.Text.XXXX, colSpan: 1, key: 'xxxxxxxx'}, {html: CONST.Text.XXXX, colSpan: 2, key: 'xxxxxxxx'}],
]
const elements = insertLines(title);
// scrollIntoView if need
getUrlArgv('tosettings') === 'true' && elements.settitle.scrollIntoView();
}
// Module manager user interface
function UserModuleManager() {
const UMM = this;
const moduleSettingFuncs = {};
UMM.show = show;
UMM.registerModuleSettings = registerModuleSettings;
UMM.showModuleSettings = showModuleSettings;
function show() {
//box.set('message', 'No implemented yet!').show();
const modules = ML_listModules();
// Make panel
const SetPanel = new SettingPanel.SettingPanel({
header: CONST.Text.ModuleManage,
tables: []
});
// Make table
const table = new SetPanel.PanelTable({});
// Make header
table.appendRow({
blocks: [{
isHeader: true,
colSpan: 1,
width: '60%',
innerText: CONST.Text.Module,
},{
isHeader: true,
colSpan: 3,
width: '40%',
innerText: CONST.Text.Operation,
}]
});
// Make module rows
for (const module of modules) {
const row = new SetPanel.PanelRow({
blocks: [{
colSpan: 1,
rowSpan: 1,
innerText: module.displayname
},{
colSpan: 1,
rowSpan: 1,
children: [makeBtn(CONST.Text.ModuleSettings, showModuleSettings.bind(null, module.identifier))]
},{
colSpan: 1,
rowSpan: 1,
children: [makeBtn(CONST.Text.DisableModule, ML_disableModule.bind(null, module.identifier))]
},{
colSpan: 1,
rowSpan: 1,
children: [makeBtn(CONST.Text.EnableModule, ML_enableModule.bind(null, module.identifier))]
},{
colSpan: 1,
rowSpan: 1,
children: [makeBtn(CONST.Text.UninstallModule, ML_uninstallModule.bind(null, module.identifier))]
}]
});
table.appendRow(row);
}
SetPanel.appendTable(table);
function makeBtn(text, onclick) {
const span = $CrE('span');
span.innerText = text;
span.addEventListener('click', onclick);
span.classList.add(ASSETS.ClassName.Button);
return span;
}
}
function registerModuleSettings(id, func) {
moduleSettingFuncs[id] = func;
}
function showModuleSettings(id) {
const func = moduleSettingFuncs[id];
if (typeof func === 'function') {
func();
return true;
} else {
if (!ML_moduleLoaded(id)) {
alertify.alert(CONST.Text.AlertTitle, CONST.Text.NoLoadNoSettings);
} else {
alertify.alert(CONST.Text.AlertTitle, CONST.Text.NoSettings);
}
return false;
}
}
}
function insertLines(lines, tbody) {
!tbody && (tbody = $(content, 'table>tbody'));
const elements = {};
for (const line of lines) {
const tr = $CrE('tr');
for (const item of line) {
const td = $CrE('td');
item.html && (td.innerHTML = item.html);
item.colSpan && (td.colSpan = item.colSpan);
item.class && (td.className = item.class);
item.id && (td.id = item.id);
item.tiptitle && settip(td, item.tiptitle);
item.key && (elements[item.key] = td);
if (item.onclick) {
td.style.color = 'grey';
td.style.textAlign = 'center';
td.addEventListener('click', item.onclick);
}
td.style.padding = '3px';
tr.appendChild(td);
}
tbody.appendChild(tr);
}
return elements;
}
function isSettingPage(callback) {
const page = getAPI()[0] === 'userdetail.php';
page && callback && callback();
return page;
}
// Change location.href without reloading using history.pushState/replaceState
function setPageUrl() {
let win, url, push;
switch (arguments.length) {
case 1:
win = window;
url = arguments[0];
push = false;
break;
case 2:
win = arguments[0];
url = arguments[1];
push = false;
break;
case 3:
win = arguments[0];
url = arguments[1];
push = arguments[2];
}
return win.history[push ? 'pushState' : 'replaceState']({modified: true, ...history.state}, '', url);
}
})();