Skip to content

Commit 4c8ff0d

Browse files
author
buffered
committed
fixed substring comparison in tag service
added tag/* pages to site AC helper now calls autoRegister after renaming platform directory
1 parent 9ffaeb7 commit 4c8ff0d

File tree

3 files changed

+84
-34
lines changed

3 files changed

+84
-34
lines changed

chrome/content/danbooruup/extra/ac-insert.js

+61-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// insert our prototype and scriptaculous scripts into the page
2+
// vim:set encoding=utf-8:
23
try {
34
for(var i=0; i < script_arr.length; i++)
45
{
@@ -26,7 +27,12 @@ function tagSelector(instance) {
2627
else
2728
entry = entry.replace(/\*/g, '%');
2829

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+
}
3036

3137
tags = danbooruUpSearchTags(entry);
3238

@@ -45,7 +51,7 @@ function tagSelector(instance) {
4551
return "<ul><li>" + tags.slice(0, instance.options.choices).join('</li><li>') + "</li></ul>";
4652
}
4753

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
4955
try {
5056
var lineHeight = document.getElementsByTagName("a")[1].offsetHeight;
5157
} catch(e) { lineHeight = 16; }
@@ -58,27 +64,63 @@ style.innerHTML = ".danbooruup-ac { border: 1px solid black; overflow: auto; bac
5864
".danbooruup-ac li.selected { background: #ffc; }";
5965
document.getElementsByTagName("head")[0].appendChild(style);
6066

61-
// create the autocomplete popup
62-
if(document.getElementById("search"))
67+
function createAC(elementID, options)
6368
{
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+
}
6977

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); }
7191
}
7292

93+
// create the autocomplete popups
94+
// for post/list
95+
if(document.location.href.match(/\/post\/list(\/|$)/))
96+
{
97+
createAC("search", {isSearchField: true});
98+
}
7399
// for post/view and post/add
74-
if(document.getElementById("post_tags"))
100+
else if(document.location.href.match(/\/post\/(view|add)(\/|$)/))
75101
{
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(/\/tag\/(rename|set_type)(\/|$)/))
106+
{
107+
createAC("tag", {isSearchField: true});
108+
}
109+
// for mass_edit
110+
else if(document.location.href.match(/\/tag\/mass_edit(\/|$)/))
111+
{
112+
createAC("start", {isSearchField: true});
113+
createAC("result");
114+
}
115+
// for alias
116+
else if(document.location.href.match(/\/tag\/alias(\/|$)/))
117+
{
118+
createAC("name", {isSearchField: true});
119+
createAC("alias", {isSearchField: true});
120+
}
121+
// for implications
122+
else if(document.location.href.match(/\/tag\/implications(\/|$)/))
123+
{
124+
createAC("child", {isSearchField: true});
125+
createAC("parent", {isSearchField: true});
83126
}
84-

components/danbooru/nsDanbooruTagHistoryService.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,17 @@ NS_strlen(const PRUnichar *aString)
168168
}
169169

170170
static PRBool
171-
Equals(const nsAString &str, const PRUnichar *other, ComparatorFunc c)
171+
Equals(const nsAString &str, const nsDependentSubstring &other, ComparatorFunc c)
172172
{
173-
const PRUnichar *cself;
173+
const PRUnichar *cself, *cother;
174174
PRUint32 selflen = NS_StringGetData(str, &cself);
175-
PRUint32 otherlen = NS_strlen(other);
175+
NS_StringGetData(other, &cother);
176+
PRUint32 otherlen = other.Length();
176177

177178
if (selflen != otherlen)
178179
return PR_FALSE;
179180

180-
return c(cself, other, selflen) == 0;
181+
return c(cself, cother, selflen) == 0;
181182
}
182183

183184
static nsICaseConversion* gCaseConv = nsnull;
@@ -251,8 +252,8 @@ void ReplaceSubstring(nsAString& str,
251252
}
252253

