This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·1355 lines (1194 loc) · 41.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>4485 md5ro</title>
<link rel="shortcut icon" href="http://netgear.rohidekar.com/static/icons/Orb_Icons_004.png" type="image/x-icon" />
<!-- <script src="http://www.kryogenix.org/code/browser/sorttable/sorttable.js" type="text/javascript"></script> -->
<link rel="stylesheet" href="http://jqueryui.com/jquery-wp-content/themes/jqueryui.com/style.css">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script>
<script src="http://netgear.rohidekar.com/md5ro/jquery/jquery-ui.js"></script>
<script src="http://netgear.rohidekar.com/md5ro/js/imagezoom.ssarnobat.js"></script>
<script type="text/javascript" src="http://netgear.rohidekar.com/md5ro/jquery/purl.js"></script>
<!-- we can't use the kb_shortcuts API because you can't keep the shift key held down in between keypresses -->
<script src="http://netgear.rohidekar.com/md5ro/js/webtoolkit.md5.js"></script>
<script>
var host = "http://netgear.rohidekar.com";
// TODO: Don't use this
var urlBase = "http://netgear.rohidekar.com:44485/md5ro";
var rootId;
var parentOfRootId;
var orderedDescending = true;
var readyToRender = false;
var limit;
var uncategorizedResponse; // Populated via rest call
var categories; // Populated via rest call
var biggestImages = {};
var IMAGE_SIZE = 100; // for thumbnails
var imageSize = 300; // for cards
function initialize() {
initializeBeforeAjax();
////
//// Uncategorized URLs (main part)
////
$.when(
$.ajax(host + ":44485/md5ro/uncategorized?rootId=" +rootId),
$.ajax(host + "/md5ro/iphone_categories.txt"),
$.ajax(host + "/md5ro/copy_events.txt?cacheBust=" + Math.random())
)
.done(function(a1, a2, copyEvents){
var alreadyCopied = {};
copyEvents[0].split('\n').forEach(function(line){
alreadyCopied[line.split('::')[0]] = line.split('::')[1];
});
var folders = a2[0].split('\n');
var buttonsHtml = folders.sort(function (a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
}).map(function(categoryName) {
return "<input type=button class='genericButton' "
+ " value='" + categoryName + "'"
+ " onclick='copy(this)' "
+ " style='background-color:" + getColorForDir(categoryName)
+ "'>";
})
.reduce(function(acc, tag){
return acc + " " + tag;
}, "");
var images =
//shuffle(
a1[0].split('\n')
//)
//.splice(0, 50)
.reverse()
;
var i = 0;
$("#url_cards").append(
"<ol>"
//+ shuffle(
+ images.filter(function(line) {
var pair = line.split('::');
var md5 = pair[0];
if (alreadyCopied.hasOwnProperty(md5)) {
return false;
} else {
return true;
}
})
.filter(function(line) {
var pair = line.split('::');
var filePath = pair[1];
if (filePath == null) {
pair = line.split(' ');
filePath = pair[1];
//debugger;
}
var matchesVideo = filePath.match(/.*((mp4)|(webm)|(mov)|(mkv)|(flv)|(avi)|(mts))/gi);
var matchesTxt = filePath.match(/.*((txt)|(log))/gi);
var ignore = filePath.match(/.*\.((jp2)|(dat))/gi);
if (matchesVideo != null) {
return false;
} else if (matchesTxt !=null) {
return false;
} else if (ignore !=null) {
return false;
} else {
return true;
}
})
.slice(0,limit)
.map(function(item) {
var pair = item.split('::');
var md5 = pair[0];
var filePath = pair[1];
if (filePath == null) {
pair = item.split(' ');
filePath = pair[1];
//debugger;
}
return {
md5 : pair[0],
filepath : filePath,
url : 'http://netgear.rohidekar.com:44452' + filePath,
};
})
//)
.filter(function(fileObj){
if (fileObj.filepath == null) {
// console.debug('filtered out: ' + fileObj);
// return false;
debugger;
}
// // filter out rsync dotfile junk
var filename = fileObj.filepath.replace(/^.*[\\\/]/, '');
var rsyncEmptyJunk = (/\..+\..+\..+/.test(filename));
if (rsyncEmptyJunk) {
// Why is this not getting printed?
console.debug(filename);
//debugger;
return false;
}
return true;
})
.map(function(fileObj) {
var cardHtml = "";
cardHtml += "<img src='" + fileObj.url + "' height=250><br>" +fileObj.md5+ "<br><textarea cols=50>" + fileObj.filepath+"</textarea><br><hr width=500><br>";
return cardHtml;
}).map(function(item) {
++i;
return "<a id='anchor"+i+"'>"
+ "<li class='buttonize' style='background-color: #FDFD96'>"
+ "<table>"
+ "<tr>"
+ "<td>"
+ buttonsHtml
+ "</td>"
+ "<td>"
+ item
+ "</td>"
+ "</tr>"
+ "</table>"
+ "</li>"
+ "</a>";
}).reduce(function(acc, tag){
return acc + " " + tag;
}, "")
+ "</ol>"
);
$("#url_thumbnails").append(
images.map(function(item) {
var pair = item.split('::');
var filePath = pair[1];
return {
md5 : pair[0],
filepath : filePath,
url : 'http://netgear.rohidekar.com:44452' + filePath,
};
}).map(function(fileObj) {
return "<img src='" + fileObj.url + "' height=75>";
}).reduce(function(acc, tag){
return acc + " " + tag;
}, "")
);
location.href = "#";
location.href = "#anchor20";
});
}
function getColorForDir(dirName) {
var color = "";
if (dirName == 'other' || dirName == 'divas') {
color = 'pink';
} else if (dirName.match(/Atletico_whatsapp/i) || dirName == 'brst') {
color = '#ff5959';
} else if (dirName.match(/Atletico/i) || dirName == 'brst') {
color = 'red';
}
else if (dirName.match(/Liverpool/i)) {
color = 'red';
}
else if (dirName == 'legs') {
color = 'yellow';
} else if (dirName == 'navel') {
color = 'lightpurple';
} else if (dirName == 'teen') {
color = 'lavender';
} else if (dirName.match(/productivity/i)) {
color = 'yellow';
} else if (dirName.match(/soccer/i)) {
color = 'green';
} else if (dirName == 'ind') {
color = 'orange';
} else if (dirName == 'originals') {
color = 'orange';
} else if (dirName == 'whatsapp') {
color = 'white';
} else if (dirName == 'matrimonial') {
color = '#afffe5';
} else if (dirName == 'post_it_notes') {
color = 'yellow';
} else if (dirName == 'Sridhar') {
color = '#4a662d';
} else if (dirName == 'screenshots') {
color = '#d1ecff';
}
return color;
}
var fileServerPrefix = "http://netgear.rohidekar.com:44452";
function copy(button) {
// TODO: get the file path
var subdirSimpleName = button.value;
var filePath = button.parentElement.parentElement.parentElement.children[0].children[1].children[0].src.replace(fileServerPrefix, '');
var parentDirPath = getParentPath(filePath);
return copyFileToFolder(filePath,
// '/media/sarnobat/Unsorted/new/Photos/iPhone/' // does not work
'/media/sarnobat/3TB/new/move_to_unsorted/iphone/'
// '/media/sarnobat/Large/trash/' // works
// '/media/sarnobat/3TB/trash/' // works
// '/home/sarnobat/trash/' // works
// '/media/sarnobat/e/trash/' // works
// '/media/sarnobat/Large/new/photos/iPhone/' // symlink to Unsorted, does not work
+subdirSimpleName, button);
}
function getParentPath(filePath) {
return filePath.split('/').slice(-2).join('/');
}
function copyFileToFolder(filePath, destinationDirPath, button) {
var li = button.parentElement.parentElement.parentElement.parentElement.parentElement.remove();
// debugger;
$.getJSON(host + ":44486/md5ro/copyToFolder?filePath="+encodeURIComponent(filePath) + "&destinationDirPath=" + encodeURIComponent(destinationDirPath), function(response) {
$(button).css('background-color','green');
//debugger;
// TODO: remove element (like with move)
// button.parentElement.remove();
}).done(function(){
console.debug("success");
})
.fail(function(){
alert("!!!! FAILURE !!!!");
});
$(button).css('background-color','orange');
//button.parentElement.style.backgroundColor="rgb(0,0,0)"
button.parentElement.style.height="0px"
button.parentElement.style.height="hidden"
//debugger;
}
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex ;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
// Map function
function CATGORY_TREE_TO_LINKS_HTML(categoryNode) {
var category = categoryNode;
return "<input type=checkbox value=false name=" + category.id + ">"
+ "<a href='/md5ro/?rootId=" + category.id + "' style='text-transform:capitalize;'>"
+ category.name + " (" + category.id + ")"
+ "</a>"
+ "</input>"
+ "<br>"
+ "<ul>"
+ category.children.map(CATGORY_TREE_TO_LINKS_HTML).join("</li><li>")
+ "</ul>"
;
}
// Reduction function
function CATEGORY_TO_LINK(accumulator, categoryNode) {
var category = categoryNode;
return accumulator + "<input type=checkbox value=false name=" + category.id + ">"
+ "<a href='/md5ro/?rootId=" + category.id + "' style='text-transform:capitalize;'>"
+ category.name + " (" + category.id + ")"
+ "</a>"
+ "</input>"
+ "<br>";
}
function renderIfReady() {
if (!uncategorizedResponse) {
return;
}
if (!uncategorizedResponse.categoriesRecursive) {
debugger;
}
categories = getCategoriesUnderID2(uncategorizedResponse.categoriesRecursive, rootId);
configureKeyBindings();
$("#status").text("Populating");
//var categoryOrdinal = 0;
var categoryIdsToNames = getCategoryNamesMap(uncategorizedResponse.categoriesRecursive);
var urls = uncategorizedResponse.urls;
var categoryIdsUnderRootOrdered = putRootAtFront(urls, rootId);
var cardsHtml = "";
{
var urlsRootOnly = uncategorizedResponse.urls[rootId];
if (urlsRootOnly != null) {
//var headLength = 10;
//var truncated =
// This doesn't return the new list unfortunately. It will cause the thumbnails to also get truncated
//urlsRootOnly.splice(headLength, urlsRootOnly.length - 1 - headLength);
//console.debug("remaining elements: " + truncated.length + " of " + urlsRootOnly.length);
var childCategories = findCategoryChildren(uncategorizedResponse.categoriesRecursive, rootId);
cardsHtml = urlsRootOnly
.map(function(i){ if (i.ordinal < 9999999999) { i.ordinal = i.ordinal * 1000; }; return i;})
.sort(function (u1, u2) {return u2.ordinal - u1.ordinal ;})
.slice(0, limit)
.map(ITEM_TO_HTML(childCategories, rootId, parentOfRootId)).join("\n");
}
}
var urlThumbnailsHtml = "";
var urlListHtml = "";
var tableHtml = "";
var productsHtml = "";
var markupHtml = "";
for (var i = 0; i < categoryIdsUnderRootOrdered.length; ++i) {
var categoryId = categoryIdsUnderRootOrdered[i];
var categoryName = categoryIdsToNames[categoryId];
var urlsForCategory = urls[categoryId];
urlThumbnailsHtml += getCategoryThumbnailsHtml(categoryId, categoryIdsToNames[categoryId], urls[categoryId], limit);
tableHtml += getCategoryTableHtml(categoryId, categoryName, urlsForCategory);
urlListHtml += getCategoryListHtml(categoryId, categoryIdsToNames[categoryId], urls[categoryId]);
productsHtml += getProductsHtml(categoryId, categoryName, urlsForCategory);
markupHtml += "<h1>" + categoryName + "</h1>\n\n" + urlsForCategory.map(ITEM_TO_IMAGE).join("\n");
}
$("#url_cards").append(cardsHtml);
$("#url_thumbnails").append(urlThumbnailsHtml);
$("#url_table").append(tableHtml);
$("#list").append(urlListHtml);
$("#products").append(productsHtml);
$("#htmlText").val(markupHtml);
}
function initializeBeforeAjax() {
////
//// Determine the root ID
////
getRootId: {
rootId = $.url().param('rootId');
}
updateURL: {
if (rootId == null || rootId == '') {
rootId = 45;
history.pushState(null, null, '/md5ro?rootId=' + rootId); // HTML5
}
}
showLoading : {
$("#status").text("Loading");
}
setColorForCategory : {
var rootColor = MD5(rootId.toString()).substring(0,6);
$("#rootColor").attr("style", "background-color: #" + rootColor);
}
limit = $.url().param('limit');
if (limit == null) {
limit = 50;
window.history.pushState("object or string", "Title", document.URL + "&limit=50");
}
}
function fillThumbnailItem(resultRowNumber, field, result, limit, biggestImages, categories) {
if (resultRowNumber > limit && resultRowNumber < result.length - 10) {
return;
}
var toBeAppended = createImageCell(field, biggestImages, IMAGE_SIZE, resultRowNumber);
$("#url_thumbnails").append(toBeAppended);
}
function getDownloadedVideoColor(downloaded) {
if ("null" == downloaded) {
return "red";
}
if (!downloaded) {
return "red";
}
return "green";
}
function ITEM_TO_IMAGE(item) {
return createImageCell(item)[0].outerHTML;
}
// Creates a JQquery DOM element
// field = item
function createImageCell(field) {
var imageCell = "";
var hasScreenshot = false;
{
if (field.url.match(".jpg\??") ||
field.url.match(/.*jpg/i) ||
field.url.match(".gif$") ||
field.url.match(".png\??") ||
field.url.match("images.q=tbn:")) {
imageCell += ("<img class=itemImage src='"+field.url+"' height="+imageSize+" onmouseenter='zoom(this)' title='" +field.title+ "'>");
hasScreenshot = true;
}
if (field.user_image != null) {
imageCell += ("<img class=itemImage src=\""+ field.user_image +"\" class='screenshot' width="+imageSize+" />");
hasScreenshot = true;
} else if (field.url.match("youtube.com")) {
if (field.url.match("youtube.com/watch")) {
var youtubeId = field.url.replace(/^https?:..www.youtube.com.watch.*v=([^&]+).*/g,'$1');
imageCell += ("");
imageCell += ("<img class=itemImage src='http://img.youtube.com/vi/"+youtubeId+"/0.jpg' width="+imageSize+" title='" +field.title+ "'>");
imageCell += ("");
imageCell += ("");
imageCell += ("");
hasScreenshot = true;
}
} else if (field.url.match("dailymotion.com/video")) {
var youtubeId = field.url.replace(/^http.*video.([^?]+)(.*)/g,'$1');
imageCell += ("");
imageCell += ("<img class=itemImage src='http://dailymotion.com/thumbnail/video/"+youtubeId +"' width="+imageSize+" title='" +field.title+ "'>");
imageCell += ("");
imageCell += ("");
imageCell += ("");
hasScreenshot = true;
} else if (field.url.match(".amazon.co[^/]+\/[^s]")) {
//else if (false) {
imageCell += ("");
var asin = field.url.replace(/.+((dp)|(product))\/([^\/?]+)[\/?].*/,'$4');
asin = asin.replace(/.*dp./,'');
asin = asin.replace(/.*gp.aw.d./, '');
asin = asin.replace(/.ref_?=.*/, '');
asin = asin.replace(/.*offer-listing./, '');
var productImageUrl = 'http://images.amazon.com/images/P/'+asin+'.01.LZZZZZZZ.jpg';
imageCell += ("<img class=itemImage src='"+productImageUrl+"' height='280' title='" +field.title+ "'>");
hasScreenshot = true;
}
}
if (!hasScreenshot) {
imageCell += ("<img class=itemImage src=\"http://free.pagepeeker.com/v2/thumbs.php?size=x&url="+encodeURIComponent(field.url)+"\" class='screenshot' width="+imageSize+" title='" +field.title+ "'/>");
// Check if the biggest image server is up
if (biggestImages != null) {
if (biggestImages[field.url] != null) {
imageCell += ("<img class=itemImage src=\""+ biggestImages[field.url] +"\" class='screenshot' width="+imageSize+" />");
}
}
}
// Tooltip
var img = $($.parseHTML("<a href='"+field.url+"' title='" +field.title+ "' >" + imageCell + "</a>"));
/* img.tooltip({
items: "img",
content: field.title + "<br><font style=\"font-size : xx-small \">"+field.url+"</font>",
}); */
return img;
}
function relateNew(newParentId, currentRootId, button) {
if (newParentId == null) {
alert("newParentId = " + newParentId);
return;
}
var liElem = button.parentElement.parentElement.parentElement.parentElement.parentElement;
var url = $(liElem).attr("url");
var created = $(liElem).attr("created");
var categoryId = $(liElem).attr("categoryId");
url = urlBase + "/relate?parentId=" +newParentId+"&url=" + encodeURIComponent(url) + "¤tParentId=" + categoryId + "&created=" + created;
var parentId = newParentId;
removeTopNew(newParentId, liElem);
//
// The main part
//
$.getJSON(url, function(result){})
.success(function() {
$("#list_"+parentId).effect("highlight", null, 4000, function() {});
// Change the destination category count
var count = parseInt($("#count_"+parentId).text()) + 1;
$("#count_"+parentId).text(count);
$("#count_"+parentId).css("font-weight","Bold");
// Decrement the number of items in this category that is displayed
var newCount = parseInt($("#count").text());
newCount -= 1;
$("#count").text(newCount);
})
.error(function() { alert("error occurred "); })
.complete(function() { });
}
function relate(parentId, childId, currentRootId) {
removeTop(parentId, childId);
var url = urlBase + "/relate?parentId=" +parentId+"&childId=" + childId + "¤tParentId=" + currentRootId;
//
// The main part
//
$.getJSON(url, function(result){})
.success(function() {
$("#list_"+parentId).effect("highlight", null, 4000, function() {});
// Change the destination category count
var count = parseInt($("#count_"+parentId).text()) + 1;
$("#count_"+parentId).text(count);
$("#count_"+parentId).css("font-weight","Bold");
// Decrement the number of items in this category that is displayed
var newCount = parseInt($("#count").text());
newCount -= 1;
$("#count").text(newCount);
})
.error(function() { alert("error occurred "); })
.complete(function() { });
}
function createAndRelate(childId, currentRootId) {
var newParentName = prompt('Category name:');
removeTopNoDest(childId);
var url = urlBase + "/createAndRelate?newParentName=" +encodeURIComponent(newParentName)+"&childId=" + childId + "¤tParentId=" + currentRootId;
//
// The main part
//
$.getJSON(url, function(result){})
.success(function() {
})
.error(function() { alert("error occurred "); })
.complete(function() { });
}
// This part just performs frontend changes, nothing backend
function removeTopNoDest(childId) {
$($("#" + childId)).effect( "blind",null, 5, function() { $(this).remove(); });
}
// This part just performs frontend changes, nothing backend
function removeTopNew(parentId, itemElem) {
var target;
if (parentId == parentOfRootId) {
target = "#up";
} else {
target = "#list_"+parentId;
}
var options = { to: target, className: "ui-effects-transfer" };
$($(itemElem)).effect('transfer', options, 50, function() { // !!!!!!!! TODO : Wrong. remove the one specified by child ID
$($(itemElem)).effect( "blind",null, 5, function() { $(this).remove(); });
});
}
// This part just performs frontend changes, nothing backend
function removeTop(parentId, childId) {
var target;
if (parentId == parentOfRootId) {
target = "#up";
} else {
target = "#list_"+parentId;
}
var options = { to: target, className: "ui-effects-transfer" };
$($("#" + childId)).effect('transfer', options, 50, function() { // !!!!!!!! TODO : Wrong. remove the one specified by child ID
$($("#" + childId)).effect( "blind",null, 5, function() { $(this).remove(); });
});
}
// Delete. Redundant functionality
function writeCategoryTree(root, level) {
var indent = "";
for (var i = 0; i < level; i++) {
indent = indent + " ";
}
$("#categoriesTree").append(indent + "<a href='/md5ro/?rootId="+root.id+"' style='text-transform:capitalize;'>"+root.name + "</a>");
$("#categoriesTree").append("<br>");
if (root.children != null) {
$.each(root.children, function(a,b){
writeCategoryTree(b, level + 1);
});
}
}
function moveToTop(source, button) {
var liElement = button.parentElement.parentElement.parentElement.parentElement.parentElement;
var url = liElement.getAttribute('url');
var categoryId = liElement.getAttribute('categoryId');
var created = liElement.getAttribute('created');
if (orderedDescending) {
var elem = $(liElement).remove();
$("#url_cards").prepend(elem);
// 1 more than latest timestamp
$.getJSON(host + ":44439/md5ro/surpassOrdinal?url=" + encodeURIComponent(url) + "&categoryId=" + categoryId + "&created=" + created,
function(result){
})
.success(function(data) {
})
.error(function() {
alert("error occurred ");
})
.complete(function() { });
} else {
// 1 less than earliest timestamp
alert('not implemented');
}
}
function moveToBottom(source) {
var idToMove = source;
var lastId = $("#url_cards").children().last().attr("id");
if (orderedDescending) {
var elem = $("#" + idToMove).remove();
$("#url_cards").append(elem);
$.getJSON(host + ":44439/md5ro/undercutOrdinal?nodeIdToChange=" + idToMove + "&nodeIdToUndercut=" + lastId,
function(result){
})
.success(function(data) {
})
.error(function() {
alert("error occurred ");
})
.complete(function() { });
} else {
alert('not implemented');
}
}
function sendBatch() {
var urls = encodeURIComponent($("#urlBatchToSend").val());
$("#batchStatus").text("Sending new batch");
$.getJSON(urlBase + "/batchInsert?rootId=" + rootId + "&urls=" + urls, function(result){})
.success(function(data) {
$("#batchStatus").text("Successfully imported batch, except for ones remaining in text box");
$("#urlBatchToSend").val("");
$("#urlBatchToSend").val(data.unsuccessful);
})
.error( function(data) {
alert("error occurred ");
} )
.complete( function() {} );
}
function createArrayWithId(id) {
var selected = new Array();
selected.push(id);
return JSON.stringify(selected);
}
function getTagSelections() {
var selected = new Array();
$('#categoriesRecursive input:checked').each(function() {
selected.push($(this).attr('name'));
});
return JSON.stringify(selected);
}
function tagUrlWithSelections(nodeId) {
var selections = getTagSelections();
tagUrlWithCategoryIds(nodeId, selections);
}
function tagUrlWithCategoryIds(nodeId, selections, button) {
var url = urlBase + "/relateCategoriesToItem?nodeId=" + nodeId + "&newCategoryIds=" + encodeURIComponent(selections);
$.getJSON(url,
function(result){
})
.success(function(data) {
button.style.cssText = "background-color : green";
})
.error(function() {
alert("error occurred ");
})
.complete(function() {
}
);
}
$(function() {
$( "#tabs" ).tabs();
});
// TODO: Remove. Unused
function addEmbeddedVideo(id, url) {
$("#" + id).children().last().append("<iframe width=420 height=345 src="+url.replace("watch?v=","embed/")+"></iframe>");
}
// TODO: Remove. Unused
function getBiggestImages() {
$.getJSON("http://localhost:3000/biggestImages", function(result){
biggestImages = result;
initialize();
});
}
function findCategoryChildren(categoriesNode, categoryIdToFind) {
if (categoriesNode.id == categoryIdToFind || categoriesNode.id == parseInt(categoryIdToFind)) {
return categoriesNode.children;
}
else if (categoriesNode.children != null) {
for (var i = 0; i < categoriesNode.children.length; i++ ) {
var category = findCategoryChildren(categoriesNode.children[i], categoryIdToFind);
if (category != null) {
return category;
}
}
} else {
return null;
}
}
function ITEM_TO_HTML(categories, item) {
return function (item) {
return fillCardItem(null, item, null, null, null, categories);
};
}
function putRootAtFront(urls, rootId) {
var categoryIdsUnderRoot = Object.keys(urls);
var first = categoryIdsUnderRoot.splice(categoryIdsUnderRoot.indexOf(rootId),1);
var categoryIdsUnderRootOrdered = first.concat(categoryIdsUnderRoot);
return categoryIdsUnderRootOrdered;
}
function getCategoryTableHtml(categoryId, categoryName, urlsInCategory) {
var html = "<h3>" + categoryName + " (" + categoryId + ")</h3>";
html += "<table id='table-"+categoryId+"' class='sortable urlTable'>";
html += "<thead><th>Title</th><th>URL</th></thead>";
html += "<tbody>";
for (var j = 0; j < urlsInCategory.length; j++) {
var item = urlsInCategory[j];
html += "<tr>";
html += "<td><div class='truncate'>" + item.title + "</div><td>";
html += "<td><div class='truncate'>" + item.url + "</div><td>";
html += "</tr>";
}
html += "</tbody>";
html += "</table>";
return html;
}
function getCategoryThumbnailsHtml(categoryId, categoryName, urlsInCategory1, limit) {
var urlsInCategory = urlsInCategory1.map(function(i){ if (i.ordinal < 9999999999) { i.ordinal = i.ordinal * 1000; }; return i;}).sort(function (u1, u2) {return u2.ordinal - u1.ordinal ;});
var urlThumbnailsHtml = "<h3><a href='/md5ro/?rootId="+categoryId+"'>" + categoryName + " (" + categoryId + ")</a></h3>";
for (var j = 0; j < urlsInCategory.length; j++) {
if (j > limit) {
break;
}
var item = urlsInCategory[j];
var displayImageUrl = getDisplayImageUrl(item);
urlThumbnailsHtml += "<a href="+item.url+"><img class=itemImage src='"+displayImageUrl+"' height="+IMAGE_SIZE+" onmouseenter='zoom(this)'></a>" ;
}
return urlThumbnailsHtml;
}
function getDisplayImageUrl(item) {
var url = item.url;
var specialSiteImageUrl = getSpecialSiteUrl(url);
if (url.match(".jpg\??") || url.match(/.*jpg/i) || url.match(".gif$")
|| url.match(".png\??") || url.match("images.q=tbn:")) {
displayImageUrl = url;
} else if (specialSiteImageUrl != null) {
displayImageUrl = specialSiteImageUrl;
} else if (item.user_image != null) {
displayImageUrl = item.user_image;
} else if (item.biggest_image != null) {
displayImageUrl = item.biggest_image;
} else if (url.match(".amazon.co[^/]+\/[^s]")) {
var asin = url.replace(/.+((dp)|(product))\/([^\/?]+)[\/?].*/,'$4');
asin = asin.replace(/.*dp./,'');
asin = asin.replace(/.*gp.aw.d./, '');
asin = asin.replace(/.ref_?=.*/, '');
asin = asin.replace(/.*offer-listing./, '');
var productImageUrl = 'http://images.amazon.com/images/P/'+asin+'.01.LZZZZZZZ.jpg';
displayImageUrl = productImageUrl;
} else {
displayImageUrl = "http://free.pagepeeker.com/v2/thumbs.php?size=x&url="
+ encodeURIComponent(url);
}
return displayImageUrl;
}
function getImageForUrl(url) {
var imageUrl;
if (url.match(".jpg\??") ||
url.match(/.*jpg/i) ||
url.match(".gif$") ||
url.match(".png\??") ||
url.match("images.q=tbn:")) {
imageUrl = url;
} else {
var specialSiteImageUrl = getSpecialSiteUrl(url);
if (specialSiteImageUrl == null) {
imageUrl = "http://free.pagepeeker.com/v2/thumbs.php?size=x&url="+encodeURIComponent(url);
} else {
imageUrl = specialSiteImageUrl;
}
}
return imageUrl;
}
function getSpecialSiteUrl(url) {
var imageUrl;
if (url.match("youtube.com/watch")) {
var youtubeId = url.replace(/^https?:..www.youtube.com.watch.*v=([^&]+).*/g,'$1');
imageUrl = "http://img.youtube.com/vi/"+youtubeId+"/0.jpg";
} else if (url.match("dailymotion.com/video")) {
var youtubeId = url.replace(/^http.*video.([^?]+)(.*)/g,'$1');
imageUrl = "http://dailymotion.com/thumbnail/video/"+youtubeId ;
}
// Too unreliable
// else if (url.match(".amazon.co[^/]+\/[^s]")) {
// var asin = url.replace(/.+((dp)|(product))\/([^\/?]+)[\/?].*/,'$4');
// asin = asin.replace(/.*dp./,'');
// asin = asin.replace(/.*gp.aw.d./, '');
// asin = asin.replace(/.ref_?=.*/, '');
// asin = asin.replace(/.*offer-listing./, '');
// var productImageUrl = 'http://images.amazon.com/images/P/'+asin+'.01.LZZZZZZZ.jpg';
// imageUrl = productImageUrl;
// }
else {
imageUrl = null;
}
return imageUrl;
}
function getProductsHtml(categoryId, categoryName, urlsInCategory) {
var productsHtml = "<h3>" + categoryName + " (" + categoryId + ")</h3>";
for (var j = 0; j < urlsInCategory.length; j++) {
var item = urlsInCategory[j];
if (item.url.match(".amazon.co[^/]+\/[^s]")) {
productsHtml += "";
var asin = item.url.replace(/.+((dp)|(product))\/([^\/?]+)[\/?].*/,'$4');
asin = asin.replace(/.*dp./,'');
asin = asin.replace(/.*gp.aw.d./, '');
asin = asin.replace(/.ref_?=.*/, '');
asin = asin.replace(/.*offer-listing./, '');
var productImageUrl = 'http://images.amazon.com/images/P/'+asin+'.01.LZZZZZZZ.jpg';
var imageTag = ("<img class=itemImage src='"+productImageUrl+"' height='280'>");
productsHtml += "<a href='" + item.url +"'>" + imageTag + "</a>\n";
hasScreenshot = true;
} else {
productsHtml += item.url + "<br>";
}
}
return productsHtml;
}
function getCategoryListHtml(categoryId, categoryName, urlsInCategory) {
var urlThumbnailsHtml = "<h3>" + categoryName + " (" + categoryId + ")</h3>";
for (var j = 0; j < urlsInCategory.length; j++) {
var item = urlsInCategory[j];
urlThumbnailsHtml += item.title + " (<a href='" + item.url +"'>" + item.url + "</a>)<br><br>";
}
return urlThumbnailsHtml;
}
function fillCardItem(resultRowNumber, field, result, limit, biggestImages, categories) {
//var one = $("<td style='background-color:'>1");
var two = $("<td style='background-color:' >2");
var three = $("<td style='background-color:'>3");
var four = $("<td id='categoryButtonsCell' style='background-color:'>4");
var five = $("<td style='background-color:'>5");
var six = $("<td style='background-color:'>6");
var listItem;
var table = $("<table/>");
{
table.attr('width','100%');
{
var row1 = $("<tr/>");
table.append(row1);
row1.append(two);
row1.append(three);
}
{
var row2 = $("<tr/>");
table.append(row2);
row2.append(four);
row2.append(five);
row2.append(six);
}
{
listItem = $("<li>").attr('id',field.id).attr("class",'buttonize').attr('style','background-color:#FDFD96')
.attr('url',field.url)
.attr('created',field.created)
.attr('categoryId',rootId);
listItem.append(table);
//$("#url_cards").append(listItem);
}
}
{
var urlElements = field.url.match(/^http:\/\/[^\/]+/);
if (urlElements != null) {
var site = urlElements[0];
two.append("<img src='" + site + "/favicon.ico' width=18 onerror=\"this.style.display='none'\" > ");
}
if (field.created < 9999999999) {
field.created = field.created * 1000;
}
var dddd = (new Date(field.created)).toString();
two.append("<font style=\"color: #002366 ; font-weight : normal; font-size: medium\">"+ field.title + "</font><br><sub><font style=\"color: #436B95\"><a href='" +field.url+"'>"+field.url+"</a></font><br>"+field.created+" - "+dddd+"<br>"+"</sub>");
}
var imageCell = createImageCell(field, biggestImages, null, resultRowNumber);
three.append(imageCell);
if (field.parentId != null) {
six.append("Parent ID: " + field.parentId);
}
{
var buttonCell = two;
buttonCell.append("<br>");
buttonCell.append("<br>");
buttonCell.append("<input type=button class='genericButton' value=Tag onClick='tagUrlWithSelections("+field.id+")'><br>");
buttonCell.append("<input type=button class='genericButton' value='Wrong Category' onClick='relateNew("+parentOfRootId+","+rootId+",this)'><br>");
buttonCell.append("<br>");
buttonCell.append("<input type=button class='genericButton' value='Change Image' onClick='changeImage("+field.id+",this,\"" +field.url+ "\")'><br>");
buttonCell.append("<input type=button class='genericButton' value='Remove Custom Image' onClick='removeImage("+field.id+",this,\"" +field.url +"\"," + rootId + ")'><br>");
buttonCell.append("<br>");
buttonCell.append("<br>");
buttonCell.append("<input type=button class='genericButton' value='Top' onclick='moveToTop("+field.id+", this)'><br>");
buttonCell.append("<input type=button class='genericButton' value='Move Up' onclick='moveUp("+field.id+")'><br>");
buttonCell.append("<input type=button class='genericButton' value='Move Down' onclick='moveDown("+field.id+")'><br>");
buttonCell.append("<input type=button class='genericButton' value='Bottom' onclick='moveToBottom("+field.id+")'><br>");
buttonCell.append("<sub>"+field.id+"</sub>");
}
{
var categoryButtons = four;
if (categories && categories.length == 0) {
// TODO: 'categories' may not yet be set. Really we should add these buttons in the callback where "categories" is set. But we don't know the field ID unless we wait until the item results load
debugger;
}
if (categories) {
var html = categories.sort(COMPARE_OBJ_NAME).map(CATEGORY_TO_BUTTON(field.id, rootId)).join(" ");
categoryButtons.append(html);
// TODO: would be nice to use map and fold
//$.each(categories, function(a,binding,c){
// categoryButtons.append("<input type=button class='genericButton' value='"+binding.name+" ("+ binding.key+")' onclick='relate("+binding.id+","+field.id+","+rootId+")'> ");