kuy / Wedata Manager
This greasemonkey script works on Wedata and provide various enhancement for editing database items from website.
Clone this repository (size: 24.1 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/kuy/wedata-manager/
| commit 15: | 4757849434b6 |
| parent 14: | eb38a456ac7a |
| branch: | default |
[ItemList] add 'Duplicate' handler [Wedata] add Wedata#createItem method;
- View kuy's profile
-
kuy's public repos »
- CSSocketLib
- libhttpd_sample
- kaerubot
- CSHgCmd
- Google Keyword Highlight
- IdenticonSample
- EndflowControls
- msgdiff
- Wedata Manager
- subscldr
- hgtip-ja-kuy
- win32color
- thg-test
- EFTreeView
- Google Site Image
- GeckoFxHelperSample
- libhttpd
- mercurial-translation-ja
- pxpi
- gm-comps
- thg-web
- GeckoFxSimpleTest
- SharpHg
- qswap
- Hginder
- HginderUI
- dotfiles
- thg-kuy
- thg-ja
- thg-l10n
- Issue Tracker
- Flickr Fav Set
- FirePalette
- GeckoFxHelper
- jsutils
- TreeTool
- Send message
11 months ago
Changed (Δ1.2 KB):
raw changeset »
wedata_manager.user.js (33 lines added, 4 lines removed)
Up to file-list wedata_manager.user.js:
| … | … | @@ -210,6 +210,29 @@ Wedata.prototype.getItem = function(id, |
210 |
210 |
xhr.send(null); |
211 |
211 |
return true; |
212 |
212 |
} |
213 |
Wedata.prototype.createItem = function(db, name, data, callback, thisObj){ |
|
214 |
if(!this.isReady){ |
|
215 |
console.log('Wedata#createItem: not ready'); |
|
216 |
return false; |
|
217 |
} |
|
218 |
var xhr = this._newXHR('POST', '/databases/' + encodeURI(db) + '/items'); |
|
219 |
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
|
220 |
xhr.onreadystatechange = function(){ |
|
221 |
if(xhr.readyState != 4) return; |
|
222 |
if(xhr.status == 201) |
|
223 |
callback.call(thisObj, true); |
|
224 |
else{ |
|
225 |
console.log('Wedata#createItem: failed to create item: ' + xhr.status + ', ' + xhr.responseText); |
|
226 |
callback.call(thisObj, false); |
|
227 |
} |
|
228 |
} |
|
229 |
var body = 'api_key=' + this.apikey + '&name=' + name; |
|
230 |
for(var k in data){ |
|
231 |
body += '&data[' + k + ']=' + data[k]; |
|
232 |
} |
|
233 |
xhr.send(encodeURI(body)); |
|
234 |
return true; |
|
235 |
} |
|
213 |
236 |
Wedata.prototype.deleteItem = function(id, callback, thisObj){ |
214 |
237 |
if(!this.isReady){ |
215 |
238 |
console.log('Wedata#deleteItem: not ready'); |
| … | … | @@ -289,15 +312,21 @@ ItemList.prototype.init = function(){ |
289 |
312 |
var scope = this; |
290 |
313 |
unsafeWindow.wdmgr_delete = function(id){ |
291 |
314 |
setTimeout(function(){ |
292 |
console.log('ItemList#init: wdmgr_delete: func result: ' + scope.wd.deleteItem(id, function(result){ |
|
293 |
console.log('ItemList#init: wdmgr_delete: callback result: ' + result); |
|
315 |
console.log('ItemList#init: del: FN: ' + scope.wd.deleteItem(id, function(result){ |
|
316 |
console.log('ItemList#init: del: CB: ' + result); |
|
294 |
317 |
}, scope)); |
295 |
318 |
}, 0); |
296 |
319 |
} |
297 |
320 |
unsafeWindow.wdmgr_duplicate = function(id){ |
298 |
321 |
setTimeout(function(){ |
299 |
console.log('ItemList#init: wdmgr_duplicate: func result: ' + scope.wd.getItem(id, function(result){ |
|
300 |
console.log('ItemList#init: wdmgr_duplicate: callback result: ' + result); |
|
322 |
console.log('ItemList#init: dup: FN1: ' + scope.wd.getItem(id, function(res1, info){ |
|
323 |
console.log('ItemList#init: dup: CB1: ' + res1.toSource()); |
|
324 |
var tokens = info.database_resource_url.split('/'); |
|
325 |
var db = decodeURI(tokens[tokens.length - 1]); |
|
326 |
console.log('ItemList#init: dup: FN2: ' + scope.wd.createItem(db, |
|
327 |
'Copy of ' + info.name, res1, function(res2){ |
|
328 |
console.log('ItemList#init: dup: CB2: ' + res2); |
|
329 |
}, scope)); |
|
301 |
330 |
}, scope)); |
302 |
331 |
}, 0); |
303 |
332 |
} |
