1
1
// insert our prototype and scriptaculous scripts into the page
2
+ // vim:set encoding=utf-8:
2
3
try {
3
4
for ( var i = 0 ; i < script_arr . length ; i ++ )
4
5
{
@@ -26,7 +27,12 @@ function tagSelector(instance) {
26
27
else
27
28
entry = entry . replace ( / \* / g, '%' ) ;
28
29
29
- if ( instance . options . isSearchField && entry [ 0 ] == '-' ) entry = entry . substr ( 1 ) ;
30
+ if ( instance . options . isSearchField &&
31
+ ( entry [ 0 ] == '-' || entry [ 0 ] == '~' )
32
+ )
33
+ {
34
+ entry = entry . substr ( 1 ) ;
35
+ }
30
36
31
37
tags = danbooruUpSearchTags ( entry ) ;
32
38
@@ -45,7 +51,7 @@ function tagSelector(instance) {
45
51
return "<ul><li>" + tags . slice ( 0 , instance . options . choices ) . join ( '</li><li>' ) + "</li></ul>" ;
46
52
}
47
53
48
- // get the pixel height of an A element to size things in multiples of lines
54
+ // get the pixel height of the A element after the big danbooru link to size things in multiples of lines
49
55
try {
50
56
var lineHeight = document . getElementsByTagName ( "a" ) [ 1 ] . offsetHeight ;
51
57
} catch ( e ) { lineHeight = 16 ; }
@@ -58,27 +64,63 @@ style.innerHTML = ".danbooruup-ac { border: 1px solid black; overflow: auto; bac
58
64
".danbooruup-ac li.selected { background: #ffc; }" ;
59
65
document . getElementsByTagName ( "head" ) [ 0 ] . appendChild ( style ) ;
60
66
61
- // create the autocomplete popup
62
- if ( document . getElementById ( "search" ) )
67
+ function createAC ( elementID , options )
63
68
{
64
- var div1 = document . createElement ( "div" ) ;
65
- div1 . setAttribute ( "id" , "danbooruup-autocomplete" ) ;
66
- div1 . setAttribute ( "class" , "danbooruup-ac" ) ;
67
- div1 . style . display = 'none' ;
68
- document . body . appendChild ( div1 ) ;
69
+ try {
70
+ var foptions = { tokens :[ ' ' , ' ' ] , choices :150 , selector :tagSelector } ;
71
+ var ac = null ;
72
+
73
+ options = options || { } ;
74
+ for ( var p in options ) {
75
+ foptions [ p ] = options [ p ] ;
76
+ }
69
77
70
- ac = new Autocompleter_DanbooruUp ( "search" , "danbooruup-autocomplete" , [ ] , { tokens :[ ' ' , ' ' ] , choices :150 , selector :tagSelector , isSearchField : true } ) ;
78
+ if ( document . getElementById ( elementID ) )
79
+ {
80
+ var div = document . createElement ( "div" ) ;
81
+ var divid = "danbooruup-" + elementID + "-autocomplete" ;
82
+ div . setAttribute ( "id" , divid ) ;
83
+ div . setAttribute ( "class" , "danbooruup-ac" ) ;
84
+ div . style . display = 'none' ;
85
+ document . body . appendChild ( div ) ;
86
+
87
+ ac = new Autocompleter_DanbooruUp ( elementID , divid , [ ] , foptions ) ;
88
+ }
89
+ return ac ;
90
+ } catch ( ee ) { GM_log ( "danbooruUp: while inserting for " + elementID + ":\n" + ee ) ; }
71
91
}
72
92
93
+ // create the autocomplete popups
94
+ // for post/list
95
+ if ( document . location . href . match ( / \/ p o s t \/ l i s t ( \/ | $ ) / ) )
96
+ {
97
+ createAC ( "search" , { isSearchField : true } ) ;
98
+ }
73
99
// for post/view and post/add
74
- if ( document . getElementById ( "post_tags" ) )
100
+ else if ( document . location . href . match ( / \/ p o s t \/ ( v i e w | a d d ) ( \/ | $ ) / ) )
75
101
{
76
- div2 = document . createElement ( "div" ) ;
77
- div2 . setAttribute ( "id" , "danbooruup-pt-autocomplete" ) ;
78
- div2 . setAttribute ( "class" , "danbooruup-ac" ) ;
79
- div2 . style . display = 'none' ;
80
- document . body . appendChild ( div2 ) ;
81
-
82
- ac2 = new Autocompleter_DanbooruUp ( "post_tags" , "danbooruup-pt-autocomplete" , [ ] , { tokens :[ ' ' , ' ' ] , choices :150 , selector :tagSelector } ) ;
102
+ createAC ( "post_tags" ) ;
103
+ }
104
+ // for rename, set_type
105
+ else if ( document . location . href . match ( / \/ t a g \/ ( r e n a m e | s e t _ t y p e ) ( \/ | $ ) / ) )
106
+ {
107
+ createAC ( "tag" , { isSearchField : true } ) ;
108
+ }
109
+ // for mass_edit
110
+ else if ( document . location . href . match ( / \/ t a g \/ m a s s _ e d i t ( \/ | $ ) / ) )
111
+ {
112
+ createAC ( "start" , { isSearchField : true } ) ;
113
+ createAC ( "result" ) ;
114
+ }
115
+ // for alias
116
+ else if ( document . location . href . match ( / \/ t a g \/ a l i a s ( \/ | $ ) / ) )
117
+ {
118
+ createAC ( "name" , { isSearchField : true } ) ;
119
+ createAC ( "alias" , { isSearchField : true } ) ;
120
+ }
121
+ // for implications
122
+ else if ( document . location . href . match ( / \/ t a g \/ i m p l i c a t i o n s ( \/ | $ ) / ) )
123
+ {
124
+ createAC ( "child" , { isSearchField : true } ) ;
125
+ createAC ( "parent" , { isSearchField : true } ) ;
83
126
}
84
-
0 commit comments