33 */
44var afullpage = document . querySelector ( 'fullpage' ) ,
55 smileList = document . querySelector ( 'fullpage smile-list' ) ,
6- asspages = document . querySelectorAll ( 'asett pages input ' ) ,
6+ asspages = document . querySelectorAll ( 'asett pages page ' ) ,
77 chess = 'a-dota2smile' , storageCache = _getStorage ( ) ,
8- storagePages = JSON . parse ( localStorage . getItem ( 'pages ' ) ) ,
8+ storagePage = JSON . parse ( localStorage . getItem ( 'page ' ) ) ,
99 alert = document . querySelector ( 'fullpage alert' ) , list = [ ] , aflag = true ,
1010 version = '0.0.4' ;
1111
@@ -14,17 +14,23 @@ var afullpage = document.querySelector('fullpage'),
1414 */
1515function reload ( )
1616{
17- if ( ! storagePages )
17+ if ( localStorage . getItem ( 'pages' ) )
18+ localStorage . removeItem ( 'pages' ) ;
19+
20+ if ( ! localStorage . getItem ( 'page' ) )
1821 {
19- // Спасибо Поняхе за найденный баг
20- localStorage . setItem ( 'pages' , `{"1":true,"5":true,"6":true,"7":true,"9":true,"11":true,"14":true,"16":true,"17":true,"18":true,"-1":true}` ) ;
21- storagePages = JSON . parse ( localStorage . getItem ( 'pages' ) ) ;
22+ localStorage . setItem ( 'page' , `{"1":{"name":"Стандартные","is":true},"5":{"name":"Твич","is":true},"6":{"name":"Разное","is":true},"7":{"name":"Dota 2 анимированные","is":true},"9":{"name":"Dota 2 герои","is":true},"11":{"name":"Аниме","is":true},"14":{"name":"Пепа","is":true},"16":{"name":"Dota 2 предметы","is":true},"17":{"name":"LoL","is":true},"18":{"name":"Твич-герои","is":true},"-1":{"name":"Популярные","is":true}}` ) ;
23+ storagePage = JSON . parse ( localStorage . getItem ( 'page' ) ) ;
2224 }
2325
2426 // Переприсваиваем все разрешённые вкладки смайлов
2527 asspages . forEach
2628 ( function ( a ) {
27- a . checked = storagePages [ a . value . toString ( ) ] ;
29+ var input = a . querySelector ( 'input[type="checkbox"]' ) ,
30+ name = a . querySelector ( 'input[type="text"]' ) ;
31+
32+ name . value = storagePage [ input . value . toString ( ) ] . name ;
33+ input . checked = storagePage [ input . value . toString ( ) ] . is ;
2834 } ) ;
2935
3036 // Самый простой способ очистить от всего старого
@@ -369,20 +375,95 @@ function loadFrom ()
369375 */
370376function savePages ( )
371377{
372- var pages = document . querySelectorAll ( 'asett pages input ' ) ,
378+ var pages = document . querySelectorAll ( 'asett pages page ' ) ,
373379 array = { } ;
374380
375381 pages . forEach
376382 ( function ( a , i ) {
377- array [ a . value ] = a . checked ;
383+ var input = a . querySelector ( 'input[type="checkbox"]' ) ,
384+ name = a . querySelector ( 'input[type="text"]' ) . value ;
385+
386+ array [ input . value ] = { name : name , is : input . checked } ;
387+ console . log ( name , input . value , input . checked ) ;
378388 } ) ;
379389
380- localStorage . setItem ( 'pages' , JSON . stringify ( array ) ) ;
390+ localStorage . setItem ( 'page' , JSON . stringify ( array ) ) ;
391+ storagePage = array ;
381392 reload ( ) ;
382393
383394 openAlert ( { text : 'Отображение изменено по вашему усмотрению!' } ) ;
384395}
385396
397+ /**
398+ * Автоматически поделиться с указанным пользователем
399+ */
400+ function sendSmiles ( { you, to, username} )
401+ {
402+ var you = you , user = to , username = username ,
403+ title = '[dota2smile] ' + you + ' поделился с ' + username + ' своими смайлами' ,
404+ content =
405+ `<div class="bbCodeBlock bbCodeQuote">
406+ <blockquote class="quoteContainer">
407+ <div class="quote">
408+ <p>` + JSON . stringify ( _getStorage ( ) ) + `</p>
409+ </div>
410+ </blockquote>
411+ </div>` ;
412+
413+ void requestHandler . ajaxRequest
414+ ( "/api/message/createConversation" ,
415+ { title : title , content : content , recipient : user } ,
416+
417+ function ( response )
418+ {
419+ if ( response . status == 'success' )
420+ {
421+ openAlert ( { text : 'Пак смайлов отправлен!' } ) ;
422+
423+ adoor ( 'savetouser' ) ;
424+ adoor ( 'saveto' ) ;
425+ }
426+ else
427+ {
428+ openAlert ( { text : 'Ошибка: некорректный никнейм пользователя' } ) ;
429+ }
430+ }
431+ )
432+ }
433+
434+ /**
435+ * Проверка пользователя на существование
436+ */
437+ function findUser ( )
438+ {
439+ var stu = document . querySelector ( 'fullpage savetouser' ) ,
440+ info = stu . querySelector ( 'information' ) ,
441+ username = stu . querySelector ( 'input' ) . value ;
442+
443+ info . innerHTML = 'Загрузка..' ;
444+
445+ fetch ( 'https://dota2.ru/forum/search?type=user&keywords=' + username + '&sort_by=username' )
446+ . then ( function ( response ) {
447+ return response . text ( ) ;
448+ } )
449+ . then ( function ( html ) {
450+ var you = document . querySelector ( 'div.hello .username' ) . innerHTML ,
451+ userdocument = dom ( html ) . ownerDocument . querySelector ( '.member-list-item .avatar' ) ,
452+ href = userdocument . href . split ( '/' ) ,
453+ id = href [ href . length - 2 ] . split ( '.' ) [ 1 ] ,
454+ avatar = userdocument . querySelector ( 'img' ) . src ;
455+
456+ info . innerHTML =
457+ `<avatar><img src='` + avatar + `'></avatar>
458+ <pass>
459+ <name><t>Имя</t> ` + username + `</name>
460+ <id><t>ID</t> ` + id + `</id>
461+ <confirmation>Это верный пользователь?</confirmation>
462+ <fing onclick="sendSmiles({you: '` + you + `', to: '` + id + `', username: '` + username + `'})">Да, отправить</fing>
463+ </pass>` ;
464+ } ) ;
465+ }
466+
386467/**
387468 * Смена страниц
388469 */
0 commit comments