Greasy Fork

GM_option

support tool for UserConfig.(library)

目前为 2015-04-26 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.icu/scripts/9507/48605/GM_option.js

作者
noisys
版本
1.00
创建于
2015-04-26
更新于
2015-04-26
大小
22.4 KB
许可证
http://creativecommons.org/licenses/by-nc-sa/4.0/




Work on Greasemonkey(Not support Scriptish)


---------------------------------  --------------------------------------------------------------------------------------------------------------------------------------------
script nameGM_option
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
aboutThis script is the library to make a setting screen.
I made this support tool in order to make more easily.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[How to use]Sample code is end of this Script.


If savedata is none....?
first start-up or delete savedata
This script make GM_option window and save default.
next time
This script never make GM_option window without running open-function.


start function----------------------------------------------
GM_option.open(String,String,Array);

first String is HTML Tag(style or script or etc...)
second String is HTML Tag(in document.body).
third Array is optional,it's messages for dialog.

Message List
'save' - when click save button.
'reset' - when click reset button.(discard changes)
'clear' - when click clear button.(delete savedata)
'delete' - when click del button.(delete multiple)


user function--------------------------------------
At first,get user's settings.
GM_option.get();

return hashArray(Associative array).


HTML tag-------------------------------------------
use form inputs.
'name' is save-key.
'value' is save-data.

ex)
HTML tag is...
< input type="text" name="this_is_Key" value="this_is_Data" />

Save Data is...
{"this_is_Key":"this_is_Data"}


multiple text--------------------------------------
'name' is ****_multiple9999.(required)
9999 is number of array.(required)
'value' is default.(optional)
< button id="this_is_required"> is addButton.(required)

ex)
HTML tag is...
< input type="text" name="freeName_multiple2" value="data1" /> add

Save Data is...
{"freeName_multiple2":[["data1","data2"],["data3","data4"], and more ]}


select-multiple(HTML5)----------------------------
selected is checked.(optional)

ex)
HTML tag is...
< select name="selectName" multiple size=5>
< option name="optionName1" value="data1" >item1
< option name="optionName2" value="data2" selected>item2
< option name="optionName3" value="data3" >item3
< option name="optionName4" value="data4" selected>item4
< option name="optionName5" value="data5" >item5

Save Data is...
{"selectName":"{\"data2\":true,\"data4\":true}"}

To use...
var userSettings = GM_option.get();
var selectArray = JSON.parse(userSettings['selectName']);


addEventListener----------------------------------
'GM_option_loaded'

this event is dispatched...
when made GM_option frame (@first start-up)
when loaded User's Settings from GM_getValue (@next time)

ex)
window.addEventListener('GM_option_loaded',userFunction,false);
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
history04/26/2015 - v1.0 release
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------