253254
nsDanbooruTagHistoryService::nsDanbooruTagHistoryService() :
254-
mRequest(nsnull),
255-
mDB(nsnull)
255+
mDB(nsnull),
256+
mRequest(nsnull)
256257
{
257258
}
258259

@@ -944,9 +945,7 @@ nsDanbooruTagHistoryService::AutoCompleteSearch(const nsAString &aInputName,
944945
}
945946

946947
nsDependentSubstring sub = Substring(name, 0, aInputName.Length());
947-
const PRUnichar *sd;
948-
NS_StringGetData(sub, &sd);
949-
if (!Equals(aInputName, sd, CaseInsensitiveCompare))
948+
if (!Equals(aInputName, sub, CaseInsensitiveCompare))
950949
result->RemoveValueAt(i, PR_FALSE);
951950
}
952951
} else {

components/danbooruUpHelper.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ this.log(this.browserWindows.length+' after unregistering');
325325
var uri = ioService.newURI(sites[i], null, null);
326326
if (winUri.prePath != uri.prePath) continue;
327327
//this.log(winUri.spec+' matched ' + uri.spec);
328-
if (winUri.path.match(/\/post\/(list|view|add)(\/|$)/)) {
328+
if (winUri.path.match(/\/post\/(list|view|add)(\/|$)/) ||
329+
winUri.path.match(/\/tag\/(mass_edit|rename|alias|implications|set_type)(\/|$)/)) {
329330
this.inject(href, unsafeWin);
330331
return;
331332
}
@@ -418,6 +419,8 @@ var HelperModule = new Object();
418419

419420
HelperModule.registerSelf = function(compMgr, fileSpec, location, type)
420421
{
422+
var compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar);
423+
421424
if (!this._deferred)
422425
{
423426
this._deferred = true;
@@ -426,30 +429,37 @@ HelperModule.registerSelf = function(compMgr, fileSpec, location, type)
426429
try {
427430
if (Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS == 'linux-gnu')
428431
{
429-
__log("linux-gnu detected");
432+
//__log("linux-gnu detected");
430433
// find the extension directory
431434
var dirs = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties)
432435
.get("XREExtDL", Ci.nsISimpleEnumerator);
433436
var dir;
434437
while(dirs.hasMoreElements())
435438
{
436439
dir = dirs.getNext().QueryInterface(Ci.nsILocalFile);
437-
__log("checking "+dir.path);
440+
//__log("checking "+dir.path);
438441
if(dir.leafName == '{7209145A-6A2A-42C1-99EB-4DE7293990E1}')
439442
break;
440443
dir = null;
441444
}
442445
// rename the platform component directory
443446
if (dir)
444447
{
445-
__log("locked on");
448+
//__log("locked on");
446449
var moveDir;
447450
dir.append('platform');
448451
moveDir = dir.clone();
449452
moveDir.append('Linux_x86-gcc3');
450-
__log("using "+moveDir.path+(moveDir.exists?" (exists)":" (doesn't exist)"));
453+
//__log("using "+moveDir.path+(moveDir.exists?" (exists)":" (doesn't exist)"));
451454
if(moveDir.exists())
455+
{
452456
moveDir.moveTo(dir, 'linux-gnu_x86-gcc3');
457+
// moveDir will still point to the old path, so we need to use dir
458+
dir.append('linux-gnu_x86-gcc3');
459+
dir.append('components');
460+
__log("danbooruUpHelper: registering "+dir.path);
461+
compMgr.autoRegister(dir);
462+
}
453463
}
454464
}
455465
} catch(ex) {
@@ -459,7 +469,6 @@ __log("using "+moveDir.path+(moveDir.exists?" (exists)":" (doesn't exist)"));
459469
throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
460470
}
461471

462-
var compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar);
463472
compMgr.registerFactoryLocation(DANBOORUUPHELPER_CID,
464473
"Danbooru Helper Service",
465474
DANBOORUUPHELPER_CONTRACTID,

0 commit comments

Comments
 (0)