From 54140d5159a68d7cd5fe66bd1e4bf04c7775feab Mon Sep 17 00:00:00 2001 From: aleqsunder Date: Sat, 17 Aug 2019 00:57:02 +0400 Subject: [PATCH] 0.1.2.2 --- assets/css/breadcrumb.css | 139 +++++++ assets/css/chat.css | 2 +- assets/js/alert.js | 93 +++++ assets/js/breadcrumb.js | 126 +++++++ assets/js/categories.js | 103 +---- assets/js/chat.js | 32 +- assets/js/checkversion.js | 12 +- assets/js/footerfunctions.js | 136 ++++++- assets/js/forumredactor.js | 2 +- assets/js/integrate.js | 55 +-- assets/js/reservecopy.js | 24 +- assets/js/smiles.js | 14 +- assets/settings.html | 13 + extens.css | 708 +++++++++++++++++++++++++++++++++++ extension.js | 34 +- manifest.json | 4 +- 16 files changed, 1302 insertions(+), 195 deletions(-) create mode 100644 assets/css/breadcrumb.css create mode 100644 assets/js/alert.js create mode 100644 assets/js/breadcrumb.js create mode 100644 extens.css diff --git a/assets/css/breadcrumb.css b/assets/css/breadcrumb.css new file mode 100644 index 0000000..e89ab2b --- /dev/null +++ b/assets/css/breadcrumb.css @@ -0,0 +1,139 @@ +.openbc_poule +{ + position: absolute; + + width: 100%; + max-width: 1220px; + + margin-left: calc((100% - 1220px) / 2); + + height: 100vh; + top: 0; + + display: none; +} + +.displayed +{ + display: block; +} + +.bc-fone +{ + position: fixed; + top: 0; + left: 0; + + width: 100vw; + height: 100vh; + background: #000; + opacity: 0; + + z-index: 15; + + transition: all .3s; +} + +.bc-fone-opacity +{ + opacity: var(--blackout); +} + +.bc-loaded-post +{ + position: absolute; + width: 100%; + max-width: 700px; + padding: 3px 0; + background: #171717; + border: 1px solid #333; + border-radius: 6px; + z-index: 15; + left: 100px; + top: 27px; + + overflow: hidden; + height: auto; + opacity: 0; + + max-height: 65px; + transition: all .4s cubic-bezier(1, 0.27, 0.93, 0.54), opacity .3s; +} + +.bc-loaded-post-opacity +{ + opacity: 1; +} + +.bc-loaded-post usercode +{ + display: block; + padding: 4px 10px; + border-bottom: 1px solid #333; + + font-size: 12px; +} + +.bc-loaded-post postmessage +{ + display: block; + padding: 4px 8px; +} + +.bc-loaded-post img +{ + max-width: 100%; +} + +.bc-loaded-post postmessage > p { + font-size: 12px; + padding: 0px 5px; + line-height: 16px; +} + +.bc-loaded-post loadpost +{ + position: relative; + display: block; + + background: #333; + border-radius: 6px; + margin: 4px 0; +} + + + +.bc-loaded-post .bc-nickname +{ + padding: 0px 5px; + font-size: 12px; +} + +.bc-loaded-post .bc-loadpost +{ + position: relative; + + font-size: 11px; + padding: 1px 6px; + background: #222; + border-radius: 6px; + max-height: 34px; + overflow: hidden; +} + +.bc-loaded-post .bottomborder +{ + position: absolute; + + width: 100%; + height: 36px; + top: 0; + background: linear-gradient(to top, #222 0px, #fff0 12px, #fff0 100%); + border-bottom-left-radius: 6px; + border-bottom-right-radius: 6px; +} + +.max-height-auto +{ + max-height: 1000px; +} \ No newline at end of file diff --git a/assets/css/chat.css b/assets/css/chat.css index b60efa8..49dc510 100644 --- a/assets/css/chat.css +++ b/assets/css/chat.css @@ -292,7 +292,7 @@ body opacity: .8; } -.messageText img[data-smile] +img[data-smile] { margin: -5px 0; vertical-align: middle; diff --git a/assets/js/alert.js b/assets/js/alert.js new file mode 100644 index 0000000..c03beee --- /dev/null +++ b/assets/js/alert.js @@ -0,0 +1,93 @@ +/** + * Смена страниц + */ +function adoor (elem) +{ + var flag = ''; + + if (!__('.open', afp)) + { + afp.classList.toggle('open'); + afp.classList.toggle('margin'); + } + + __(`backfon.${elem}`, afp).classList.toggle('open'); + if (flag = __(elem, afp).classList.toggle('open')) + { + __(`backfon.${elem}`, afp).classList.toggle('margin'); + __(elem, afp).classList.toggle('margin'); + } + else + { + setTimeout + ( function () { + __(`backfon.${elem}`, afp).classList.toggle('margin'); + __(elem, afp).classList.toggle('margin'); + }, 400); + } + + if (elem == 'saveto' && flag) + saveTo(); + + if (!__('.open', afp)) + { + setTimeout + ( function () { + afp.classList.toggle('open'); + afp.classList.toggle('margin'); + }, 400); + } +} + +/** + * Управление уведомлениями + */ +function openAlert ({text, wait, button, titleOf}) +{ + if (titleOf == 'none') __('top', alert).style.setProperty('display', 'none'); + var header = titleOf || 'Уведомление'; + + __('top', alert).textContent = header; + __('middle', alert).innerHTML = text; + + adoor('alert'); + + if (wait) + { + if (button) + { + alert.appendChild + ( dom (` + + `)); + + bottom = __('bottom', alert); + + button.forEach + ( function (a) { + log(a); + bottom.appendChild + ( dom(` + + ${a.value} + + `)); + }); + } + + // На случай бесконечного уведомления возможность закрыть + __('fullpage backfon.alert').setAttribute + ( + 'onclick', + `adoor('alert'); this.querySelector('bottom').outerHTML = ''; this.querySelector('top').style = ''; this.onclick = 'return false;'` + ); + } + else + { + // Временное уведомление закрывается само + setTimeout + (function () { + adoor('alert'); + }, 2000); + } +} \ No newline at end of file diff --git a/assets/js/breadcrumb.js b/assets/js/breadcrumb.js new file mode 100644 index 0000000..f87fb6d --- /dev/null +++ b/assets/js/breadcrumb.js @@ -0,0 +1,126 @@ +var open_count = 0, left = 0, + poule = dom(`
`); + +if (!has('breadcrumb-isCascade')) +{ + log('[breadcrumb] Установлены первоначальные настройки'); + + set('breadcrumb-isCascade', 'true'); + set('breadcrumb-left', '160'); + set('breadcrumb-blackout', '0.5'); + +} + +document.addEventListener +("DOMContentLoaded", function () { + document.body.appendChild(poule); + + document.body.style.setProperty('--blackout', + get('breadcrumb-blackout')); +}); + +watching +({ + elem: 'blockquote.messageText div.attribution a', + bool: true, + + callback: function (el) + { + el.addEventListener('click', {handleEvent: openbc, b: true}); + } +}); + +function closebc () +{ + open_count--; + var post_id = this.getAttribute('data-post-id'); + + if (open_count == 0) + if (poule.classList.contains('displayed')) + poule.classList.remove('displayed'); + + this.outerHTML = ''; + __(`.bc-loaded-post[data-post-id='${post_id}']`).outerHTML = ''; +} + +function openbc (e) +{ + e.preventDefault(); + e.stopPropagation(); + open_count++; + left = parseInt(get('breadcrumb-left')); + + var element = e.target, + flag = this.b, + x = 0; + + if (get('breadcrumb-isCascade') == 'true') + { + if (Math.floor(open_count / 5) & 1) + x = (300 + left) - (60 * (open_count % 5)); + else + x = left + (60 * (open_count % 5)); + } + else + { + x = parseInt(get('breadcrumb-blackout')); + } + + var y = e.pageY, + p = element.parentElement.parentElement, + post_id = p.getAttribute('data-post-id'), + author = p.getAttribute('data-author'), + set = __(`.bc-loaded-post`), + ob = dom( + `
+ Сообщение ${author} #${post_id} + + Загрузка... + +
` + ), + bc_fone = dom( + `
` + ); + + poule.appendChild(bc_fone); + poule.appendChild(ob); + + if (!poule.classList.contains('displayed')) + poule.classList.add('displayed'); + + setTimeout + ( function () { + bc_fone.classList.add('bc-fone-opacity'); + ob.classList.add('bc-loaded-post-opacity'); + }); + + requestHandler.ajaxRequest + ("/api/forum/getPostCode", { + pid: post_id, + quotes: true, + type: 'post' + }, function (response) { + switch (response.status) { + case "success": + data = Base64.decode(response.data); + data = data.replace( + /

\[QUOTE=\"(.*?), post: (.*?), member: (.*?)\"\]<\/p>(.*?)

\[\/QUOTE\]<\/p>/ig, + "

$1#$2
$4
" + ) + + __('postmessage', ob).innerHTML = data; + ob.classList.add('max-height-auto'); + break; + case "invalidPost": + Utils.notify("Некорректный пост", "warning", 6e3); + break; + default: + Utils.notify("Произошла неизвестная ошибка", "danger"); + } + }, true); +} \ No newline at end of file diff --git a/assets/js/categories.js b/assets/js/categories.js index ba8fd25..a943ef0 100644 --- a/assets/js/categories.js +++ b/assets/js/categories.js @@ -26,7 +26,7 @@ function delTab (tab, bool) }); cath = array; - localStorage.setItem('cath', JSON.stringify(cath)); + set('cath', JSON.stringify(cath), true); } else { @@ -69,7 +69,7 @@ function savePages (output) ( function (a) { var input = __('input[type="checkbox"]', a); - localStorage.setItem(`setting--${input.value}`, input.checked); + set(input.value, input.checked); }); pages.forEach @@ -80,7 +80,7 @@ function savePages (output) arrayPage[input.value] = {name: name, is: input.checked}; }); - localStorage.setItem('page', JSON.stringify(arrayPage)); + set('page', JSON.stringify(arrayPage), true); storagePage = arrayPage; tabs.forEach @@ -98,7 +98,7 @@ function savePages (output) ( function (a) { var el = JSON.parse(storageCache[a]); - console.log(el.tab, tab); + log(el.tab, tab); if (el.tab == oldtab) { el.tab = tab; @@ -108,7 +108,7 @@ function savePages (output) } }); - localStorage.setItem('cath', JSON.stringify(arrayTab)); + set('cath', JSON.stringify(arrayTab), true); cath = arrayTab; reload(); @@ -120,96 +120,7 @@ function savePages (output) }); } -/** - * Смена страниц - */ -function adoor (elem) -{ - var flag = ''; - - if (!__('.open', afp)) - { - afp.classList.toggle('open'); - afp.classList.toggle('margin'); - } - - __(`backfon.${elem}`, afp).classList.toggle('open'); - if (flag = __(elem, afp).classList.toggle('open')) - { - __(`backfon.${elem}`, afp).classList.toggle('margin'); - __(elem, afp).classList.toggle('margin'); - } - else - { - setTimeout - ( function () { - __(`backfon.${elem}`, afp).classList.toggle('margin'); - __(elem, afp).classList.toggle('margin'); - }, 400); - } - - if (elem == 'saveto' && flag) - saveTo(); - - if (!__('.open', afp)) - { - setTimeout - ( function () { - afp.classList.toggle('open'); - afp.classList.toggle('margin'); - }, 400); - } -} - -/** - * Управление уведомлениями - */ -function openAlert ({text, wait, button, titleOf}) +function userStyles() { - if (titleOf == 'none') __('top', alert).style.setProperty('display', 'none'); - var header = titleOf || 'Уведомление'; - - __('top', alert).textContent = header; - __('middle', alert).innerHTML = text; - - adoor('alert'); - - if (wait) - { - if (button) - { - alert.appendChild - ( dom (` - - `)); - - bottom = __('bottom', alert); - - button.forEach - ( function (a) { - console.log(a); - bottom.appendChild - ( dom(` - - ${a.value} - - `)); - }); - } - - // На случай бесконечного уведомления возможность закрыть - __('fullpage backfon.alert').setAttribute - ( - 'onclick', - `adoor('alert'); this.querySelector('bottom').outerHTML = ''; this.querySelector('top').style = ''; this.onclick = 'return false;'` - ); - } - else - { - // Временное уведомление закрывается само - setTimeout - (function () { - adoor('alert'); - }, 2000); - } + set('userstyles-css', JSON.stringify(__('[userstyles]').value)); } \ No newline at end of file diff --git a/assets/js/chat.js b/assets/js/chat.js index da1d0f5..0069699 100644 --- a/assets/js/chat.js +++ b/assets/js/chat.js @@ -7,17 +7,18 @@ var default_vars = }, vars = { - 'f-color': localStorage.getItem('f-color') || default_vars['f-color'], - 'f-time-color': localStorage.getItem('f-time-color') || default_vars['f-time-color'], - 'f-background': localStorage.getItem('f-background') || default_vars['f-background'], - 'f-chat-background': localStorage.getItem('f-chat-background') || default_vars['f-chat-background'] + 'f-color': get('f-color', true) || default_vars['f-color'], + 'f-time-color': get('f-time-color', true) || default_vars['f-time-color'], + 'f-background': get('f-background', true) || default_vars['f-background'], + 'f-chat-background': get('f-chat-background', true) || default_vars['f-chat-background'] } -function changebodycolor(){ +function changebodycolor() +{ var attr = this.getAttribute('var'), color = this.value || vars[attr]; - localSet(attr, color); + set(attr, color); styleSet(attr, color); vars[attr] = color; @@ -26,29 +27,26 @@ function changebodycolor(){ function styleSet (name, value) { __('body').style.setProperty(`--${name}`, value) } -function localSet (name, value) -{ localStorage.setItem(name, value) } - function toDefault () { - console.log(this, this.parentElement); + log(this, this.parentElement); var input = this.parentElement.querySelector('input'), name = input.getAttribute('var'); input.value = default_vars[name]; styleSet(name, default_vars[name]); - localSet(name, default_vars[name]); + set(name, default_vars[name]); vars[name] = default_vars[name]; } function chatSetting () { - console.log(this); + log(this); var name = this.getAttribute('caller'); - localSet(`--${name}`, this.checked); + set(name, this.checked); Chat.getChatMessages(true); } @@ -89,7 +87,7 @@ function loading (bool) function notify_turn () { - var turn = localStorage.getItem('chatTurn') || 'false', + var turn = get('chatTurn') || 'false', chatFull = __('#chatFull h3.content-title .fa-bell'); if (turn == 'false') @@ -101,7 +99,7 @@ function notify_turn () switch (permission) { case "granted": - localStorage.setItem('chatTurn', true); + set('chatTurn', true); openAlert ({ @@ -128,7 +126,7 @@ function notify_turn () } else { - localStorage.setItem('chatTurn', true); + set('chatTurn', true); openAlert ({ @@ -144,7 +142,7 @@ function notify_turn () } else { - localStorage.setItem('chatTurn', false); + set('chatTurn', false); openAlert ({ diff --git a/assets/js/checkversion.js b/assets/js/checkversion.js index 3578d35..f094cfa 100644 --- a/assets/js/checkversion.js +++ b/assets/js/checkversion.js @@ -1,9 +1,9 @@ -const version = '0.1.2.1'; +const version = '0.1.2.2'; // Если новая версия -if (localStorage.getItem('version') != version) +if (get('version', true) != version) { - if (!localStorage.getItem('first')) + if (!get('first', true)) { adoor('wellcome'); @@ -37,8 +37,8 @@ if (localStorage.getItem('version') != version) ( function () { adoor('wellcome'); - localStorage.setItem('first', 'est zhi'); - localStorage.setItem('version', version); + set('first', 'est zhi', true); + set('version', version, true); }, timer) } } @@ -47,7 +47,7 @@ if (localStorage.getItem('version') != version) } else { - localStorage.setItem('version', version); + set('version', version, true); openAlert({ wait: true, diff --git a/assets/js/footerfunctions.js b/assets/js/footerfunctions.js index 2cc55f3..c1a799e 100644 --- a/assets/js/footerfunctions.js +++ b/assets/js/footerfunctions.js @@ -43,6 +43,78 @@ var chess = 'a-dota2smile', } ]; +/** + * Кастомный log + * + * @param string item + */ +function log (text) +{ + console.log + ( + `%cD2S - forumhelper%c ${text}`, + `background: #333; color:#FFF; padding: 3px 8px; border-radius: 6px;`, `` + ); +} + +/** + * Установка ключа localstorage + * + * @param string item + * @param string str + * @param boolean a + */ +function set (item, str, a) +{ + a = a == null ? 'setting--' : ''; + localStorage.setItem(`${a}${item}`, str); +} + +/** + * Получение ключа localstorage + * + * @param string item + * @param boolean a + * + * @return string + */ +function get (item, a) +{ + a = a == null ? 'setting--' : ''; + return localStorage.getItem(`${a}${item}`); +} + +/** + * Удаление ключа localstorage + * + * @param string item + * @param boolean a + */ +function remove (item, a) +{ + a = a == null ? 'setting--' : ''; + localStorage.removeItem(`${a}${item}`); +} + +/** + * Проверка наличия ключа localstorage + * + * @param string item + * @param boolean a + * + * @return string + */ +function has (item, a) +{ + a = a == null ? 'setting--' : ''; + + var b = localStorage.getItem(`${a}${item}`); + + if (b == 'null') + return false; + else return b; +} + /** * Загрузка разрешённых стилей и скриптов * @@ -50,24 +122,32 @@ var chess = 'a-dota2smile', */ function load (capt) { - var name = capt.split('.')[0], - type = capt.split('.')[1], - elem = type == 'css' ? 'style' : 'script'; - - if (localStorage.getItem(`setting--${name}`) == 'false') return false; - else localStorage.setItem(`setting--${name}`, 'true'); - - fetch(chrome.extension.getURL(`/assets/${type}/${name}.${type}`)) - .then(function(response){ - return response.text(); - }) - .then(function(html){ - var el = document.createElement(elem); - el.innerHTML = html; - - document.head.appendChild(el); - console.log(`${name}.${type} загружен успешно`); - }); + var name = capt.split('.')[0], + type = capt.split('.')[1], + elem = type == 'css' ? 'style' : type == 'js' ? 'script' : 'user'; + + if (get(name) == 'false') return false; + else set(name, 'true'); + + if (capt.indexOf('.') > -1) + { + fetch(chrome.extension.getURL(`/assets/${type}/${name}.${type}`)) + .then(function(response){ + return response.text(); + }) + .then(function(html){ + createDom(elem, html); + log(`${name}.${type} загружен успешно`); + }); + } + else + { + setTimeout + ( () => { + let html = JSON.parse(get(`${capt}-css`)); + createDom('style', html); + }); + } } /** @@ -96,6 +176,7 @@ function watching ({doc, elem, callback, bool}) /** * Создаёт DOM объект из string + * Ограничение в одиночный тег * * @param string html * @@ -109,6 +190,21 @@ function dom (html) .childNodes[0]; } +/** + * Создаёт DOM объект из html и отправляет в head + * + * @param string html + * + * @return HTMLElement + */ +function createDom (elem, html) +{ + var el = document.createElement(elem); + el.innerHTML = html; + + document.head.appendChild(el); +} + /** * Возвращает URL от расширения * @@ -176,7 +272,7 @@ function setStorage (key, value) storageCache = _getStorage(); storageCache[key] = value; - localStorage.setItem(chess, JSON.stringify(storageCache)); + set(chess, JSON.stringify(storageCache), true); return storageCache[key]; } @@ -190,7 +286,7 @@ function setStorage (key, value) */ function _getStorage () { - var storage = localStorage.getItem(chess); + var storage = get(chess, true); if (storage === null) storage = {}; diff --git a/assets/js/forumredactor.js b/assets/js/forumredactor.js index 38cb22d..b3ec32d 100644 --- a/assets/js/forumredactor.js +++ b/assets/js/forumredactor.js @@ -248,7 +248,7 @@ if (tinyMods.indexOf(mode) > -1) title = ob.getAttribute('dota-title'), mcet = document.querySelector('div.mce-tooltip'); - console.log(event, this); + log(event, this); if (!mcet) { diff --git a/assets/js/integrate.js b/assets/js/integrate.js index 3a421e5..31a95ae 100644 --- a/assets/js/integrate.js +++ b/assets/js/integrate.js @@ -10,9 +10,9 @@ var afp = __('fullpage'), asstabes = __('asett pages[name="tabsetting"]', afp), assscroll = __('asett pages[name="scrollbar"]', afp), asschat = __('asettchat pages[name="st"]', afp), - getchat = localStorage.getItem('setting--chat'), - storagePage = JSON.parse(localStorage.getItem('page')), - cath = JSON.parse(localStorage.getItem('cath')), + getchat = get('chat'), + storagePage = JSON.parse(get('page', true)), + cath = JSON.parse(get('cath', true)), alert = __('alert', afp), aflag = true; /* @@ -28,7 +28,7 @@ if (mode == 'unknown' && __('head title').innerText == 'Форум Dota 2' && (g { stab.querySelectorAll('a').forEach ( function (a){ - var page = JSON.parse(localStorage.getItem('page')), + var page = JSON.parse(get('page', true)), a = a; // получаемая переменная может работать только в пределах своей ф-ии @@ -61,7 +61,7 @@ if (mode == 'unknown' && __('head title').innerText == 'Форум Dota 2' && (g styleSet('f-chat-background', vars['f-chat-background']); __('input[caller="chat-avatar"]', asschat).checked - = JSON.parse(localStorage.getItem('--chat-avatar')) === true; + = JSON.parse(get('chat-avatar')) === true; var old_time = '0', array_notify = []; @@ -86,7 +86,7 @@ if (mode == 'unknown' && __('head title').innerText == 'Форум Dota 2' && (g if (skipDuplicates && $('#chatMessage' + data.id).length > 0) $('#chatMessage' + data.id).remove(); - var enableUserAvatar = JSON.parse(localStorage.getItem('--chat-avatar')) === true, + var enableUserAvatar = JSON.parse(get('chat-avatar')) === true, chatBlock = $(".chatMessages"), liClass = (data.visible !== undefined && !data.visible) ? 'not-visible' : '', id = (data.id !== undefined) ? `id="chatMessage${data.id}"` : '', @@ -292,12 +292,12 @@ if (mode == 'unknown' && __('head title').innerText == 'Форум Dota 2' && (g { for (var i = 0; i < response.data.length; i++) Chat.appendToChat(response.data[i], scroll); - if (localStorage.getItem('chatTurn') == "true") + if (has('chatTurn')) { var data = response.data[response.data.length-1], text = Base64.decode(data.content), id = data.id.toString(), - notify = localStorage.getItem('notify'); + notify = get('notify', true); if (notify) { @@ -317,7 +317,7 @@ if (mode == 'unknown' && __('head title').innerText == 'Форум Dota 2' && (g } } - localStorage.setItem('notify', notify.join()); + set('notify', notify.join(), true); } } else notify = []; @@ -325,7 +325,7 @@ if (mode == 'unknown' && __('head title').innerText == 'Форум Dota 2' && (g if (notify.indexOf(id) < 0) { notify.push(id); - localStorage.setItem('notify', notify.join()); + set('notify', notify.join(), true); text = text .replace(//ig, "[Голосовое]") @@ -350,10 +350,10 @@ if (mode == 'unknown' && __('head title').innerText == 'Форум Dota 2' && (g { notify[id] = true; - var deleteNotify = localStorage.getItem('notify').split(','); + var deleteNotify = get('notify', true).split(','); deleteNotify.splice(deleteNotify.indexOf(id), 1); - localStorage.setItem('notify', deleteNotify.join()); + set('notify', deleteNotify.join(), true); }, 30000); }, 5000); } @@ -361,6 +361,7 @@ if (mode == 'unknown' && __('head title').innerText == 'Форум Dota 2' && (g Chat._scroll_at_end && Chat.scrollChat() } + Chat.lastMessageDate = moment.unix(response.data[response.data.length - 1].date_sent), Chat.updateInterval !== Utils.config.chatUpdateInterval && (Chat.updateInterval = Utils.config.chatUpdateInterval, clearInterval(Chat.chatInterval), Chat.chatUpdateRunning = !1, Chat.runChatInterval()) } @@ -437,7 +438,7 @@ if (mode == 'unknown' && __('head title').innerText == 'Форум Dota 2' && (g `` )); - var red = (localStorage.getItem('chatTurn') == 'true') ? '' : ' red'; + var red = (has('chatTurn')) ? '' : ' red'; chatTitle.appendChild (dom( `` @@ -449,23 +450,25 @@ if (mode == 'unknown' && __('head title').innerText == 'Форум Dota 2' && (g */ function reload () { - reservetime.innerText = localStorage.getItem('reserve-time'); + reservetime.innerText = get('reserve-time', true); mainsetting.forEach ( function (a) { var input = __('input[type="checkbox"]', a); - input.checked = (localStorage.getItem(`setting--${input.value}`) == 'true'); + input.checked = (get(input.value) == 'true'); }); - if (localStorage.getItem('pages')) - localStorage.removeItem('pages'); + if (has('pages', true)) + remove('pages', true); - if (!localStorage.getItem('page')) + if (!has('page', true)) { - 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}}`); - storagePage = JSON.parse(localStorage.getItem('page')); + set('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}}`, true); + storagePage = JSON.parse(get('page', true)); } + + __('[userstyles]').value = JSON.parse(get('userstyles-css')) || ``; // Переприсваиваем все разрешённые вкладки смайлов asspages.forEach @@ -483,8 +486,8 @@ function reload () if (!cath) { - localStorage.setItem('cath', `[{"name":"Без категории","index":"100","hidden":"false"}]`); - cath = JSON.parse(localStorage.getItem('cath')); + set('cath', `[{"name":"Без категории","index":"100","hidden":"false"}]`, true); + cath = JSON.parse(get('cath', true)); } var arraytabes = []; @@ -494,7 +497,7 @@ function reload () Object.keys(cath).forEach (function (tab) { tab = cath[tab]; - console.log(tab, tab.name, tab.index); + log(tab, tab.name, tab.index); arraytabes.push({ name: tab.name, index: tab.index, hidden: tab.hidden }); @@ -537,19 +540,19 @@ function reload () } // Если обнаружены смайлы старого образца - конвертация в новый и обновление - if (localStorage.getItem('a-dota2smiles')) + if (get('a-dota2smiles', true)) { chess = 'a-dota2smiles'; storageCache = _getStorage(); Object.keys(storageCache).forEach ( function (name) { add({a: name}) }); - localStorage.removeItem('a-dota2smiles'); + remove('a-dota2smiles', true); chess = 'a-dota2smile'; save(); - console.log(_getStorage); + log(_getStorage); document.location.reload(); return false; diff --git a/assets/js/reservecopy.js b/assets/js/reservecopy.js index 1d48dca..cfebedd 100644 --- a/assets/js/reservecopy.js +++ b/assets/js/reservecopy.js @@ -3,7 +3,7 @@ const reserve = massive: [ 'a-dota2smile', - '--chat-avatar', + 'chat-avatar', 'cath', 'chatTurn', 'first', 'page' ], @@ -27,7 +27,7 @@ const reserve = { if (a != true) { - if (this.get('reserve-first')) + if (get('reserve-first', true)) { openAlert ({ @@ -54,14 +54,14 @@ const reserve = { this.massive.forEach ( function (a) { - reserve.set(`reserve-${a}`, reserve.get(a)); + set(`reserve-${a}`, reserve.get(a), true); }); var d = new Date(), month = d.getMonth() < 10 ? `0` : ``, minutes = d.getMinutes() < 10 ? `0` : ``; - this.set('reserve-time', `${d.getDate()}.${month}${d.getMonth()}.${d.getFullYear()} в ${d.getHours()}:${minutes}${d.getMinutes()}`); + set('reserve-time', `${d.getDate()}.${month}${d.getMonth()}.${d.getFullYear()} в ${d.getHours()}:${minutes}${d.getMinutes()}`, true); openAlert ({ @@ -77,7 +77,7 @@ const reserve = { if (a != true) { - if (!this.get('reserve-first')) + if (!get('reserve-first', true)) { openAlert ({ @@ -109,13 +109,13 @@ const reserve = { this.massive.forEach ( function (a) { - reserve.set(a, reserve.get(`reserve-${a}`)); + set(a, reserve.get(`reserve-${a}`), true); }); - if (reserve.get('a-dota2smile') == 'null') + if (has('a-dota2smile', true)) { - reserve.set('a-dota2smile', '{}'); - reserve.set('reserve-a-dota2smile', '{}'); + set('a-dota2smile', '{}', true); + set('reserve-a-dota2smile', '{}', true); } openAlert @@ -149,11 +149,11 @@ const reserve = { this.massive.forEach ( function (a) { - reserve.remove(a); - reserve.remove(`reserve-${a}`); + remove(a, true); + remove(`reserve-${a}`, true); }); - reserve.remove('reserve-time'); + remove('reserve-time', true); openAlert ({ diff --git a/assets/js/smiles.js b/assets/js/smiles.js index ed1171f..c6e4883 100644 --- a/assets/js/smiles.js +++ b/assets/js/smiles.js @@ -72,7 +72,7 @@ function add ({a, bool}) }) arraytab.push({ "name": tab, "index": "100", "hidden": "false" }) - localStorage.setItem('cath', JSON.stringify(arraytab)); + set('cath', JSON.stringify(arraytab), true); } else { @@ -193,8 +193,8 @@ function CEtoggle () */ function save () { - var tabs = [], tabes = JSON.parse(localStorage.getItem('cath')); - localStorage.setItem(chess, JSON.stringify({})); + var tabs = [], tabes = JSON.parse(get('cath', true)); + set(chess, JSON.stringify({}), true); $_('list', smileList).forEach ( function(a) { @@ -224,8 +224,8 @@ function save () tabs[b] = {name: a.name, index: a.index, hidden: hddn} }); - localStorage.setItem('cath', JSON.stringify(tabs)); - cath = JSON.parse(localStorage.getItem('cath')); + set('cath', JSON.stringify(tabs), true); + cath = JSON.parse(get('cath', true)); storageCache = _getStorage(); reload(); @@ -279,7 +279,7 @@ function loadFrom (bool) oth = Object.assign(load, your); - localStorage.setItem(chess, JSON.stringify(oth)); + set(chess, JSON.stringify(oth), true); area.value = ''; // Ну и сразу получаем готовенькое @@ -326,7 +326,7 @@ function sendSmiles ({you, to, username}) else { openAlert({text: 'Ошибка'}); - console.log(response); + log(response); } } ) diff --git a/assets/settings.html b/assets/settings.html index e118744..f0a9a72 100644 --- a/assets/settings.html +++ b/assets/settings.html @@ -209,6 +209,7 @@ + Редактор стилей Сохранить @@ -250,4 +251,16 @@ В шапке темы тебя ждут несколько обучающих гайдов, чтобы ты смог свободно разобраться в интерфейсе! Эти сообщения (кроме упоминаний обновлений) отображаются лишь раз, так что желаю удачи :) + + + + Редактор стилей + + Тут вы можете редактировать стили форума под себя

+ +
+ + Сохранить стили + +
\ No newline at end of file diff --git a/extens.css b/extens.css new file mode 100644 index 0000000..4a4fe73 --- /dev/null +++ b/extens.css @@ -0,0 +1,708 @@ +/* Стили */ + +.smile-content +{ + display: inline-block!important; + margin: 3px!important; +} + +.smile-content img[role="presentation"] +{ + max-height: 28px; + max-width: 28px; + white-space: unset!important; +} + +.tabs li.active a, .tabs.no-links li.active +{ + padding-bottom: 0px!important; +} + +.node .content-info +{ + overflow: inherit!important; +} + +fullpage +{ + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + + position: fixed; + + width: 100%; + height: 100%; + left: 0; + top: 0; + + color: #fff; + transition: opacity .3s; + + opacity: 0; + margin-top: -1000%; +} + +fullpage +{ z-index: 10000; } + + +backfon +{ + width: 100%; + height: 100%; + + position: fixed; + z-index: 10001; + + background: rgba(0, 0, 0, .7); + transition: opacity .3s; + + opacity: 0; +} + +backfon.loadfrom, backfon.saveto, +backfon.asett, backfon.asettchat, backfon.chan +{ + margin-top: -1000%; + z-index: 10003; +} + +backfon.alert, backfon.savetouser, backfon.wellcome, +backfon.userstyles +{ + margin-top: -1000%; + z-index: 10005; +} + +fullpage * +{ + display: flex; +} + +fullpage.open, smiles.open, +loadfrom.open, saveto.open, savetouser.open, +alert.open, asett.open, asettchat.open, backfon.open, +chan.open, wellcome.open, userstyles.open +{ + opacity: 1; +} + +fullpage.margin, smiles.margin, +loadfrom.margin, saveto.margin, savetouser.margin, +alert.margin, asett.margin, asettchat.margin, backfon.margin, +chan.margin, wellcome.margin, userstyles.margin +{ + margin-top: 0; +} + +smiles, loadfrom, saveto, savetouser, asett, asettchat, alert, chan, wellcome, userstyles +{ + position: absolute; + + width: 600px; + height: auto; + max-height: 85%; + border-radius: 3px; + + background: #121215; + + flex-direction: column; + transition: opacity .3s; + + opacity: 0; +} + +smiles { margin-top: -1000%; z-index: 10002; } +loadfrom, saveto, asett, asettchat, chan { margin-top: -1000%; z-index: 10004; } +alert, savetouser, wellcome, userstyles { margin-top: -1000%; z-index: 10006; } + +fullpage top +{ + background: #2b2c32; + border-radius: 3px; + + margin: 6px; + padding: 10px; + font-size: 16px; + + justify-content: space-between; + align-items: center; +} + +fullpage close, fullpage remove +{ + border-radius: 3px; + padding: 3px; + margin: 0 3px; + background: #121215; +} + +fullpage middle +{ + height: 100%; + flex-direction: column; + + padding: 10px 16px; +} + +@media (max-width: 600px) +{ + smiles, loadfrom, saveto, asett, asettchat, chan, userstyles + { + width: 100%; + height: 100%; + } + + alert, savetouser, wellcome + { + width: 100%; + } + + fullpage middle + { + overflow: auto; + } + + pages page + { + width: 100%!important; + } +} + +fullpage pages +{ + padding: 10px 16px; + justify-content: space-between; + flex-flow: row wrap; +} + +pages page +{ + width: 40%; + height: 39px; + padding: 0px 9px; + margin: 3px; + border-radius: 3px; + background: #2b2c32; + justify-content: center; + align-items: center; +} + +pages page.fullstroke +{ + width: 100%; + padding: 0px 9px; + margin: 3px; + border-radius: 3px; + background: #2b2c32; + justify-content: center; + align-items: center; +} + +.fullstroke gotcha +{ + width: 100%; + padding: 9px; + padding-left: 5px; +} + +pages page .page-centered +{ + display: flex; + align-items: center; + justify-content: center; +} + +fullpage bottom +{ + flex-direction: row; + padding: 0px 16px 10px; + justify-content: space-between; +} + +fullpage bottom left > * +{ + margin-right: 6px; +} + +finder +{ + flex-direction: row; + align-items: center; + margin-bottom: 6px; +} + +saveto finder +{ + justify-content: space-between; +} + +fullpage input[name='name'] +{ + width: 100px!important; +} + +fullpage input[name="tab"] +{ + width: 125px!important; +} + +/* Перекрываем стили как можем ей богу */ +fullpage input:not([mode="withoutfone"]), fullpage textarea +{ + margin: 0 5px 0 0!important; /* Особенно это */ + height: 29px!important; + line-height: 29px!important; + border-radius: 4px!important; + border: 1px solid #343434; + background-color: #000; + color: #989899!important; +} + +fullpage textarea +{ + height: 200px!important; + max-height: 200px; + word-break: break-all; +} + +fing +{ + height: 27px!important; + line-height: 25px; + border-radius: 4px!important; + color: #a8b5ba!important; + background-color: #000!important; + padding: 0px 7px!important; + border: 1px solid #343434!important; + + cursor: pointer; +} + +fing:hover +{ + background-color: #343434!important; +} + +fullpage smile-settings +{ + display: none; +} + +information img +{ + width: 150px; + height: 150px; +} + +fullpage pass +{ + width: 100%; + padding-left: 6px; + flex-direction: column; + + justify-content: center; +} + +fullpage pass > * +{ + align-items: center; +} + +fullpage pass t +{ + padding: 3px 9px; + border-radius: 3px; + margin: 3px 6px 3px 0; + background: #2b2c32; +} + +fullpage pass confirmation +{ + padding: 3px; + margin: 3px 6px 3px 0; +} + +fullpage pass fing +{ + width: 120px; + justify-content: center; +} + +smile-list +{ + flex-direction: column; + height: 100%; + overflow-y: scroll; + overflow-x: hidden; +} + +smile-list tab +{ + flex-direction: column; + margin-bottom: 5px; +} + +smile-list tab.minimized list +{ + display: none; +} + +smile-list tab list +{ + margin-left: 20px; + position: relative; +} + +smile-list tab list:before +{ + content: ''; + + left: -10px; + bottom: 0; + + width: 1px; + height: 41px; + + background: #2b2c32; + position: absolute; +} + +smile-list tab list:last-child:before +{ + content: ''; + + top: -6px; + left: -10px; + + width: 1px; + height: 23px; + + background: #2b2c32; + position: absolute; +} + +smile-list tab list:after +{ + content: ''; + + bottom: 0; + top: 16px; + left: -10px; + + width: 10px; + height: 1px; + + background: #2b2c32; + position: absolute; +} + +smile-list hit +{ + font-size: 14px; + justify-content: space-between; + align-items: center; + background: rgb(43, 44, 50); + border-radius: 3px; + margin: 0 3px 3px 0; + padding: 2px 10px; +} + +smile-list list +{ + margin: 3px 0; + transition: all .4s; + opacity: 0; + max-height: 0px; +} + +smile-list list.created +{ + opacity: 1; + max-height: 100px; +} + +smile-list list img +{ + max-height: 28px; + max-width: 28px; +} + +smile-list list > * +{ + background-color: #000; + margin: 0 3px; + border: 1px solid #343434; + border-radius: 4px; + padding: 2px 7px!important; +} + +smile-list list > *:first-child +{ + margin: 0 3px 0 0; +} + + +smile-list list > *:last-child +{ + margin: 0 0 0 3px; +} + +list input[name="name"] +{ + width: 84px; +} + +list input[name="value"] +{ + width: 100%; + align-items: center; +} + +list red, list del +{ + width: 25px; + + display: flex!important; + align-items: center; + justify-content: center; + + cursor: pointer; + text-decoration: none; +} + +list red:hover, list del:hover +{ + background-color: #343434!important; +} + +chan middle +{ + align-items: center; +} + +chan canedit +{ + width: 100%; + justify-content: center; + padding: 5px; + margin: 6px 0; + border-radius: 3px; + background: radial-gradient(circle, rgba(0,101,22,1) 0%, rgba(0,0,0,0) 100%); + + cursor: pointer; + + transition: background .3s; +} + +chan canedit.false +{ + background: radial-gradient(circle, rgba(101,0,0,1) 0%, rgba(0,0,0,0) 100%); +} + +chan helper +{ + text-align: center; +} + +chan canedit.false ~ finder[name='hiddly'] +{ max-height: 0px } + +chan finder +{ + max-height: 100px; + width: 100%; + overflow: hidden; + + transition: all .3s; +} + +chan input +{ + width: 50%!important; + border: none!important; +} + +chan finder input:first-child +{ + text-align: right; + background: linear-gradient(90deg, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 100%)!important; +} + +chan finder input:last-child +{ + text-align: left; + margin: 0!important; + background: linear-gradient(90deg, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 100%)!important; +} + +quotebutton +{ + padding: 5px 10px; + border-radius: 4px; + color: #a8b5ba; + background-color: #000; + border: 1px solid #343434; + + cursor: pointer; +} + +asett page[tab] input[name="index"] +{ + width: 45px; +} + +asett middle +{ + overflow: auto; +} + +fullpage input[mode="withoutfone"] +{ + margin: 5px!important; + margin-left: 0px!important; + border: none!important; + outline: none!important; + color: #eee!important; + background: none!important; + height: 29px!important; + border-radius: 3px; + + transition: all .3s; +} + + +fullpage input[mode="withoutfone"]:focus +{ + background: #121215!important; +} + +smiles finder input[mode="withoutfone"]:focus +{ + background: #0e0e0e!important; +} + +category +{ + flex-direction: column; + position: relative; +} + +category listed +{ + flex-direction: column; + position: absolute; + margin-top: 30px; + padding: 5px; + background: #000; + border-radius: 3px; + z-index: 10000; + width: 150%; + overflow: hidden; + transition: .4s; + + max-height: 0; + opacity: 0; +} + +category listed > * +{ + border-radius: 3px; + padding: 6px 9px; + margin: 3px 0; + border: 1px solid #343434; + + cursor: pointer; +} + +smiles finder category:hover listed +{ + max-height: 600px; + opacity: 1; +} + +wellcome +{ + padding: 10px; + align-items: center; + text-align: center; +} + +wellcome qn +{ + max-height: 0px; + opacity: 0; + transition: .4s; +} + + +alemg +{ + position: fixed; + display: flex!important; + top: 0; + left: 0; + + align-items: center; + justify-content: center; + + width: 100vw; + height: 100vh; + + z-index: 10010; + overflow: hidden; + + background: rgba(0, 0, 0, .6) center center; + background-repeat: no-repeat; + background-size: contain; + + transition: .3s; + opacity: 0; +} + +alemg:before +{ + position: absolute; + font-size: 32px!important; + + animation: rotate 1s linear infinite; +} + +alemg.endAnimate:before +{ + opacity: 0; +} + +@keyframes rotate +{ + from + { + transform: rotate(0deg); + } + + to + { + transform: rotate(360deg); + } +} + +alemg img +{ + opacity: 0; + transition: all .3s; +} + +page p { + width: 100%; +} + +[userstyles] +{ + border: 1px solid #333; + background: #3333; + color: #eee!important; + line-height: 18px!important; + font-size: 12px; +} \ No newline at end of file diff --git a/extension.js b/extension.js index a74c381..8bba7a5 100644 --- a/extension.js +++ b/extension.js @@ -8,6 +8,7 @@ load ('queryfinder.js'); load ('reservecopy.js'); load ('smiles.js'); load ('categories.js'); +load ('alert.js'); /* Форумные сообщения */ if (forumpostMods.indexOf(mode) > -1) @@ -16,10 +17,20 @@ if (forumpostMods.indexOf(mode) > -1) load ('forumpost.js'); } +/* Хлебные крошки */ +if (mode == 'threads') +{ + load ('breadcrumb.css'); + load ('breadcrumb.js'); +} + /* Форумный редактор */ load ('forumredactor.css'); load ('forumredactor.js'); +/* Стили пользователя */ +load ('userstyles'); + /* Чат на главной */ watching ({ @@ -167,7 +178,7 @@ document.addEventListener { el.querySelectorAll('a').forEach ( function (a){ - var page = JSON.parse(localStorage.getItem('page')), + var page = JSON.parse(get('page', this)), a = a; // получаемая переменная может работать только в пределах своей ф-ии @@ -175,13 +186,22 @@ document.addEventListener if (page) { Object.keys(page).forEach - ( function (b, index) { - var index = a.dataset.cat.toString(); - - a.textContent = page[index].name; + ( function (b) { + var index = parseInt(a.dataset.cat.toString()); - if (page[index].is == false) - a.style = 'display: none'; + if (page[index] != undefined) + { + a.textContent = page[index].name; + + if (page[index].is == false) + a.style = 'display: none'; + } + else + { + page[index] = {name: a.textContent, is: true}; + set('page', JSON.stringify(page), true); + log(`Обнаружена новая вкладка - ${a.textContent}`); + } }); } }); diff --git a/manifest.json b/manifest.json index 6933ba8..4288235 100644 --- a/manifest.json +++ b/manifest.json @@ -1,11 +1,11 @@ { "manifest_version": 2, - "version": "0.1.2.1", + "version": "0.1.2.2", "name": "D2S - форумный редактор", "description": "Кастомные смайлы, новый чат, редактор текста и прочее!", "content_scripts": [ { - "css": [ "extension.css" ], + "css": [ "extens.css" ], "js": [ "assets/js/footerfunctions.js",