// ==UserScript== // @name Dollchan Extension Tools // @version 20.3.17.0 // @namespace http://www.freedollchan.org/scripts/* // @author Sthephan Shinkufag @ FreeDollChan // @copyright © Dollchan Extension Team. See the LICENSE file for license rights and limitations (MIT). // @description Doing some profit for imageboards // @icon https://raw.github.com/SthephanShinkufag/Dollchan-Extension-Tools/master/Icon.png // @updateURL https://raw.github.com/SthephanShinkufag/Dollchan-Extension-Tools/master/Dollchan_Extension_Tools.meta.js // @nocompat Chrome // @run-at document-start // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @grant GM_openInTab // @grant GM_xmlhttpRequest // @grant GM.getValue // @grant GM.setValue // @grant GM.deleteValue // @grant GM.xmlHttpRequest // @grant unsafeWindow // @include https://endchan.net/* // ==/UserScript== /* eslint indent: ["error", "tab", { "flatTernaryExpressions": true, "outerIIFEBody": 0 }] */ (function deMainFuncInner(deWindow, prestoStorage, FormData, scrollTo, localData) { 'use strict'; const version = '20.3.17.0'; const commit = '71cd57c'; /* ==[ DefaultCfg.js ]======================================================================================== DEFAULT CONFIG =========================================================================================================== */ const defaultCfg = { disabled : 0, // Dollchan enabled by default language : 0, // Dollchan language [0=ru, 1=en] hideBySpell : 1, // hide posts by spells spells : null, // user defined spells sortSpells : 0, // sort spells and remove duplicates hideRefPsts : 0, // hide replies to hidden posts nextPageThr : 0, // load threads from next pages instead of hidden delHiddPost : 0, // remove placeholders [0=off, 1=all, 2=posts only, 3=threads only] ajaxUpdThr : 1, // threads updater updThrDelay : 20, // update interval (sec) updCount : 1, // show countdown to thread update favIcoBlink : 0, // blink the favicon on new posts desktNotif : 0, // desktop notifications for new posts noErrInTitle : 0, // don't show error code in title (except 404) markNewPosts : 1, // highlight new posts with color useDobrAPI : 1, // dobrochan: use json API markMyPosts : 1, // highlight my own posts expandTrunc : 0, // auto-expand truncated posts showHideBtn : 1, // show "Hide" buttons [0=off, 1=with menu, 2=no menu] showRepBtn : 1, // show "Quick reply" buttons [0=off, 1=with menu, 2=no menu] postBtnsCSS : 1, // post buttons style [0=simple, 1=gradient grey, 2=custom] postBtnsBack : '#8c8c8c', // custom background color thrBtns : 1, /* additional buttons under threads [0=off, 1=all, 2=all (on board), 3='New posts' on board] */ noSpoilers : 1, // text spoilers expansion [0=off, 1=grey, 2=native] limitPostMsg : 2000, // limit text width in posts nessages widePosts : 0, // stretch posts to screen width noPostNames : 0, // hide poster names correctTime : 0, // time correction in posts timeOffset : '+0', // time offset (h) timePattern : '', // search pattern timeRPattern : '', // replace pattern expandImgs : 2, // expand images on click [0=off, 1=in post, 2=by center] imgNavBtns : 1, // add buttons to navigate images imgInfoLink : 1, // show name under expanded image resizeDPI : 0, // don't upscale images on high DPI displays resizeImgs : 1, // resize large images to fit screen [0=off', '1=by width', '2=width+height] minImgSize : 100, // minimal size for expanded images (px) zoomFactor : 25, // images zoom sensibility [1-100%] webmControl : 1, // show control bar for WebM webmTitles : 0, // load titles from WebM metadata webmVolume : 100, // default volume for WebM [0-100%] minWebmWidth : 320, // minimal width for WebM (px) preLoadImgs : 0, // preload images [0=off, 1=all, 2=non-WebM] findImgFile : 0, // detect embedded files in images openImgs : 0, // replace thumbs with original images [0=off, 1=all, 2=GIFs only, 3=non-GIFs] imgSrcBtns : 1, // add "Search" buttons for images imgNames : 0, // image names in links [0=off, 1=original, 2=hide] maskImgs : 0, // NSFW mode maskVisib : 7, // image opacity in NSFW mode [0-100%] linksNavig : 1, // posts navigation by >>links linksOver : 100, // delay appearance (ms) linksOut : 1500, // delay disappearance (ms) markViewed : 0, // mark viewed posts strikeHidd : 0, // strike >>links to hidden posts removeHidd : 0, // also remove from reply maps noNavigHidd : 0, // don't show previews for hidden posts markMyLinks : 1, // mark links to my posts with (You) crossLinks : 0, // replace http:// with >>/b/links* decodeLinks : 0, // decode %D0%A5%D1 in links insertNum : 1, // insert >>link on №postnumber click* addOPLink : 0, // insert >>link when replying to OP on board addImgs : 0, // load images to jpg/png/gif links* addMP3 : 1, // embed mp3 links addVocaroo : 1, // embed Vocaroo links embedYTube : 1, // embed YouTube links [0=off, 1=preview+player, 2=onclick] YTubeWidth : 360, // player width (px) YTubeHeigh : 270, // player height (px) YTubeTitles : 0, // load titles for YouTube links ytApiKey : '', // YouTube API key addVimeo : 1, // embed Vimeo links ajaxPosting : 1, // posting without refresh postSameImg : 1, // ability to post duplicate images removeEXIF : 1, // remove EXIF from JPEG removeFName : 0, // clear file names [0=off, 1=empty, 2=unixtime, 3=unixtime-random] sendErrNotif : 1, // inform in title about post send error scrAfterRep : 0, // scroll to bottom after reply fileInputs : 2, // enhanced file attachment field [0=off, 1=simple, 2=preview] addPostForm : 2, // reply form display in thread [0=at top, 1=at bottom, 2=hidden] spacedQuote : 1, // insert a space when quoting "> " favOnReply : 1, // add thread to favorites after reply warnSubjTrip : 0, // warn about a tripcode in "Subject" field addSageBtn : 1, // replace "Email" with Sage button saveSage : 1, // remember sage sageReply : 0, // reply with sage altCaptcha : 0, // use alternative captcha (if available) capUpdTime : 300, // captcha update interval (sec) captchaLang : 1, // forced captcha input language [0=off, 1=en, 2=ru] addTextBtns : 1, // text markup buttons [0=off, 1=graphics, 2=text, 3=usual] txtBtnsLoc : 1, // located at [0=top, 1=bottom] userPassw : 1, // user password passwValue : '', // value userName : 0, // user name nameValue : '', // value noBoardRule : 0, // hide board rules noPassword : 1, // hide form "Password" field noName : 0, // hide form "Name" field noSubj : 0, // hide form "Subject" field scriptStyle : 0, /* Dollchan style [0=Gradient darkblue, 1=gradient blue, 2=solid grey, 3=transparent blue, 4=square dark] */ userCSS : 0, // user CSS userCSSTxt : '', // css text expandPanel : 0, // show full main panel animation : 1, // CSS3 animation hotKeys : 1, // hotkeys loadPages : 1, // number of pages that are loaded on F5 panelCounter : 1, // panel counter for posts/images [0=off, 1=all posts, 2=except hidden] hideReplies : 0, // show only op-posts in threads list rePageTitle : 1, // show thread title in the page tab inftyScroll : 1, // infinite scrolling for pages scrollToTop : 0, // always scroll to top in the threads list saveScroll : 1, // remember the scroll position in threads favThrOrder : 0, /* threads sorting order in the Favorites window [0=by opnum, 1=by opnum (desc), 2=by adding, 3=by adding (desc)] */ favWinOn : 0, // Always open the Favorites window closePopups : 0, // close popups automatically updDollchan : 2, // Check for Dollchan updates [0=off, 1=per day, 2=2days, 3=week, 4=2weeks, 5=month] textaWidth : 300, // textarea width (px) textaHeight : 115, // textarea height (px) replyWinDrag : 0, // draggable "Quick Reply" form replyWinX : 'right: 0', // "Quick Reply" form X position replyWinY : 'top: 0', // "Quick Reply" form Y position cfgTab : 'filters', // remembered tab in "Settings" window cfgWinDrag : 0, // draggable "Settings" window cfgWinX : 'right: 0', // "Settings" window X position cfgWinY : 'top: 0', // "Settings" window Y position hidWinDrag : 0, // draggable "Hidden" window hidWinX : 'right: 0', // "Hidden" window X position hidWinY : 'top: 0', // "Hidden" window Y position favWinDrag : 0, // draggable "Favorites" window favWinX : 'right: 0', // "Favorites" window X position favWinY : 'top: 0', // "Favorites" window Y position favWinWidth : 500, // "Favorites" window width (px) vidWinDrag : 0, // draggable "Video" window vidWinX : 'right: 0', // "Video" window X position vidWinY : 'top: 0' // "Video" window Y position }; /* ==[ Localization.js ]====================================================================================== LOCALIZATION =========================================================================================================== */ const Lng = { // "Settings" window: tab names cfgTab: { filters : ['Фильтры', 'Filters', 'Фільтри'], posts : ['Посты', 'Posts', 'Пости'], images : ['Картинки', 'Images', 'Зображ.'], links : ['Ссылки', 'Links', 'Посил.'], form : ['Форма', 'Form', 'Форма'], common : ['Общее', 'Common', 'Спільне'], info : ['Инфо', 'Info', 'Інфо'] }, // "Settings" window: options cfg: { language: { sel : [['Ru', 'En', 'Ua'], ['Ru', 'En', 'Ua'], ['Ru', 'En', 'Ua']], txt : ['', '', ''] }, // "Filters" tab hideBySpell: [ 'Спеллы: ', 'Magic spells: ', 'Спелли: '], sortSpells: [ 'Сортировать спеллы и удалять дубликаты', 'Sort spells and remove duplicates', 'Сортувати спелли та видаляти дублікати'], hideRefPsts: [ 'Скрывать ответы на скрытые посты', 'Hide replies to hidden posts', 'Ховати відповіді на сховані пости'], nextPageThr: [ 'Скрытые треды - загружать со следующих страниц', 'Load threads from next pages instead of hidden', 'Сховані треди - брати з наступних сторінок'], delHiddPost: { sel: [ ['Откл.', 'Всё', 'Только посты', 'Только треды'], ['Disable', 'All', 'Posts only', 'Threads only'], ['Вимк.', 'Все', 'Лише пости', 'Лише треди']], txt: [ 'Удалять скрытое', 'Remove placeholders', 'Видаляти сховане'] }, // "Posts" tab ajaxUpdThr: [ 'Апдейтер тредов ', 'Threads updater ', 'Оновлювач тредів '], updThrDelay: [ '(сек)', '(sec)', '(сек)'], updCount: [ 'Обратный счетчик обновления треда', 'Show countdown to thread update', 'Зворотній відлік оновлення треду'], favIcoBlink: [ 'Мигать фавиконом при появлении новых постов', 'Blink the favicon on new posts', 'Блимати фавіконом в разі появи нових постів'], desktNotif: [ 'Уведомлять о новых постах на рабочем столе', 'Desktop notifications for new posts', 'Повідомляти про нові пости на стільниці'], noErrInTitle: [ 'Не показывать номер ошибки в заголовке', 'Donʼt show error code in pageʼs title', 'Не показувати номер помилки в заголовку'], markNewPosts: [ 'Выделять цветом новые посты', 'Highlight new posts with color', 'Виділяти кольором нові пости'], useDobrAPI: [ 'dobrochan: использовать JSON API', 'dobrochan: use JSON API', 'dobrochan: використовувати JSON API'], markMyPosts: [ 'Выделять цветом мои посты', 'Highlight my own posts', 'Виділяти кольором мої пости'], expandTrunc: [ 'Авторазворот сокращенных постов*', 'Autoexpand truncated posts*', 'Авторозгортання скорочених постів*'], thrBtns: { sel: [ ['Откл.', 'Все', 'Все (на доске)', '"Новые посты" на доске'], ['Disable', 'All', 'All (on board)', '"New posts" on board'], ['Вимк.', 'Всі', 'Всі (на дошці)', '"Нові пости" на дошці']], txt: [ 'Кнопки под тредами', 'Buttons under threads', 'Кнопки під тредами'] }, showHideBtn: { sel: [ ['Откл.', 'С меню', 'Без меню'], ['Disable', 'With menu', 'No menu'], ['Вимк.', 'Із меню', 'Без меню']], txt: [ 'Кнопки "Скрыть пост/тред"', '"Hide post/thread" buttons', 'Кнопки "Сховати пост/тред"'] }, showRepBtn: { sel: [ ['Откл.', 'С меню', 'Без меню'], ['Disable', 'With menu', 'No menu'], ['Вимк.', 'Із меню', 'Без меню']], txt: [ 'Кнопки "Ответить на пост/тред"', '"Reply to post/thread" buttons', 'Кнопки "Відповісти на пост/тред"'] }, postBtnsCSS: { sel: [ ['Упрощенные', 'Серый градиент', 'Настраиваемые'], ['Simple', 'Gradient grey', 'Custom'], ['Спрощені', 'Сірий градієнт', 'Користувацькі']], txt: [ 'Кнопки постов ', 'Post buttons ', 'Кнопки постів '] }, noSpoilers: { sel: [ ['Откл.', 'Серое', 'Родное'], ['Disable', 'Grey', 'Native'], ['Вимк.', 'Сіре', 'Рідне']], txt: [ 'Раскрытие текстовых спойлеров', 'Text spoilers expansion', 'Розкриття текстових спойлерів'] }, limitPostMsg: [ 'Ограничение ширины текста в постах (px)', 'Limit text width in posts messages (px)', 'Обмеження ширини тексту в постах (px)' ], widePosts: [ 'Растягивать посты по ширине экрана', 'Stretch posts to page width', 'Розтягувати пости на ширину екрану'], noPostNames: [ 'Скрывать имена в постах', 'Hide poster names', 'Ховати імена в постах'], correctTime: [ 'Коррекция времени в постах* ', 'Time correction in posts* ', 'Корекція часу в постах* '], timeOffset: [ 'разница (ч) ', 'time offset (h) ', 'різниця (год) '], timePattern: [ 'Шаблон поиска', 'Search pattern', 'Шаблон пошуку'], timeRPattern: [ 'Шаблон замены', 'Replace pattern', 'Шаблон заміни'], // "Images" tab expandImgs: { sel: [ ['Откл.', 'В посте', 'По центру'], ['Disable', 'In post', 'By center'], ['Вимк.', 'В пості', 'По центру']], txt: [ 'Раскрывать картинки по клику', 'Expand images on click', 'Розгортати зображення по кліку'] }, imgNavBtns: [ 'Добавлять кнопки навигации по картинкам', 'Add buttons to navigate images', 'Додавати кнопки навігації по зображеннях'], imgInfoLink: [ 'Имя файла под раскрытой картинкой', 'Show file name under expanded image', 'Імʼя файлу під розкритим зображенням'], resizeDPI: [ 'Не растягивать на дисплеях с высоким DPI', 'Donʼt upscale images on high DPI displays', 'Не розтягувати на дисплеях з високим DPI'], resizeImgs: { sel: [ ['Откл.', 'По ширине', 'Шир.+выс.'], ['Disable', 'By width', 'Width+Height'], ['Вимк.', 'По ширині', 'Шир.+выс.']], txt: [ 'Уменьшать при раскрытии в посте', 'Fit to screen for expanding in post', 'Зменшувати при розкритті в пості'] }, minImgSize: [ 'Миним. размер раскрытых картинок (px)', 'Minimal size for expanded images (px)', 'Мінім. розмір розгорнутих зображень (px)'], zoomFactor: [ 'Чувствительность зума картинок [1-100%]', 'Images zoom sensibility [1-100%]', 'Чутливість зуму зображень [1-100%]'], webmControl: [ 'Показывать контрол-бар для WebM', 'Show control bar for WebM', 'Показувати смугу керування для WebM'], webmTitles: [ 'Получать названия WebM из метаданных', 'Load titles from WebM metadata', 'Отримувати назви WebM з метаданих'], webmVolume: [ 'Громкость WebM по умолчанию [0-100%]', 'Default volume for WebM [0-100%]', 'Гучність WebM по замовчуванню [0-100%]'], minWebmWidth: [ 'Минимальная ширина WebM (px)', 'Minimal width for WebM (px)', 'Мінімальна ширина WebM (px)'], preLoadImgs: { sel: [ ['Откл.', 'Все', 'Без WebM'], ['Disable', 'All', 'Non-WebM'], ['Вимк.', 'Всі', 'Крім WebM']], txt: [ 'Предварительно загружать картинки*', 'Preload images*', 'Наперед завантажувати зображення*'] }, findImgFile: [ 'Распознавать файлы, встроенные в картинках*', 'Detect embedded files in images*', 'Розпізнавати файли, що вбудовані в зображення*'], openImgs: { sel: [ ['Откл.', 'Все подряд', 'Только GIF', 'Кроме GIF'], ['Disable', 'All types', 'Only GIF', 'Non-GIF'], ['Вимк.', 'Всі', 'Лише GIF', 'Крім GIF']], txt: [ 'Заменять картинки на оригиналы*', 'Replace thumbnails with original images*', 'Замінювати зображення на оригінали*'] }, imgSrcBtns: [ 'Добавлять кнопки "Поиск" для картинок', 'Add "Search" buttons for images', 'Додавати кнопки "Пошук" для зображень'], imgNames: { sel: [ ['Не изменять', 'Настоящие (сокр.)', 'Скрывать', 'Настоящие (полные)'], ['Don`t change', 'Original (trunc.)', 'Hide', 'Original (full)'], ['Не змінювати', 'Справжні (скороч.)', 'Ховати', 'Справжні (повні)']], txt: [ 'имена картинок', 'filenames', 'імена зображень'] }, maskVisib: [ 'Видимость для NSFW-картинок [0-100%]', 'Visibility for NSFW images [0-100%]', 'Видимість для NSFW-зображень [0-100%]'], // "Links" tab linksNavig: [ 'Навигация постов по >>ссылкам* ', 'Posts navigation by >>links* ', 'Навігація постів по >>посиланнях* '], linksOver: [ 'Появление ', 'Appearance ', 'Поява '], linksOut: [ 'Пропадание (мс)', 'Disappearance (ms)', 'Зникнення (мс)'], markViewed: [ 'Помечать просмотренные посты', 'Mark viewed posts', 'Позначати переглянуті пости'], strikeHidd: [ 'Зачеркивать >>ссылки на скрытые посты', 'Strike >>links to hidden posts', 'Закреслювати >>посилання на сховані пости'], removeHidd: [ 'Также удалять из обратных >>ссылок', 'Also remove from >>backlinks', 'Також видаляти із зворотніх >>посилань'], noNavigHidd: [ 'Не отображать превью для скрытых постов', 'Donʼt show previews for hidden posts', 'Не показувати превʼю до cхованих постів'], markMyLinks: [ 'Помечать ссылки на мои посты как (You)', 'Mark links to my posts with (You)', 'Позначати посилання на мої пости як (You)'], crossLinks: [ 'Заменять http:// на >>/b/ссылки*', 'Replace http:// with >>/b/links*', 'Замінювати https:// на >>/b/посилання*'], decodeLinks: [ 'Декодировать %D0%A5%D1 в ссылках*', 'Decode %D0%A5%D1 in links*', 'Декодувати %D0%A5%D1 в посиланнях*'], insertNum: [ 'Вставлять >>ссылку по клику на №поста*', 'Insert >>link on №postnumber click*', 'Вставляти >>посилання на клік по №посту*'], addOPLink: [ '>>ссылка при ответе на OP в списке тредов', 'Insert >>link when replying to OP on threads list', '>>посилання при відповіді на OP у списці тредів'], addImgs: [ 'Загружать картинки к jpg/png/gif ссылкам*', 'Load images for jpg/png/gif links*', 'Додавати зображення до jpg/png/gif посилань*'], addMP3: [ 'Плеер к mp3 ссылкам* ', 'Player for mp3 links* ', 'Плеєр до mp3 посилань* '], addVocaroo: [ 'к Vocaroo ссылкам*', 'for Vocaroo links*', 'до Vocaroo посилань*'], addVimeo: [ 'Добавлять плеер к Vimeo ссылкам*', 'Add player for Vimeo links*', 'Додавати плеєр до Vimeo посилань*'], embedYTube: { sel: [ ['Ничего', 'Превью+плеер', 'Плеер по клику'], ['Nothing', 'Preview+player', 'On click player'], ['Нічого', 'Превʼю+плеєр', 'Плеєр по кліку']], txt: [ 'к YouTube ссылкам* ', 'for YouTube links* ', 'до YouTube посилань* '] }, YTubeTitles: [ 'Загружать названия к YouTube ссылкам*', 'Load titles for YouTube links*', 'Отримувати назви до YouTube посилань*'], ytApiKey: [ 'Ключ YT API*', 'YT API Key*', 'Ключ YT API*'], // "Form" tab ajaxPosting: [ 'Отправка постов без перезагрузки*', 'Posting without page refresh*', 'Постування без оновлення сторінки*'], postSameImg: [ 'Возможность отправки одинаковых картинок', 'Ability to post duplicate images', 'Можливість надсилання однакових зображень'], removeEXIF: [ 'Удалять EXIF из JPEG ', 'Remove EXIF from JPEG ', 'Видаляти EXIF з JPEG '], removeFName: { sel: [ ['Не изменять', 'Удалять', 'Unixtime', 'Unixtime-random'], ['Don`t change', 'Clear', 'Unixtime', 'Unixtime-random'], ['Не змінювати', 'Видаляти', 'Unixtime', 'Unixtime-random']], txt: [ 'имена файлов', 'file names', 'імена файлів'] }, sendErrNotif: [ 'Оповещать в заголовке об ошибке отправки', 'Inform in title about post send error', 'Сповіщати в заголовку про помилку надсилання'], scrAfterRep: [ 'Перемещаться в конец треда после отправки', 'Scroll to bottom after reply', 'Гортати в кінець треду після надсилання'], fileInputs: { sel: [ ['Откл.', 'Упрощ.', 'Превью'], ['Disable', 'Simple', 'Preview'], ['Вимкн.', 'Спрощене', 'Превʼю']], txt: [ 'Улучшенное поле добавления файлов', 'Enhanced file attachment field', 'Покращене поле додавання файлів'] }, addPostForm: { sel: [ ['Сверху', 'Внизу', 'Скрытая'], ['At top', 'At bottom', 'Hidden'], ['Вгорі', 'Знизу', 'Прихована']], txt: [ 'Форма ответа в треде', 'Reply form display in thread', 'Форма відповіді в треді'] }, spacedQuote: [ 'Вставлять пробел при цитировании "> "', 'Insert a space when quoting "> "', 'Вставляти пробіл при цитуванні "> "'], favOnReply: [ 'Добавлять тред в "Избранное" после ответа', 'Add thread to "Favorites" after reply', 'Додавати тред в "Вибране" після відповіді'], warnSubjTrip: [ 'Оповещать о трипкоде в поле "Тема"', 'Warn about a tripcode in "Subject" field', 'Сповіщувати про трипкод в полі "Тема"'], addSageBtn: [ 'Кнопка Sage вместо поля "Email" ', 'Replace "Email" with Sage button ', 'Кнопка Sage замість "E-mail" '], saveSage: [ 'Помнить сажу', 'Remember sage', 'Памʼятати сажу'], altCaptcha: [ 'Использовать альтернативную капчу', 'Use alternative captcha', 'Використовувати альтернативну капчу'], capUpdTime: [ 'Интервал обновления капчи (сек)', 'Captcha update interval (sec)', 'Інтервал оновлення капчі (сек)'], captchaLang: { sel: [ ['Откл.', 'Eng', 'Rus'], ['Disable', 'Eng', 'Rus'], ['Вимк.', 'Eng', 'Ukr']], txt: [ 'Принудительный язык ввода капчи', 'Forced captcha input language', 'Примусова мова вводу капчі'] }, addTextBtns: { sel: [ ['Откл.', 'Графические', 'Упрощённые', 'Стандартные'], ['Disable', 'As images', 'As text', 'Standard'], ['Вимк.', 'Графічні', 'Спрощені', 'Стандартні']], txt: [ 'Кнопки разметки текста ', 'Text markup buttons ', 'Кнопки розмітки тексту '] }, txtBtnsLoc: [ 'Внизу', 'At bottom', 'Знизу'], userPassw: [ 'Постоянный пароль', 'Fixed password', 'Постійний пароль'], userName: [ 'Постоянное имя', 'Fixed name', 'Постійне імʼя'], noBoardRule: [ 'Правила ', 'Rules ', 'Правила '], noPassword: [ 'Пароль ', 'Password ', 'Пароль '], noName: [ 'Имя ', 'Name ', 'Імʼя '], noSubj: [ 'Тему', 'Subject', 'Тему'], // "Common" tab scriptStyle: { sel: [ ['Gradient darkblue', 'Gradient blue', 'Solid grey', 'Transparent blue', 'Square dark'], ['Gradient darkblue', 'Gradient blue', 'Solid grey', 'Transparent blue', 'Square dark'], ['Gradient darkblue', 'Gradient blue', 'Solid grey', 'Transparent blue', 'Square dark']], txt: [ 'Стиль Dollchan', 'Dollchan style', 'Стиль Dollchan'] }, userCSS: [ 'Пользовательский CSS', 'User CSS', 'Користувацький CSS'], animation: [ 'CSS3 анимация', 'CSS3 animation', 'CSS3 анімація'], hotKeys: [ 'Горячие клавиши', 'Hotkeys', 'Гарячі клавіші'], loadPages: [ 'Количество страниц, загружаемых по F5', 'Number of pages that are loaded on F5 ', 'Кількість сторінок, що завантажуються по F5'], panelCounter: { sel: [ ['Откл.', 'Все посты', 'Без скрытых'], ['Disabled', 'All posts', 'Except hidden'], ['Вимкн.', 'Усі пости', 'Крім схованих']], txt: [ 'Счетчик постов/картинок в треде', 'Сounter for posts/images in thread', 'Лічильник постів/зображень в треді'] }, rePageTitle: [ 'Название треда в заголовке вкладки*', 'Show thread title in the page tab*', 'Назва треду в заголовку вкладки*'], inftyScroll: [ 'Бесконечная прокрутка страниц', 'Infinite scrolling for pages', 'Нескінченна прокрутка сторінок'], hideReplies: [ 'Показывать только OP в списке тредов*', 'Show only OP in threads list*', 'Показувати лише OP в списку тредів*'], scrollToTop: [ 'Всегда перемещаться вверх в списке тредов', 'Always scroll to top in the threads list', 'Завжди гортати догори в списку тредів'], saveScroll: [ 'Запоминать позицию скролла в тредах', 'Remember the scroll position in threads', 'Пам`ятати позицію скролла в тредах'], favThrOrder: { sel: [ ['По номеру', 'По номеру (убыв)', 'По добавлению', 'По добавлению (убыв)'], ['By number', 'By number (desc)', 'By adding', 'By adding (desc)'], ['За номером', 'За номером (зменш)', 'По додаванню', 'По додаванню (зменш)']], txt: [ 'Сортировка в Избранном', 'Sorting in Favorites', 'Сортування в Вибраному'] }, favWinOn: [ 'Всегда открывать окно Избранное', 'Always open the Favorites window', 'Завжди відкривати вікно Вибране'], closePopups: [ 'Автоматически закрывать уведомления', 'Close popups automatically', 'Автоматично закривати сповіщення'], updDollchan: { sel: [ ['Откл.', 'Каждый день', 'Каждые 2 дня', 'Каждую неделю', 'Каждые 2 недели', 'Каждый месяц'], ['Disable', 'Every day', 'Every 2 days', 'Every week', 'Every 2 weeks', 'Every month'], ['Вимкн.', 'Щодня', 'Кожні 2 дні', 'Щотижня', 'Кожні 2 тижні', 'Щомісяця']], txt: [ 'Проверять обновления Dollchan', 'Check for Dollchan updates', 'Перевіряти оновлення Dollchan'] } }, // Main panel buttons: tooltips panelBtn: { attach: [ 'Прикрепить/Открепить панель', 'Attach/Detach panel', 'Закріпити/відкріпити панель'], cfg: [ 'Настройки', 'Settings', 'Налаштування'], hid: [ 'Скрытое', 'Hidden', 'Сховане'], fav: [ 'Избранное', 'Favorites', 'Вибране'], vid: [ 'Ссылки на видео', 'Video links', 'Посилання на відео'], refresh: [ 'Обновить', 'Refresh', 'Оновити'], goback: [ 'Назад на доску', 'Return to board', 'Назад до дошки'], gonext: [ 'На %s страницу', 'Go to page %s', 'До %s сторінки'], goup: [ 'В начало страницы', 'Scroll to top', 'Прогорнути догори'], godown: [ 'В конец страницы', 'Scroll to bottom', 'Прогорнути донизу'], expimg: [ 'Раскрыть все картинки', 'Expand all images', 'Розгорнути всі зображення'], maskimg: [ 'Режим NSFW', 'NSFW mode', 'Режим NSFW'], preimg: [ 'Предзагрузить картинки\r\n([Ctrl+Click] только для новых постов)', 'Preload images\r\n([Ctrl+Click] for new posts only)', 'Наперед завантажити зображення\r\n([Ctrl+Click] лише для нових постів)'], savethr: [ 'Сохранить на диск', 'Save to disk', 'Зберегти на диск'], 'upd-on': [ 'Выключить автообновление треда', 'Disable thread updater', 'Вимкнути оновлювач треду'], 'upd-off': [ 'Включить автообновление треда', 'Enable thread updater', 'Увімкнути оновлювач треду'], 'audio-off': [ 'Звуковое оповещение о новых постах', 'Sound notification about new posts', 'Звукове сповіщення про нові пости'], catalog: [ 'Перейти в каталог', 'Go to catalog', 'Перейти до каталогу'], enable: [ 'Включить/выключить Dollchan', 'Turn on/off the Dollchan', 'Увімкнути/вимкнути Dollchan'], pcount: [ 'Постов в треде', 'Posts in thread', 'Постів у треді'], pcountNotHid: [ 'Постов в треде (без скрытых)', 'Posts in thread (without hidden)', 'Постів у треді (крім схованих)'], imglen: [ 'Картинок в треде', 'Images in thread', 'Зображень у треді'], posters: [ 'Постящих в треде', 'Posters in thread', 'Постувачів у треді'] }, // Post buttons: tooltips togglePost: [ 'Скрыть/Раскрыть пост', 'Hide/Unhide post', 'Сховати/показати пост'], toggleThr: [ 'Скрыть/Раскрыть тред', 'Hide/Unhide thread', 'Сховати/показати тред'], replyToPost: [ 'Ответить на пост', 'Reply to post', 'Відповісти на пост'], replyToThr: [ 'Ответить в тред', 'Reply to thread', 'Відповісти в тред'], expandThr: [ 'Развернуть тред', 'Expand thread', 'Розгорнути тред'], addFav: [ 'Добавить тред в Избранное', 'Add thread to Favorites', 'Додати тред в Вибране'], delFav: [ 'Убрать тред из Избранного', 'Remove thread from Favorites', 'Прибрати тред з Вибраного'], attachPview: [ 'Закрепить превью', 'Attach preview', 'Закріпити превʼю'], // Windows buttons: tooltips closeWindow: [ 'Закрыть окно', 'Close window', 'Закрити вікно'], closeReply: [ 'Закрыть форму', 'Close form', 'Закрити форму'], toPanel: [ 'Закрепить на панели', 'Attach to panel', 'Закріпити на панелі'], makeDrag: [ 'Сделать перетаскиваемым окном', 'Make draggable window', 'Зробити перетягуваним вікном'], underPost: [ 'Разместить форму после поста', 'Move form under post', 'Розмістити форму після посту'], clearForm: [ 'Очистить форму', 'Clear form', 'Очистити форму'], // Markup buttons: tooltips txtBtn: [ ['Жирный', 'Bold', 'Жирний'], ['Курсив', 'Italic', 'Курсив'], ['Подчеркнутый', 'Underlined', 'Підкреслений'], ['Зачеркнутый', 'Strike', 'Закреслений'], ['Спойлер', 'Spoiler', 'Спойлер'], ['Код', 'Code', 'Код'], ['Верхний индекс', 'Superscript', 'Верхній індекс'], ['Нижний индекс', 'Subscript', 'Нижній індекс'], ['Цитировать выделенное', 'Quote selected', 'Цитувати виділене']], // Drop-down menus: options selHiderMenu: { // "Hide" post button sel: [ 'Скрывать выделенное', 'Hide selected text', 'Ховати виділене'], name: [ 'Скрывать по имени', 'Hide by name', 'Ховати по імені'], trip: [ 'Скрывать по трипкоду', 'Hide by tripcode', 'Ховати по тріпкоду'], img: [ 'Скрывать по размеру картинки', 'Hide by image size', 'Ховати по розміру зображення'], imgn: [ 'Скрывать по имени картинки', 'Hide by image name', 'Ховати по імені зображення'], ihash: [ 'Скрывать схожие картинки', 'Hide by similar images', 'Ховати подібні зображення'], noimg: [ 'Скрывать без картинок', 'Hide without images', 'Ховати без зображень'], notext: [ 'Скрывать без текста', 'Hide without text', 'Ховати без тексту'], text: [ 'Скрыть схожий текст', 'Hide similar text', 'Сховати схожий текст'], refs: [ 'Скрыть с ответами', 'Hide with replies', 'Сховати з відповідями'], refsonly: [ 'Скрывать ответы', 'Hide replies', 'Ховати відповіді'] }, selExpandThr: [ // "Expand thread" post button ['+10 постов', 'Последние 30', 'Последние 50', 'Последние 100', 'Весь тред'], ['+10 posts', 'Last 30 posts', 'Last 50 posts', 'Last 100 posts', 'Entire thread'], ['+10 постів', 'Останні 30', 'Останні 50', 'Останні 100', 'Весь тред']], selAjaxPages: [ // "Refresh" panel button ['1 страница', '2 страницы', '3 страницы', '4 страницы', '5 страниц'], ['1 page', '2 pages', '3 pages', '4 pages', '5 pages'], ['1 сторінка', '2 сторінки', '3 сторінки', '4 сторінки', '5 сторінок']], selSaveThr: [ // "Save to disk" panel button ['Скачать весь тред', 'Скачать картинки'], ['Download thread', 'Download images'], ['Завантажити весь тред', 'Завантажити зображення']], selAudioNotif: [ // "Sound notification" panel button ['Каждые 30 сек.', 'Каждую минуту', 'Каждые 2 мин.', 'Каждые 5 мин.'], ['Every 30 sec.', 'Every minute', 'Every 2 min.', 'Every 5 min.'], ['Кожні 30 сек.', 'Щохвилини', 'Кожні 2 хв.', 'Кожні 5 хв.']], reportPost: [ 'Жалоба на пост', 'Report post', 'Скарга на пост'], reportThr: [ 'Жалоба на тред', 'Report thread', 'Скарга на тред'], markMyPost: [ 'Пометить пост как мой', 'Mark post as mine', 'Відмітити пост як мій' ], deleteMyPost: [ 'Убрать из моих постов', 'Delete from my posts', 'Прибрати з моїх постів' ], // Sauce search for images and video frames searchIn: [ 'Искать в ', 'Search in ', 'Шукати в '], frameSearch: [ 'Поиск кадра в ', 'Frame search in ', 'Пошук кадру в '], gotoResults: [ 'Перейти к результатам поиска', 'Go to search results', 'Перейти до результатів пошуку'], getFrameLinks: [ 'Получить ссылки для поиска этого кадра', 'Get links to search this frame', 'Отримати посилання для пошуку цього кадру'], saveFrame: [ 'Сохранить полученный кадр', 'Save the received frame', 'Зберегти отриманий кадр'], errSaucenao: [ 'Ошибка: не могу загрузить на saucenao.com', 'Error: can`t load to saucenao.com', 'Помилка: не можу завантажити на saucenao.com'], // Hotkeys editor hotKeyEdit: [[ // Ru '%l%i24 – предыдущая страница/картинка%/l', '%l%i217 – следующая страница/картинка%/l', '%l%i21 – тред (на доске)/пост (в треде) ниже%/l', '%l%i20 – тред (на доске)/пост (в треде) выше%/l', '%l%i31 – пост (на доске) ниже%/l', '%l%i30 – пост (на доске) выше%/l', '%l%i23 – скрыть пост/тред%/l', '%l%i32 – перейти в тред%/l', '%l%i33 – развернуть тред%/l', '%l%i211 – раскрыть картинку в посте%/l', '%l%i22 – быстрый ответ%/l', '%l%i25t – отправить пост%/l', '%l%i210 – открыть/закрыть "Настройки"%/l', '%l%i26 – открыть/закрыть "Избранное"%/l', '%l%i27 – открыть/закрыть "Скрытое"%/l', '%l%i218 – открыть/закрыть "Видео"%/l', '%l%i28 – открыть/закрыть панель%/l', '%l%i29 – вкл./выкл. режим NSFW%/l', '%l%i40 – обновить тред (в треде)%/l', '%l%i212t – жирный%/l', '%l%i213t – курсив%/l', '%l%i214t – зачеркнутый%/l', '%l%i215t – спойлер%/l', '%l%i216t – код%/l'], [ // En '%l%i24 – previous page/image%/l', '%l%i217 – next page/image%/l', '%l%i21 – thread (on board)/post (in thread) below%/l', '%l%i20 – thread (on board)/post (in thread) above%/l', '%l%i31 – on board post below%/l', '%l%i30 – on board post above%/l', '%l%i23 – hide post/thread%/l', '%l%i32 – go to thread%/l', '%l%i33 – expand thread%/l', '%l%i211 – expand postʼs images%/l', '%l%i22 – quick reply%/l', '%l%i25t – send post%/l', '%l%i210 – open/close "Settings"%/l', '%l%i26 – open/close "Favorites"%/l', '%l%i27 – open/close "Hidden"%/l', '%l%i218 – open/close "Videos"%/l', '%l%i28 – open/close main panel%/l', '%l%i29 – toggle NSFW mode%/l', '%l%i40 – update thread%/l', '%l%i212t – bold%/l', '%l%i213t – italic%/l', '%l%i214t – strike%/l', '%l%i215t – spoiler%/l', '%l%i216t – code%/l'], [ // Ua '%l%i24 – попередня сторінка/зображення%/l', '%l%i217 – наступна сторінка/зображення%/l', '%l%i21 – тред (на дошці)/пост (в треді) нижче%/l', '%l%i20 – тред (на дошці)/пост (в треді) вище%/l', '%l%i31 – пост (на дошці) нижче%/l', '%l%i30 – пост (на дошці) вище%/l', '%l%i23 – приховати пост/тред%/l', '%l%i32 – перейти в тред%/l', '%l%i33 – розгорнути тред%/l', '%l%i211 – розгорнути зображення в пості%/l', '%l%i22 – швидка відповідь%/l', '%l%i25t – відправити пост%/l', '%l%i210 – відкрити/закрити "Налаштування"%/l', '%l%i26 – відкрити/закрити "Вибране"%/l', '%l%i27 – відкрити/закрити "Сховане"%/l', '%l%i218 – відкрити/закрити "Посилання на відео"%/l', '%l%i28 – відкрити/закрити панель%/l', '%l%i29 – увімкнути/вимкнути режим NSFW%/l', '%l%i40 – оновити тред (в треді)%/l', '%l%i212t – жирний%/l', '%l%i213t – курсив%/l', '%l%i214t – закреслений%/l', '%l%i215t – спойлер%/l', '%l%i216t – код%/l']], // Time correction in posts cTimeError: [ 'Неправильные настройки времени', 'Invalid time settings', 'Неправильні налаштування часу'], month: [ ['янв', 'фев', 'мар', 'апр', 'мая', 'июн', 'июл', 'авг', 'сен', 'окт', 'ноя', 'дек'], ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], ['січ', 'лют', 'бер', 'кві', 'тра', 'чер', 'лип', 'сер', 'вер', 'жов', 'лис', 'гру']], fullMonth: [ ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'], ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], ['січня', 'лютого', 'березня', 'квітня', 'травня', 'червня', 'липня', 'серпня', 'вересня', 'жовтня', 'листопада', 'грудня']], week: [ ['Вск', 'Пнд', 'Втр', 'Срд', 'Чтв', 'Птн', 'Сбт'], ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], ['Нед', 'Пон', 'Вів', 'Сер', 'Чет', 'Птн', 'Сбт']], monthDict: { /* eslint-disable */ янв: 0, фев: 1, мар: 2, апр: 3, май: 4, мая: 4, июн: 5, июл: 6, авг: 7, сен: 8, окт: 9, ноя: 10, дек: 11, jan: 0, feb: 1, mar: 2, apr: 3, may: 4, jun: 5, jul: 6, aug: 7, sep: 8, oct: 9, nov: 10, dec: 11, січ: 0, лют: 1, бер: 2, кві: 3, тра: 4, чер: 5, лип: 6, сер: 7, вер: 8, жов: 9, лис: 10, гру: 11 /* eslint-enable */ }, // Spells: popups seSyntaxErr: [ 'синтаксическая ошибка в аргументе спелла: %s', 'syntax error in argument of spell: %s', 'синтаксична помилка в аргументі спеллу: %s'], seUnknown: [ 'неизвестный спелл: %s', 'unknown spell: %s', 'невідомий спелл: %s'], seMissOp: [ 'пропущен оператор', 'missing operator', 'пропущено оператор'], seMissArg: [ 'пропущен аргумент спелла: %s', 'missing argument of spell: %s', 'пропущено аргумент спеллу: %s'], seMissSpell: [ 'пропущен спелл', 'missing spell', 'пропущено спелл'], seErrRegex: [ 'синтаксическая ошибка в регулярном выражении: %s', 'syntax error in regular expression: %s', 'синтаксична помилка в регулярному виразі: %s'], seUnexpChar: [ 'неожиданный символ: %s', 'unexpected character: %s', 'неочікуваний символ: %s'], seMissClBkt: [ 'пропущена закрывающая скобка', "missing ')' in expression", 'пропущено закривну дужку'], seRepsInParens: [ 'спелл %s не должен располагаться в скобках', 'spell %s shouldnʼt be inside parentheses', 'спелл %s не може бути в дужках'], seOpInReps: [ 'недопустимо использовать оператор %s со спеллами #rep и #outrep', 'donʼt use operator %s with spells #rep & #outrep', 'неприпустимо використовувати оператор %s зі спеллами #rep и #outrep'], seRow: [ ' (строка ', ' (row ', ' (рядок '], seCol: [ ', столбец ', ', column ', ', стовпчик '], // Data editor editInTxt: [ 'Правка в текстовом формате', 'Edit in text format', 'Правка в текстовому форматі'], editor: { cfg: [ 'Редактирование настроек', 'Edit settings', 'Редагування налаштувань'], hidden: [ 'Редактирование скрытых тредов', 'Edit hidden threads', 'Редагування схованих тредів'], favor: [ 'Редактирование избранного', 'Edit favorites', 'Редагування вибраного'], css: [ 'Редактирование CSS', 'Edit CSS', 'Редагування CSS'] }, // Settings import/export/clearing fileImpExp: [ 'Импорт/экспорт настроек в файл', 'Import/export config to file', 'Імпорт/експорт налаштувань до файлу'], fileToData: [ 'Загрузить данные из файла', 'Load data from a file', 'Завантажити дані з файла'], dataToFile: [ 'Получить файл с данными', 'Get the file with data', 'Отримати файл з даними'], globalCfg: [ 'Глобальные настройки', 'Global config', 'Глобальні налаштування'], loadGlobal: [ 'и применить к этому домену', 'and apply to this domain', 'і застосувати до цього домену'], saveGlobal: [ 'текущие настройки как глобальные', 'current config as global', 'поточні налаштування як глобальні'], descrGlobal: [ 'Глобальные настройки применяются по умолчанию
при первом посещении других доменов', 'Global config is applied by default
on the first visit of other domains', 'Глобальні налаштування застосовуються по замовчуванню
під час першого відвідання інших доменів'], resetCfg: [ 'Сбросить в настройки по умолчанию', 'Reset config to defaults', 'Скинути в налаштування по замовчуванню'], resetData: [ 'Очистить выбранные данные', 'Reset selected data', 'Очистити обрані дані'], allDomains: [ 'для всех доменов', 'for all domains', 'для всіх доменів'], delEntries: [ 'Удалить выбранные записи', 'Delete selected entries', 'Видалити обрані записи'], saveChanges: [ 'Сохранить внесенные изменения', 'Save your changes', 'Зберегти внесені зміни'], hidPostThr: [ 'Скрытые посты и треды', 'Hidden posts and threads', 'Сховані пости та треди'], myPosts: [ 'Мои посты', 'My posts', 'Мої пости'], // Settings window: Common/Info tab checkNow: [ 'Проверить сейчас', 'Check now', 'Перевірити зараз'], updAvail: [ 'Доступно обновление Dollchan: %s', 'Dollchan update available: %s!', 'Доступне оновлення Dollchan: %s'], newCommitsAvail: [ 'Обнаружены новые исправления: %s', 'New fixes detected: %s', 'Виявлено нові виправлення: %s'], changeLog: [ 'Список изменений', 'List of changes', 'Список змін'], haveLatestStable: [ 'Ваша версия %s является последней из стабильных.', 'Your %s version is the latest from stable versions.', 'Ваша версія %s є останньою зі стабільних.'], haveLatestCommit: [ 'Ваша версия %s содержит последние исправления.', 'Your %s version contains all the latest fixes.', 'Ваша версія %s містить всі останні виправлення.'], thrViewed: [ 'Тредов посещено', 'Threads visited', 'Тредів відвідано'], thrCreated: [ 'Тредов создано', 'Threads created', 'Тредів створено'], thrHidden: [ 'Тредов скрыто', 'Threads hidden', 'Тредів сховано'], postsSent: [ 'Постов отправлено', 'Posts sent', 'Постів надіслано'], total: [ 'Всего', 'Total', 'Всього'], debug: [ 'Отладка', 'Debug', 'Відлагодження'], infoDebug: [ 'Информация для отладки', 'Information for debugging', 'Інформація для відлагодження'], // Favorites window: tooltips infoCount: [ 'Обновить счетчики постов', 'Refresh posts counters', 'Оновити лічильники постів'], infoPage: [ 'Проверить положение тредов (до 10-й страницы)', 'Check for threads position (up to 10th page)', 'Перевірити актуальність тредів (до 10 сторінки)'], clrDeleted: [ 'Очистить недоступные (404) треды', 'Clear inaccessible (404) threads', 'Очистити недоступні (404) треди'], oldPosts: [ 'Постов при последнем посещении', 'Posts at the last visit', 'Постів під час останнього відвідування'], newPosts: [ 'Количество новых постов', 'Number of new posts', 'Кількість нових постів'], myPostsRep: [ 'Ответов на ваши посты', 'Replies to your posts', 'Відповідей на ваші пости'], thrPage: [ 'Тред на @странице', 'Thread on @page', 'Тред на @сторінці'], goToThread: [ 'Перейти к треду', 'Go to the thread', 'Перейти до треду'], goToBoard: [ 'Перейти к доске', 'Go to the board', 'Перейти до дошки'], toggleEntries: [ 'Скрыть/раскрыть записи', 'Hide/expand entries', 'Сховати/розкрити записи'], // Video links: tooltips hideLnkList: [ 'Скрыть/Показать список ссылок', 'Hide/Unhide list of links', 'Сховати/показати перелік посилань'], expandVideo: [ 'Развернуть/Свернуть видео', 'Expand/Collapse video', 'Розгорнути/згорнути відео'], prevVideo: [ 'Предыдущее видео', 'Previous video', 'Попереднє відео'], nextVideo: [ 'Следующее видео', 'Next video', 'Наступне відео'], duration: [ 'Продолжительность: ', 'Duration: ', 'Тривалість: '], published: [ 'опубликовано: ', 'published: ', 'опубліковано: '], author: [ 'Автор: ', 'Author: ', 'Автор: '], views: [ 'просмотров: ', 'views: ', 'переглядів: '], // Postform file inputs: tooltips pasteImage: [ 'Ctrl+V - вставить картинку из буфера', 'Ctrl+V - paste an image from clipboard', 'Ctrl+V - додати зображення з буферу'], dropFileHere: [ 'Бросьте сюда файл(ы) или ссылку', 'Drop file(s) or link here', 'Киньте сюди файл(и) чи посилання'], youCanDrag: [ 'Можно перетаскивать картинки и ссылки на файлы\r\nпрямо со страницы или других сайтов', 'You can drag images and file links\r\ndirectly from the page or other sites', 'Можна перетягувати зображення чи посилання на файли\r\nбезпосередньо зі сторінки чи інших сайтів'], removeFile: [ 'Удалить файл', 'Remove file', 'Видалити файл'], renameFile: [ 'Переименовать файл', 'Rename file', 'Перейменувати файл'], spoilFile: [ 'Спойлер', 'Spoiler', 'Спойлер'], addManually: [ 'Ввести ссылку на файл вручную', 'Enter a link to the file manually', 'Ввести посилання на файл вручну'], enterTheLink: [ "Введите ссылку и нажмите '+'", "Enter the link and click '+'", "Введіть посилання та натисніть '+'"], helpAddFile: [ 'Встроить ogg/rar/zip/7z в картинку', 'Embed ogg/rar/zip/7z into the image', 'Вбудувати ogg/rar/zip/7z в зображення'], // Post images: tooltips expImgInline: [ '[Click] открыть в посте, [Ctrl+Click] по центру', '[Click] expand in post, [Ctrl+Click] by center', '[Click] розгорнути в пості, [Ctrl+Click] в центрі'], expImgFull: [ '[Click] открыть по центру, [Ctrl+Click] в посте', '[Click] expand by center, [Ctrl+Click] in post', '[Click] розгорнути в центрі, [Ctrl+Click] в пості'], nextImg: [ 'Следующая картинка', 'Next image', 'Наступне зображення'], prevImg: [ 'Предыдущая картинка', 'Previous image', 'Попереднє зображення'], rotateImg: [ 'Повернуть вправо', 'Rotate right', 'Повернути вправо'], autoPlayOn: [ 'Автоматически воспроизводить следующее видео', 'Automatically play the next video', 'Автоматично відтворювати наступне відео'], autoPlayOff: [ 'Отключить автовоспроизведение', 'Disable autoplay', 'Відключити автовідтворення'], downloadFile: [ 'Скачать содержащийся в картинке файл', 'Download embedded file from the image', 'Завантажити файл, що міститься в зображенні'], openOriginal: [ 'Открыть оригинал в новой вкладке', 'Open the original image in new tab', 'Відкрити оригінал в новій вкладці'], // Threads/images download: popups loadImage: [ 'Загружаются картинки', 'Loading images', 'Завантажуються зображення'], loadFile: [ 'Загружаются файлы', 'Loading files', 'Завантажуються файли'], cantLoad: [ 'Не могу загрузить', 'Canʼt load', 'Не можу завантажити'], willSavePview: [ 'Будет сохранено превью', 'Thumbnail will be saved', 'Буде збережено превʼю'], loadErrors: [ 'Во время загрузки произошли ошибки:', 'An error occurred during the loading:', 'Під час завантаження сталися помилки:'], // Ajax: popups succDeleted: [ 'Успешно удалено!', 'Succesfully deleted!', 'Успішно видалено!'], succReported: [ 'Жалоба успешно отправлена', 'Succesfully reported', 'Скарга успішно відправлена'], errDelete: [ 'Не могу удалить', 'Canʼt delete', 'Не можу видалити'], fileCorrupt: [ 'Файл повреждён', 'File is corrupt', 'Файл пошкоджено'], errCorruptData: [ 'Ошибка: сервер отправил повреждённые данные', 'Error: server sent corrupted data', 'Помилка: сервер надіслав пошкоджені дані'], noConnect: [ 'Ошибка подключения', 'Connection failed', 'Помилка зʼєднання'], thrNotFound: [ 'Тред недоступен', 'Thread is unavailable', 'Тред недоступний'], thrClosed: [ 'Тред закрыт', 'Thread is closed', 'Тред закрито'], thrArchived: [ 'Тред в архиве', 'Thread is archived', 'Тред заархівовано'], // Other warnings internalError: [ 'Внутренняя ошибка:\n', 'Internal error:\n', 'Внутрішня помилка:\n'], postNotFound: [ 'Пост не найден', 'Post not found', 'Пост не знайдено'], noHidThr: [ 'Нет скрытых тредов…', 'No hidden threads…', 'Немає схованих постів…'], noFavThr: [ 'Нет избранных тредов…', 'Favorites is empty…', 'Немає вибраних тредів…'], noVideoLinks: [ 'Нет ссылок на видео…', 'No video links…', 'Немає посилань на відео…'], invalidData: [ 'Некорректный формат данных', 'Incorrect data format', 'Некоректний формат даних'], noGlobalCfg: [ 'Глобальные настройки не найдены', 'Global config not found', 'Глобальні налаштування не знайдено'], subjHasTrip: [ 'Поле "Тема" содержит трипкод!', '"Subject" field contains a tripcode!', 'Поле "Тема" містить трипкод!'], errMsEdgeWebm: [ 'Загрузите скрипт для воспроизведения WebM (VP9/Opus)', 'Please load a script to play WebM (VP9/Opus)', 'Завантажте скрипт для відтворення WebM (VP9/Opus)'], errFormLoad: [ 'Не удаётся загрузить форму ответа', 'Can`t load the reply form', 'Не вдалося завантажити форму відповіді' ], // Single words second : ['с', 's', 'с'], sizeByte : [' Байт', ' Byte', ' Байт'], sizeKByte : [' КБ', ' KB', ' КБ'], sizeMByte : [' МБ', ' MB', ' МБ'], sizeGByte : [' ГБ', ' GB', ' ГБ'], name : ['Имя', 'Name', 'Імʼя'], subj : ['Тема', 'Subject', 'Тема'], mail : ['Почта', 'Email', 'Пошта'], video : ['Видео', 'Video', 'Відео'], cap : ['Капча', 'Captcha', 'Капча'], add : ['Добавить', 'Add', 'Додати'], apply : ['Применить', 'Apply', 'Застосувати'], cancel : ['Отмена', 'Cancel', 'Скасувати'], clear : ['Очистить', 'Clear', 'Очистити'], refresh : ['Обновить', 'Refresh', 'Оновити'], save : ['Сохранить', 'Save', 'Зберегти'], load : ['Загрузить', 'Load', 'Завантажити'], edit : ['Правка', 'Edit', 'Правка'], file : ['Файл', 'File', 'Файл'], global : ['Глобальные', 'Global', 'Глобальні'], reset : ['Сброс', 'Reset', 'Скинути'], remove : ['Удалить', 'Remove', 'Видалити'], change : ['Сменить', 'Change', 'Змінити'], page : ['Страница', 'Page', 'Сторінка'], reply : ['Ответ', 'Reply', 'Відповідь'], replies : ['Ответы:', 'Replies:', 'Відповіді:'], makeReply : ['Ответить', 'Reply', 'Відповісти'], error : ['Ошибка', 'Error', 'Помилка'], loading : ['Загрузка…', 'Loading…', 'Завантаження…'], sending : ['Отправка…', 'Sending…', 'Надсилання…'], checking : ['Проверка…', 'Checking…', 'Перевірка…'], updating : ['Обновление…', 'Updating…', 'Оновлення…'], deleting : ['Удаление…', 'Deleting…', 'Видалення…'], deleted : ['удалён', 'deleted', 'видалено'], hide : ['Скрыть: ', 'Hide: ', 'Сховати: '], // Miscellaneous hidePosts: [ 'Скрыть посты', 'Hide posts', 'Сховати пости'], showPosts: [ 'Показать посты', 'Show posts', 'Показати пости'], getNewPosts: [ 'Получить новые посты', 'Get new posts', 'Отримати нові пости'], makeThr: [ 'Создать тред', 'Create thread', 'Створити тред'], collapseThr: [ 'Свернуть тред', 'Collapse thread', 'Згорнути тред'], hiddenThr: [ 'Скрытый тред', 'Hidden thread', 'Схований тред'], hideForm: [ 'Скрыть форму', 'Hide form', 'Сховати форму'], noSage: [ 'Без сажи', 'No sage', 'Без сажі'], postsOmitted: [ 'Пропущено ответов: ', 'Posts omitted: ', 'Пропущено відповідей: '], newPost: [ ['новый пост', 'новых поста', 'новых постов'], ['new post', 'new posts', 'new posts'], ['новий пост', 'нових пости', 'нових постів']], youReplies: [ ['ответ Вам', 'ответа Вам', 'ответов Вам'], ['reply to You', 'replies to You', 'replies to You'], ['відповідь Вам', 'відповіді Вам', 'відповідей Вам']], latestPost: [ 'Последний пост', 'Latest post', 'Останній пост'], donateMsg: [ 'Спасибо за использование Dollchan Extension!
Вы можете поддержать проект пожертвованием', 'Thank You for using Dollchan Extension!
You can support the project by donating', 'Дякуємо за використання Dollchan Extension!
Ви можете підтримати проект пожертвою'], firefoxAddon: [ 'Firefox аддон доступен!', 'Firefox add-on is available!', 'Firefox аддон доступний!'] }; /* ==[ GlobalVars.js ]== */ const doc = deWindow.document; const emptyFn = Function.prototype; const aProto = Array.prototype; const gitWiki = 'https://github.com/SthephanShinkufag/Dollchan-Extension-Tools/wiki/'; const gitRaw = 'https://raw.githubusercontent.com/SthephanShinkufag/Dollchan-Extension-Tools/master/'; let $each, aib, Cfg, docBody, dTime, dummy, isExpImg, isPreImg, lang, locStorage, nav, needScroll, pByEl, pByNum, pr, sesStorage, updater; let quotetxt = ''; let visPosts = 2; let topWinZ = 10; /* ==[ Utils.js ]============================================================================================= UTILS =========================================================================================================== */ // DOM SEARCH const $Q = (path, root = docBody) => root.querySelectorAll(path); const $q = (path, root = docBody) => root.querySelector(path); const $id = id => doc.getElementById(id); function $parent(el, tagName) { do { el = el.parentElement; } while(el && el.tagName !== tagName); return el; } function $qParent(el, path) { do { el = el.parentElement; } while(el && !nav.matchesSelector(el, path)); return el; } // DOM MODIFIERS function $before(el, node) { el.parentNode.insertBefore(node, el); } function $after(el, node) { const nextEl = el.nextSibling; if(nextEl) { el.parentNode.insertBefore(node, nextEl); } else { el.parentNode.appendChild(node); } } function $bBegin(sibling, html) { sibling.insertAdjacentHTML('beforebegin', html); return sibling.previousSibling; } function $aBegin(parent, html) { parent.insertAdjacentHTML('afterbegin', html); return parent.firstChild; } function $bEnd(parent, html) { parent.insertAdjacentHTML('beforeend', html); return parent.lastChild; } function $aEnd(sibling, html) { sibling.insertAdjacentHTML('afterend', html); return sibling.nextSibling; } function $replace(origEl, newEl) { if(typeof newEl === 'string') { origEl.insertAdjacentHTML('afterend', newEl); origEl.remove(); } else { origEl.parentNode.replaceChild(newEl, origEl); } } function $del(el) { if(el) { el.remove(); } } function $delAll(path, root = docBody) { $each(root.querySelectorAll(path, root), el => el.remove()); } function $add(html) { dummy.innerHTML = html; return dummy.firstElementChild; } const $txt = el => doc.createTextNode(el); // TODO: Get rid of this function and paste buttons in html function $btn(val, ttl, fn, className = 'de-button') { const el = doc.createElement('input'); el.type = 'button'; el.className = className; el.value = val; el.title = ttl; el.addEventListener('click', fn); return el; } function $script(text) { // We can't insert scripts directly as html const el = doc.createElement('script'); el.type = 'text/javascript'; el.textContent = text; doc.head.appendChild(el).remove(); } function $css(text) { if(nav.isSafari && !('flex' in docBody.style)) { text = text.replace(/(transform|transition|flex|align-items)/g, ' -webkit-$1'); } return $bEnd(doc.head, ``); } function $DOM(html) { const myDoc = doc.implementation.createHTMLDocument(''); myDoc.documentElement.innerHTML = html; return myDoc; } // CSS UTILS function $toggle(el, needToShow = el.style.display) { if(needToShow) { el.style.removeProperty('display'); } else { el.style.display = 'none'; } } function $show(el) { el.style.removeProperty('display'); } function $hide(el) { el.style.display = 'none'; } function $animate(el, cName, isRemove = false) { el.addEventListener('animationend', function aEvent() { el.removeEventListener('animationend', aEvent); if(isRemove) { el.remove(); } else { el.classList.remove(cName); } }); el.classList.add(cName); } // Checks the validity of the user inputted color function checkCSSColor(color) { if(!color || color === 'inherit' || color === 'currentColor') { return false; } if(color === 'transparent') { return true; } const image = doc.createElement('img'); image.style.color = 'rgb(0, 0, 0)'; image.style.color = color; if(image.style.color !== 'rgb(0, 0, 0)') { return true; } image.style.color = 'rgb(255, 255, 255)'; image.style.color = color; return image.style.color !== 'rgb(255, 255, 255)'; } // OTHER UTILS const pad2 = i => (i < 10 ? '0' : '') + i; const arrTags = (arr, start, end) => start + arr.join(end + start) + end; const fixBrd = b => `/${ b }${ b ? '/' : '' }`; const getAbsLink = url => ( url[1] === '/' ? aib.prot : url[0] === '/' ? aib.prot + '//' + aib.host : '') + url; // Prepares a string to be used as a new RegExp argument const quoteReg = str => (str + '').replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); // Converts a string to a regular expression function toRegExp(str, noG) { const l = str.lastIndexOf('/'); const flags = str.substr(l + 1); return new RegExp(str.substr(1, l - 1), noG ? flags.replace('g', '') : flags); } function toggleAttr(el, name, value, isAdd) { if(isAdd) { el.setAttribute(name, value); } else { el.removeAttribute(name); } } function $pd(e) { e.preventDefault(); } function $isEmpty(obj) { for(const i in obj) { if(obj.hasOwnProperty(i)) { return false; } } return true; } function insertText(el, txt) { const scrtop = el.scrollTop; const start = el.selectionStart; el.value = el.value.substr(0, start) + txt + el.value.substr(el.selectionEnd); el.setSelectionRange(start + txt.length, start + txt.length); el.focus(); el.scrollTop = scrtop; } // XXX: SVG events hack for Opera Presto function fixEventEl(el) { if(el && nav.isPresto) { const svg = el.correspondingUseElement; if(svg) { el = svg.ownerSVGElement; } } return el; } // Allows to record the duration of code execution const Logger = { finish() { this._finished = true; this._marks.push(['LoggerFinish', Date.now()]); }, getLogData(isFull) { const marks = this._marks; const timeLog = []; let duration, i = 1; let lastExtra = 0; for(let len = marks.length - 1; i < len; ++i) { duration = marks[i][1] - marks[i - 1][1] + lastExtra; if(isFull || duration > 1) { lastExtra = 0; timeLog.push([marks[i][0], duration]); } else { // Ignore logs equal to 0ms lastExtra = duration; } } timeLog.push([Lng.total[lang], marks[i][1] - marks[0][1]]); return timeLog; }, initLogger() { this._marks.push(['LoggerInit', Date.now()]); }, log(text) { if(!this._finished) { this._marks.push([text, Date.now()]); } }, _finished : false, _marks : [] }; // Some async operations should be cancelable, to ignore all the chaining callbacks of promises. // Cancellation is supposed to flow through a graph of promise dependencies. When a promise is cancelled, it // will propagate to the farthest pending promises and reject them with the cancel reason CancelError. function CancelError() {} class CancelablePromise { constructor(resolver, cancelFn) { this._promise = new Promise((resolve, reject) => { this._reject = reject; resolver(value => { resolve(value); this._isResolved = true; }, reason => { reject(reason); this._isResolved = true; }); }); this._cancelFn = cancelFn; this._isResolved = false; } static reject(val) { return new CancelablePromise((res, rej) => rej(val)); } static resolve(val) { return new CancelablePromise(res => res(val)); } cancelPromise() { this._reject(new CancelError()); if(!this._isResolved && this._cancelFn) { this._cancelFn(); } } catch(eb) { return this.then(void 0, eb); } then(cb, eb) { const children = []; const wrap = fn => (...args) => { const child = fn(...args); if(child instanceof CancelablePromise) { children.push(child); } return child; }; return new CancelablePromise( resolve => resolve(this._promise.then(cb && wrap(cb), eb && wrap(eb))), () => { for(const child of children) { child.cancelPromise(); } this.cancelPromise(); }); } } class Maybe { constructor(Ctor/* , ...args */) { this._ctor = Ctor; // this._args = args; this.hasValue = false; } get value() { const Ctor = this._ctor; this.hasValue = !!Ctor; const value = Ctor ? new Ctor(/* ...this._args */) : null; Object.defineProperty(this, 'value', { value }); return value; } } class TemporaryContent { constructor(key) { const oClass = /* new.target */this.constructor; // https://github.com/babel/babel/issues/1088 if(oClass.purgeTO) { clearTimeout(oClass.purgeTO); } oClass.purgeTO = setTimeout(() => oClass.purge(), oClass.purgeSecs); if(oClass.data) { const rv = oClass.data.get(key); if(rv) { return rv; } } else { oClass.data = new Map(); } oClass.data.set(key, this); } static get(key) { return this.data ? this.data.get(key) : null; } static has(key) { return this.data ? this.data.has(key) : false; } static purge() { if(this.purgeTO) { clearTimeout(this.purgeTO); this.purgeTO = null; } this.data = null; } static removeTempData(key) { if(this.data) { this.data.delete(key); } } } TemporaryContent.purgeSecs = 6e4; class TasksPool { constructor(tasksCount, taskFunc, endFn) { this.array = []; this.running = 0; this.num = 1; this.func = taskFunc; this.endFn = endFn; this.max = tasksCount; this.completed = this.paused = this.stopped = false; } completeTasks() { if(!this.stopped) { if(this.array.length === 0 && this.running === 0) { this.endFn(); } else { this.completed = true; } } } pauseTasks() { this.paused = true; } runTask(data) { if(!this.stopped) { if(this.paused || this.running === this.max) { this.array.push(data); } else { this._runTask(data); this.running++; } } } stopTasks() { this.stopped = true; this.endFn(); } _continueTasks() { if(!this.stopped) { this.paused = false; if(this.array.length === 0) { if(this.completed) { this.endFn(); } return; } while(this.array.length !== 0 && this.running !== this.max) { this._runTask(this.array.shift()); this.running++; } } } _endTask() { if(!this.stopped) { if(!this.paused && this.array.length !== 0) { this._runTask(this.array.shift()); return; } this.running--; if(!this.paused && this.completed && this.running === 0) { this.endFn(); } } } _runTask(data) { this.func(this.num++, data).then(() => this._endTask(), err => { if(err instanceof TasksPool.PauseError) { this.pauseTasks(); if(err.duration !== -1) { setTimeout(() => this._continueTasks(), err.duration); } } else { this._endTask(); throw err; } }); } } TasksPool.PauseError = function(duration) { this.name = 'TasksPool.PauseError'; this.duration = duration; }; class WorkerPool { constructor(mReqs, wrkFn, errFn) { if(!nav.hasWorker) { this.runWorker = (data, transferObjs, fn) => fn(wrkFn(data)); return; } const url = deWindow.URL.createObjectURL(new Blob([`self.onmessage = function(e) { var info = (${ String(wrkFn) })(e.data); if(info.data) { self.postMessage(info, [info.data]); } else { self.postMessage(info); } }`], { type: 'text/javascript' })); this._pool = new TasksPool(mReqs, (num, data) => this._createWorker(num, data), null); this._freeWorkers = []; this._url = url; this._errFn = errFn; while(mReqs--) { this._freeWorkers.push(new Worker(url)); } } clearWorkers() { deWindow.URL.revokeObjectURL(this._url); this._freeWorkers.forEach(w => w.terminate()); this._freeWorkers = []; } runWorker(data, transferObjs, fn) { this._pool.runTask([data, transferObjs, fn]); } _createWorker(num, data) { return new Promise(resolve => { const worker = this._freeWorkers.pop(); const [sendData, transferObjs, fn] = data; worker.onmessage = e => { fn(e.data); this._freeWorkers.push(worker); resolve(); }; worker.onerror = err => { resolve(); this._freeWorkers.push(worker); this._errFn(err); }; worker.postMessage(sendData, transferObjs); }); } } class TarBuilder { constructor() { this._data = []; } addFile(filepath, input) { let i, checksum = 0; const fileSize = input.length; const header = new Uint8Array(512); const nameLen = Math.min(filepath.length, 100); for(i = 0; i < nameLen; ++i) { header[i] = filepath.charCodeAt(i) & 0xFF; } TarBuilder._padSet(header, 100, '100777', 8); // fileMode TarBuilder._padSet(header, 108, '0', 8); // uid TarBuilder._padSet(header, 116, '0', 8); // gid TarBuilder._padSet(header, 124, fileSize.toString(8), 13); // fileSize TarBuilder._padSet(header, 136, Math.floor(Date.now() / 1e3).toString(8), 12); // mtime TarBuilder._padSet(header, 148, ' ', 8); // checksum // type ('0') header[156] = 0x30; for(i = 0; i < 157; ++i) { checksum += header[i]; } // checksum TarBuilder._padSet(header, 148, checksum.toString(8), 8); this._data.push(header, input); if((i = Math.ceil(fileSize / 512) * 512 - fileSize) !== 0) { this._data.push(new Uint8Array(i)); } } addString(filepath, str) { const sDat = unescape(encodeURIComponent(str)); this.addFile(filepath, new Uint8Array(sDat.length).map((val, i) => sDat.charCodeAt(i) & 0xFF)); } get() { this._data.push(new Uint8Array(1024)); return new Blob(this._data, { type: 'application/x-tar' }); } static _padSet(data, offset, num, len) { let i = 0; const nLen = num.length; len -= 2; while(nLen < len) { data[offset++] = 0x20; // ' ' len--; } while(i < nLen) { data[offset++] = num.charCodeAt(i++); } data[offset] = 0x20; // ' ' } } class WebmParser { constructor(data) { let offset = 0; const dv = nav.getUnsafeDataView(data); const len = dv.byteLength; const el = new WebmParser.Element(dv, len, 0); const voids = []; const EBMLId = 0x1A45DFA3; const segmentId = 0x18538067; const voidId = 0xEC; this.voidId = voidId; error: do { if(el.error || el.id !== EBMLId) { break; } this.EBML = el; offset += el.headSize + el.size; while(true) { const el = new WebmParser.Element(dv, len, offset); if(el.error) { break error; } if(el.id === segmentId) { this.segment = el; break; // Ignore everything after first segment } else if(el.id === voidId) { voids.push(el); } else { break error; } offset += el.headSize + el.size; } this.voids = voids; this.data = data; this.length = len; this.rv = [null]; this.error = false; return; } while(false); this.error = true; } addWebmData(data) { if(this.error || !data) { return this; } const size = typeof data === 'string' ? data.length : data.byteLength; if(size > 127) { this.error = true; return; } this.rv.push(new Uint8Array([this.voidId, 0x80 | size]), data); return this; } getWebmData() { if(this.error) { return null; } this.rv[0] = nav.getUnsafeUint8Array(this.data, 0, this.segment.endOffset); return this.rv; } } WebmParser.Element = function(elData, dataLength, offset) { this.error = false; this.id = 0; if(offset + 4 >= dataLength) { return; } let num = elData.getUint32(offset); let leadZeroes = Math.clz32(num); if(leadZeroes > 3) { this.error = true; return; } offset += leadZeroes + 1; if(offset >= dataLength) { this.error = true; return; } this.id = num >>> (8 * (3 - leadZeroes)); this.headSize = leadZeroes + 1; num = elData.getUint32(offset); leadZeroes = Math.clz32(num); let size = num & (0xFFFFFFFF >>> (leadZeroes + 1)); if(leadZeroes > 3) { const shift = 8 * (7 - leadZeroes); if(size >>> shift !== 0 || offset + 4 > dataLength) { this.error = true; return; // We cannot handle webm-files with size greater than 4Gb :( } size = (size << (32 - shift)) | (elData.getUint32(offset + 4) >>> shift); } else { size >>>= 8 * (3 - leadZeroes); } this.headSize += leadZeroes + 1; offset += leadZeroes + 1; if(offset + size > dataLength) { this.error = true; return; } this.data = elData; this.offset = offset; this.endOffset = offset + size; this.size = size; }; function getErrorMessage(err) { if(err instanceof AjaxError) { return err.toString(); } if(typeof err === 'string') { return err; } const { stack, name, message } = err; return Lng.internalError[lang] + ( !stack ? `${ name }: ${ message }` : nav.isWebkit ? stack : `${ name }: ${ message }\n${ !nav.isFirefox ? stack : stack.replace( /^([^@]*).*\/(.+)$/gm, (str, fName, line) => ` at ${ fName ? `${ fName } (${ line })` : line }` ) }` ); } async function readFile(file, asText = false) { return new Promise(resolve => { const fr = new FileReader(); // XXX: firefox hack to prevent 'XrayWrapper denied access to property "then"' errors fr.onload = e => resolve({ data: e.target.result }); if(asText) { fr.readAsText(file); } else { fr.readAsArrayBuffer(file); } }); } const prettifySize = val => val > 512 * 1024 * 1024 ? (val / (1024 ** 3)).toFixed(2) + Lng.sizeGByte[lang] : val > 512 * 1024 ? (val / (1024 ** 2)).toFixed(2) + Lng.sizeMByte[lang] : val > 512 ? (val / 1024).toFixed(2) + Lng.sizeKByte[lang] : val.toFixed(2) + Lng.sizeByte[lang]; function getFileType(url) { const dotIdx = url.lastIndexOf('.') + 1; switch(dotIdx && url.substr(dotIdx).toLowerCase()) { case 'gif': return 'image/gif'; case 'jpeg': case 'jpg': return 'image/jpeg'; case 'mp4': return 'video/mp4'; case 'ogv': return 'video/ogv'; case 'png': return 'image/png'; case 'webm': return 'video/webm'; case 'webp': return 'image/webp'; default: return ''; } } function downloadBlob(blob, name) { const url = nav.isMsEdge ? navigator.msSaveOrOpenBlob(blob, name) : deWindow.URL.createObjectURL(blob); const link = $bEnd(docBody, ``); link.click(); setTimeout(() => { deWindow.URL.revokeObjectURL(url); link.remove(); }, 2e5); } /* ==[ Storage.js ]=========================================================================================== STORAGE =========================================================================================================== */ // Gets data from the global storage async function getStored(id) { if(nav.hasNewGM) { const value = await GM.getValue(id); return value; } else if(nav.hasOldGM) { return GM_getValue(id); } else if(nav.hasWebStorage) { // Read storage.local first. If it not existed then read storage.sync const value = await new Promise(resolve => chrome.storage.local.get(id, obj => { if(Object.keys(obj).length) { resolve(obj[id]); } else { chrome.storage.sync.get(id, obj => resolve(obj[id])); } })); return value; } else if(nav.hasPrestoStorage) { return prestoStorage.getItem(id); } return locStorage[id]; } // Saves data into the global storage // FIXME: make async? function setStored(id, value) { if(nav.hasNewGM) { return GM.setValue(id, value); } else if(nav.hasOldGM) { GM_setValue(id, value); } else if(nav.hasWebStorage) { const obj = {}; obj[id] = value; chrome.storage.sync.set(obj, () => { if(chrome.runtime.lastError) { // Store into storage.local if the storage.sync limit is exceeded chrome.storage.local.set(obj, emptyFn); chrome.storage.sync.remove(id, emptyFn); } else { chrome.storage.local.remove(id, emptyFn); } }); } else if(nav.hasPrestoStorage) { prestoStorage.setItem(id, value); } else { locStorage[id] = value; } } // Removes data from the global storage // FIXME: make async? function delStored(id) { if(nav.hasNewGM) { return GM.deleteValue(id); } else if(nav.hasOldGM) { GM_deleteValue(id); } else if(nav.hasWebStorage) { chrome.storage.sync.remove(id, emptyFn); } else if(nav.hasPrestoStorage) { prestoStorage.removeItem(id); } else { locStorage.removeItem(id); } } // Receives and parses JSON data into an object async function getStoredObj(id) { return JSON.parse(await getStored(id) || '{}') || {}; } // Replaces the domain config with an object. Removes the domain config, if there is no object. function saveCfgObj(dm, obj) { getStoredObj('DESU_Config').then(val => { if(obj) { val[dm] = obj; } else { delete val[dm]; } setStored('DESU_Config', JSON.stringify(val)); }); } // Saves the value for a particular config option function saveCfg(id, val) { if(Cfg[id] !== val) { Cfg[id] = val; saveCfgObj(aib.dm, Cfg); } } // Toggles a particular config option (1|0) function toggleCfg(id) { saveCfg(id, +!Cfg[id]); } function readData() { return Promise.all([readFavorites(), readCfg()]); } // Config initialization, checking for Dollchan update. async function readCfg() { let obj; const val = await getStoredObj('DESU_Config'); if(!(aib.dm in val) || $isEmpty(obj = val[aib.dm])) { const isGlobal = nav.hasGlobalStorage && !!val.global; obj = isGlobal ? val.global : {}; if(isGlobal) { delete obj.correctTime; delete obj.captchaLang; } } defaultCfg.captchaLang = aib.capLang; defaultCfg.language = +!String(navigator.language).toLowerCase().startsWith('ru'); Cfg = Object.assign(Object.create(defaultCfg), obj); if(!Cfg.timeOffset) { Cfg.timeOffset = '+0'; } if(!Cfg.timePattern) { Cfg.timePattern = aib.timePattern; } if(aib.prot !== 'http:') { // Vocaroo doesn't support https Cfg.addVocaroo = 0; } if(aib.dobrochan && !Cfg.useDobrAPI) { aib.JsonBuilder = null; } if(!('FormData' in deWindow)) { Cfg.ajaxPosting = 0; } if(!Cfg.ajaxPosting) { Cfg.fileInputs = 0; } if(!('Notification' in deWindow)) { Cfg.desktNotif = 0; } if(nav.isPresto) { Cfg.preLoadImgs = 0; Cfg.findImgFile = 0; if(!nav.hasOldGM) { Cfg.updDollchan = 0; } Cfg.fileInputs = 0; } if(nav.scriptHandler === 'WebExtension') { Cfg.updDollchan = 0; } if(Cfg.updThrDelay < 10) { Cfg.updThrDelay = 10; } if(!Cfg.addSageBtn || !Cfg.saveSage) { Cfg.sageReply = 0; } if(!Cfg.passwValue) { Cfg.passwValue = Math.round(Math.random() * 1e12).toString(32); } if(!Cfg.stats) { Cfg.stats = { view: 0, op: 0, reply: 0 }; } if(Cfg.addYouTube !== undefined) { Cfg.embedYTube = Cfg.addYouTube === 0 ? 0 : Cfg.addYouTube === 1 ? 2 : 1; delete Cfg.addYouTube; } lang = Cfg.language; if(val.commit !== commit && !localData) { const font = ' style="font: 13px monospace; color: green;"'; const donateMsg = Lng.donateMsg[lang] + ':
' + '' + '
Yandex.Money
' + `410012122418236
WebMoney
` + `WMZ – Z100197626370
` + `WMR – R266614957054
` + `WMU – U142375546253
` + `Bitcoin
P2PKH – 15xEo7BVQ3zjztJqKSRVhTq3tt3rNSHFpC
` + `P2SH – 3AhNPPpvtxQoFCLXk5e9Hzh6Ex9h7EoNzq
` + (nav.firefoxVer >= 56 && nav.scriptHandler !== 'WebExtension' ? `

New: ' + Lng.firefoxAddon[lang] : ''); const popupFn = () => $popup('donate', donateMsg); if(doc.readyState === 'loading') { doc.addEventListener('DOMContentLoaded', () => setTimeout(popupFn, 1e3)); } else { setTimeout(popupFn, 1e3); } val.commit = commit; } setStored('DESU_Config', JSON.stringify(val)); if(Cfg.updDollchan && !localData) { checkForUpdates(false, val.lastUpd).then(html => { if(doc.readyState === 'loading') { doc.addEventListener('DOMContentLoaded', () => $popup('updavail', html)); } else { $popup('updavail', html); } }, emptyFn); } } // Initialize of hidden and favorites. Run spells. function readPostsData(firstPost, favObj) { let sVis = null; try { // Get hidden posts and threads that cached in current session const str = aib.t ? sesStorage['de-hidden-' + aib.b + aib.t] : null; if(str) { const json = JSON.parse(str); if(json.hash === (Cfg.hideBySpell ? Spells.hash : 0) && pByNum.has(json.lastNum) && pByNum.get(json.lastNum).count === json.lastCount ) { sVis = json.data && json.data[0] instanceof Array ? json.data : null; } } } catch(err) { sesStorage['de-hidden-' + aib.b + aib.t] = null; } if(!firstPost) { return; } let updateFav = null; const favBrd = (aib.host in favObj) && (aib.b in favObj[aib.host]) ? favObj[aib.host][aib.b] : {}; const spellsHide = Cfg.hideBySpell; const maybeSpells = new Maybe(SpellsRunner); // Search existed posts in stored data for(let post = firstPost; post; post = post.next) { const { num } = post; // Mark favorite threads, update favorites data if(post.isOp && (num in favBrd)) { const f = favBrd[num]; const { thr } = post; post.toggleFavBtn(true); post.thr.isFav = true; if(aib.t) { f.cnt = thr.pcount; f.new = f.you = 0; if(Cfg.markNewPosts && f.last) { let lastPost = pByNum.get(+f.last.match(/\d+/)); if(lastPost) { // Mark all new posts after last viewed post while((lastPost = lastPost.next)) { Post.addMark(lastPost.el, true); } } } f.last = aib.anchor + thr.last.num; } else { f.new = thr.pcount - f.cnt; } updateFav = [aib.host, aib.b, aib.t, [thr.pcount, thr.last.num], 'update']; } if(HiddenPosts.has(num)) { HiddenPosts.hideHidden(post, num); continue; } let hideData; if(post.isOp) { if(HiddenThreads.has(num)) { hideData = [true, null]; } else if(spellsHide) { hideData = sVis && sVis[post.count]; } } else if(spellsHide) { hideData = sVis && sVis[post.count]; } else { continue; } if(!hideData) { maybeSpells.value.runSpells(post); // Apply spells if posts not hidden } else if(hideData[0]) { if(post.isHidden) { post.spellHidden = true; } else { post.spellHide(hideData[1]); } } } if(maybeSpells.hasValue) { maybeSpells.value.endSpells(); } if(aib.t && Cfg.panelCounter === 2) { $id('de-panel-info-pcount').textContent = Thread.first.pcount - Thread.first.hidCounter; } if(updateFav) { saveFavorites(favObj); sendStorageEvent('__de-favorites', updateFav); } // After following a link from Favorites, we need to open Favorites again. const hasFavWinKey = sesStorage['de-fav-win'] === '1'; if(hasFavWinKey || Cfg.favWinOn) { toggleWindow('fav', !!$q('#de-win-fav.de-win-active'), null, true); if(hasFavWinKey) { sesStorage.removeItem('de-fav-win'); } } let data = sesStorage['de-fav-newthr']; if(data) { // Detecting the created new thread and adding it to Favorites. data = JSON.parse(data); const isTimeOut = !data.num && (Date.now() - data.date > 2e4); if(data.num === firstPost.num || !firstPost.next && !isTimeOut) { firstPost.thr.toggleFavState(true); sesStorage.removeItem('de-fav-newthr'); } else if(isTimeOut) { sesStorage.removeItem('de-fav-newthr'); } } if(Cfg.nextPageThr && DelForm.first === DelForm.last) { const hidThrEls = $Q('.de-thr-hid', firstPost.thr.form.el); const hidThrLen = hidThrEls.length; if(hidThrLen) { Pages.addPage(hidThrLen); } } } function readFavorites() { return getStoredObj('DESU_Favorites'); } function saveFavorites(data) { setStored('DESU_Favorites', JSON.stringify(data)); } // Get posts that were read by posts previews function readViewedPosts() { if(!Cfg.markViewed) { return; } const data = sesStorage['de-viewed']; if(data) { data.split(',').forEach(pNum => { const post = pByNum.get(+pNum); if(post) { post.el.classList.add('de-viewed'); post.isViewed = true; } }); } } // HIDDEN AND MY POSTS STORAGE class PostsStorage { constructor() { this.storageName = ''; this.__cachedTime = null; this._cachedStorage = null; this._cacheTO = null; } get(num) { const storage = this._readStorage()[aib.b]; if(storage) { const val = storage[num]; return val ? val[2] : null; } return null; } has(num) { const storage = this._readStorage()[aib.b]; return storage ? storage.hasOwnProperty(num) : false; } purge() { this._cacheTO = this.__cachedTime = this._cachedStorage = null; } removeStorage(num, board = aib.b) { const storage = this._readStorage(); const bStorage = storage[board]; if(bStorage && bStorage.hasOwnProperty(num)) { delete bStorage[num]; if($isEmpty(bStorage)) { delete storage[board]; } this._saveStorage(); } } set(num, thrNum, data = true) { const storage = this._readStorage(); if(storage && storage.$count > 5e3) { const minDate = Date.now() - 5 * 24 * 3600 * 1e3; for(const b in storage) { if(storage.hasOwnProperty(b)) { const data = storage[b]; for(const key in data) { if(data.hasOwnProperty(key) && data[key][0] < minDate) { delete data[key]; } } } } } (storage[aib.b] || (storage[aib.b] = {}))[num] = [this._cachedTime, thrNum, data]; this._saveStorage(); } static _migrateOld(newName, oldName) { if(locStorage.hasOwnProperty(oldName)) { locStorage[newName] = locStorage[oldName]; locStorage.removeItem(oldName); } } get _cachedTime() { return this.__cachedTime || (this.__cachedTime = Date.now()); } _readStorage() { if(this._cachedStorage) { return this._cachedStorage; } const data = locStorage[this.storageName]; if(data) { try { return (this._cachedStorage = JSON.parse(data)); } catch(err) {} } return (this._cachedStorage = {}); } _saveStorage() { if(this._cacheTO === null) { this._cacheTO = setTimeout(() => { if(this._cachedStorage) { locStorage[this.storageName] = JSON.stringify(this._cachedStorage); } this.purge(); }, 0); } } } const HiddenPosts = new class HiddenPostsClass extends PostsStorage { constructor() { super(); this.storageName = 'de-posts'; } hideHidden(post, num) { const uHideData = HiddenPosts.get(num); if(!uHideData && post.isOp && HiddenThreads.has(num)) { post.setUserVisib(true); } else { post.setUserVisib(!!uHideData, false); } } _readStorage() { PostsStorage._migrateOld(this.storageName, 'de-threads-new'); // Old storage has wrong name return super._readStorage(); } }(); const HiddenThreads = new class HiddenThreadsClass extends PostsStorage { constructor() { super(); this.storageName = 'de-threads'; } getCount() { const storage = this._readStorage(); let rv = 0; for(const b in storage) { rv += Object.keys(storage[b]).length; } return rv; } getRawData() { return this._readStorage(); } saveRawData(data) { locStorage[this.storageName] = JSON.stringify(data); this.purge(); } _readStorage() { PostsStorage._migrateOld(this.storageName, ''); // Old storage has wrong name return super._readStorage(); } }(); const MyPosts = new class MyPostsClass extends PostsStorage { constructor() { super(); this.storageName = 'de-myposts'; this._cachedData = null; } has(num) { return this._cachedData.has(num); } purge() { super.purge(); this._cachedData = null; this._readStorage(); } readStorage() { this._readStorage(); } set(num, thrNum) { super.set(num, thrNum); this._cachedData.add(+num); sendStorageEvent('__de-mypost', 1); } _readStorage() { if(this._cachedData && this._cachedStorage) { return this._cachedStorage; } PostsStorage._migrateOld(this.storageName, 'de-myposts-new'); const rv = super._readStorage(); this._cachedData = rv[aib.b] ? new Set(Object.keys(rv[aib.b]).map(val => +val)) : new Set(); return rv; } }(); function sendStorageEvent(name, value) { locStorage[name] = typeof value === 'string' ? value : JSON.stringify(value); locStorage.removeItem(name); } function initStorageEvent() { doc.defaultView.addEventListener('storage', e => { let data, temp, val = e.newValue; if(!val) { return; } switch(e.key) { case '__de-favorites': { try { data = JSON.parse(val); } catch(err) { return; } updateFavWindow(...data); return; } case '__de-mypost': MyPosts.purge(); return; case '__de-webmvolume': val = +val || 0; Cfg.webmVolume = val; temp = $q('input[info="webmVolume"]'); if(temp) { temp.value = val; } return; case '__de-post': (() => { try { data = JSON.parse(val); } catch(err) { return; } HiddenThreads.purge(); HiddenPosts.purge(); if(data.brd === aib.b) { let post = pByNum.get(data.num); if(post && (post.isHidden ^ data.hide)) { post.setUserVisib(data.hide, false); } else if((post = pByNum.get(data.thrNum))) { post.thr.userTouched.set(data.num, data.hide); } } toggleWindow('hid', true); })(); return; case 'de-threads': HiddenThreads.purge(); Thread.first.updateHidden(HiddenThreads.getRawData()[aib.b]); toggleWindow('hid', true); return; case '__de-spells': (() => { try { data = JSON.parse(val); } catch(err) { return; } Cfg.hideBySpell = +data.hide; temp = $q('input[info="hideBySpell"]'); if(temp) { temp.checked = data.hide; } $hide(docBody); if(data.data) { Spells.setSpells(data.data, false); Cfg.spells = JSON.stringify(data.data); temp = $id('de-spell-txt'); if(temp) { temp.value = Spells.list; } } else { SpellsRunner.unhideAll(); Spells.disableSpells(); temp = $id('de-spell-txt'); if(temp) { temp.value = ''; } } $show(docBody); })(); } }); } /* ==[ Panel.js ]============================================================================================= MAIN PANEL =========================================================================================================== */ const Panel = Object.create({ isVidEnabled: false, initPanel(formEl) { const imgLen = $Q(aib.qPostImg, formEl).length; const isThr = aib.t; (pr && pr.pArea[0] || formEl).insertAdjacentHTML('beforebegin', `
${ Cfg.disabled ? '' : '

' }
`); this._el = $id('de-panel'); this._el.addEventListener('click', this, true); this._el.addEventListener('mouseover', this); this._el.addEventListener('mouseout', this); this._buttons = $id('de-panel-buttons'); this.isNew = true; }, removeMain() { this._el.removeEventListener('click', this, true); this._el.removeEventListener('mouseover', this); this._el.removeEventListener('mouseout', this); delete this._pcountEl; delete this._icountEl; delete this._acountEl; $id('de-main').remove(); }, handleEvent(e) { if('isTrusted' in e && !e.isTrusted) { return; } let el = fixEventEl(e.target); el = el.tagName.toLowerCase() === 'svg' ? el.parentNode : el; switch(e.type) { case 'click': switch(el.id) { case 'de-panel-logo': if(Cfg.expandPanel && !$q('.de-win-active')) { $hide(this._buttons); } toggleCfg('expandPanel'); return; case 'de-panel-cfg': toggleWindow('cfg', false); break; case 'de-panel-hid': toggleWindow('hid', false); break; case 'de-panel-fav': toggleWindow('fav', false); break; case 'de-panel-vid': this.isVidEnabled = !this.isVidEnabled; toggleWindow('vid', false); break; case 'de-panel-refresh': deWindow.location.reload(); break; case 'de-panel-goup': scrollTo(0, 0); break; case 'de-panel-godown': scrollTo(0, docBody.scrollHeight || docBody.offsetHeight); break; case 'de-panel-expimg': el.classList.toggle('de-panel-button-active'); isExpImg = !isExpImg; $del($q('.de-fullimg-center')); for(let post = Thread.first.op; post; post = post.next) { post.toggleImages(isExpImg, false); } break; case 'de-panel-preimg': el.classList.toggle('de-panel-button-active'); isPreImg = !isPreImg; if(!e.ctrlKey) { for(const { el } of DelForm) { ContentLoader.preloadImages(el); } } break; case 'de-panel-maskimg': el.classList.toggle('de-panel-button-active'); toggleCfg('maskImgs'); updateCSS(); break; case 'de-panel-upd-on': case 'de-panel-upd-warn': case 'de-panel-upd-off': updater.toggle(); break; case 'de-panel-audio-on': case 'de-panel-audio-off': if(updater.toggleAudio(0)) { updater.enableUpdater(); el.id = 'de-panel-audio-on'; } else { el.id = 'de-panel-audio-off'; } $del($q('.de-menu')); break; case 'de-panel-savethr': break; case 'de-panel-enable': toggleCfg('disabled'); deWindow.location.reload(); break; default: return; } $pd(e); return; case 'mouseover': if(!Cfg.expandPanel) { clearTimeout(this._hideTO); $show(this._buttons); } switch(el.id) { case 'de-panel-cfg': KeyEditListener.setTitle(el, 10); break; case 'de-panel-hid': KeyEditListener.setTitle(el, 7); break; case 'de-panel-fav': KeyEditListener.setTitle(el, 6); break; case 'de-panel-vid': KeyEditListener.setTitle(el, 18); break; case 'de-panel-goback': KeyEditListener.setTitle(el, 4); break; case 'de-panel-gonext': KeyEditListener.setTitle(el, 17); break; case 'de-panel-maskimg': KeyEditListener.setTitle(el, 9); break; case 'de-panel-refresh': if(aib.t) { return; } /* falls through */ case 'de-panel-savethr': case 'de-panel-audio-off': if(this._menu && this._menu.parentEl === el) { return; } this._menuTO = setTimeout(() => { this._menu = addMenu(el); this._menu.onover = () => clearTimeout(this._hideTO); this._menu.onout = () => this._prepareToHide(null); this._menu.onremove = () => (this._menu = null); }, Cfg.linksOver); } return; default: // mouseout this._prepareToHide(fixEventEl(e.relatedTarget)); switch(el.id) { case 'de-panel-refresh': case 'de-panel-savethr': case 'de-panel-audio-off': clearTimeout(this._menuTO); this._menuTO = 0; } } }, updateCounter(postCount, imgsCount, postersCount) { this._pcountEl.textContent = postCount; this._icountEl.textContent = imgsCount; this._acountEl.textContent = postersCount; this.isNew = false; }, _el : null, _hideTO : 0, _menu : null, _menuTO : 0, get _acountEl() { const value = $id('de-panel-info-acount'); Object.defineProperty(this, '_acountEl', { value, configurable: true }); return value; }, get _icountEl() { const value = $id('de-panel-info-icount'); Object.defineProperty(this, '_icountEl', { value, configurable: true }); return value; }, get _pcountEl() { const value = $id('de-panel-info-pcount'); Object.defineProperty(this, '_pcountEl', { value, configurable: true }); return value; }, _getButton(id) { let page, href, title, useId; switch(id) { case 'goback': page = Math.max(aib.page - 1, 0); href = aib.getPageUrl(aib.b, page); if(!aib.t) { title = Lng.panelBtn.gonext[lang].replace('%s', page); } useId = 'arrow'; break; case 'gonext': page = aib.page + 1; href = aib.getPageUrl(aib.b, page); title = Lng.panelBtn.gonext[lang].replace('%s', page); /* falls through */ case 'goup': case 'godown': useId = 'arrow'; break; case 'upd-on': case 'upd-off': useId = 'upd'; break; case 'catalog': href = aib.catalogUrl; } // XXX Opera Presto: keep in sync with updMachine._setUpdateStatus return `
${ id !== 'audio-off' ? ` ` : ` ` } `; }, _prepareToHide(rt) { if(!Cfg.expandPanel && !$q('.de-win-active') && (!rt || !this._el.contains(rt.farthestViewportElement || rt)) ) { this._hideTO = setTimeout(() => $hide(this._buttons), 500); } } }); /* ==[ WindowUtils.js ]======================================================================================= WINDOW: UTILS =========================================================================================================== */ function updateWinZ(style) { if(style.zIndex < topWinZ) { style.zIndex = ++topWinZ; } } function makeDraggable(name, win, head) { head.addEventListener('mousedown', { _oldX : 0, _oldY : 0, _win : win, _wStyle : win.style, _X : 0, _Y : 0, _Z : 0, handleEvent(e) { if(!Cfg[name + 'WinDrag']) { return; } const { clientX: curX, clientY: curY } = e; switch(e.type) { case 'mousedown': this._oldX = curX; this._oldY = curY; this._X = Cfg[name + 'WinX']; this._Y = Cfg[name + 'WinY']; if(this._Z < topWinZ) { this._Z = this._wStyle.zIndex = ++topWinZ; } docBody.addEventListener('mouseleave', this); docBody.addEventListener('mousemove', this); docBody.addEventListener('mouseup', this); $pd(e); return; case 'mousemove': { const maxX = Post.sizing.wWidth - this._win.offsetWidth; const maxY = Post.sizing.wHeight - this._win.offsetHeight - 25; const cr = this._win.getBoundingClientRect(); const x = cr.left + curX - this._oldX; const y = cr.top + curY - this._oldY; this._X = x >= maxX || curX > this._oldX && x > maxX - 20 ? 'right: 0' : x < 0 || curX < this._oldX && x < 20 ? 'left: 0' : `left: ${ x }px`; this._Y = y >= maxY || curY > this._oldY && y > maxY - 20 ? 'bottom: 25px' : y < 0 || curY < this._oldY && y < 20 ? 'top: 0' : `top: ${ y }px`; const { width } = this._wStyle; this._win.setAttribute('style', `${ this._X }; ${ this._Y }; z-index: ${ this._Z }${ width ? '; width: ' + width : '' }`); this._oldX = curX; this._oldY = curY; return; } case 'mouseleave': case 'mouseup': docBody.removeEventListener('mouseleave', this); docBody.removeEventListener('mousemove', this); docBody.removeEventListener('mouseup', this); saveCfg(name + 'WinX', this._X); saveCfg(name + 'WinY', this._Y); } } }); } class WinResizer { constructor(name, dir, cfgName, win, target) { this.name = name; this.dir = dir; this.cfgName = cfgName; this.vertical = dir === 'top' || dir === 'bottom'; this.win = win; this.wStyle = this.win.style; this.tStyle = target.style; $q('.de-resizer-' + dir, win).addEventListener('mousedown', this); } handleEvent(e) { let val, x, y; const { wWidth: maxX, wHeight: maxY } = Post.sizing; const { width } = this.wStyle; const cr = this.win.getBoundingClientRect(); const z = `; z-index: ${ this.wStyle.zIndex }${ width ? '; width:' + width : '' }`; switch(e.type) { case 'mousedown': if(this.win.classList.contains('de-win-fixed')) { x = 'right: 0'; y = 'bottom: 25px'; } else { x = Cfg[this.name + 'WinX']; y = Cfg[this.name + 'WinY']; } switch(this.dir) { case 'top': val = `${ x }; bottom: ${ maxY - cr.bottom }px${ z }`; break; case 'bottom': val = `${ x }; top: ${ cr.top }px${ z }`; break; case 'left': val = `right: ${ maxX - cr.right }px; ${ y + z }`; break; case 'right': val = `left: ${ cr.left }px; ${ y + z }`; } this.win.setAttribute('style', val); docBody.addEventListener('mousemove', this); docBody.addEventListener('mouseup', this); $pd(e); return; case 'mousemove': if(this.vertical) { val = e.clientY; this.tStyle.setProperty('height', Math.max(parseInt(this.tStyle.height, 10) + ( this.dir === 'top' ? cr.top - (val < 20 ? 0 : val) : (val > maxY - 45 ? maxY - 25 : val) - cr.bottom ), 90) + 'px', 'important'); } else { val = e.clientX; this.tStyle.setProperty('width', Math.max(parseInt(this.tStyle.width, 10) + ( this.dir === 'left' ? cr.left - (val < 20 ? 0 : val) : (val > maxX - 20 ? maxX : val) - cr.right ), this.name === 'reply' ? 275 : 400) + 'px', 'important'); } return; default: // mouseup docBody.removeEventListener('mousemove', this); docBody.removeEventListener('mouseup', this); saveCfg(this.cfgName, parseInt(this.vertical ? this.tStyle.height : this.tStyle.width, 10)); if(this.win.classList.contains('de-win-fixed')) { this.win.setAttribute('style', 'right: 0; bottom: 25px' + z); return; } if(this.vertical) { saveCfg(this.name + 'WinY', cr.top < 1 ? 'top: 0' : cr.bottom > maxY - 26 ? 'bottom: 25px' : `top: ${ cr.top }px`); } else { saveCfg(this.name + 'WinX', cr.left < 1 ? 'left: 0' : cr.right > maxX - 1 ? 'right: 0' : `left: ${ cr.left }px`); } this.win.setAttribute('style', Cfg[this.name + 'WinX'] + '; ' + Cfg[this.name + 'WinY'] + z); } } } function toggleWindow(name, isUpdate, data, noAnim) { let el, win = $id('de-win-' + name); const isActive = win && win.classList.contains('de-win-active'); if(isUpdate && !isActive) { return; } if(!win) { const winAttr = (Cfg[name + 'WinDrag'] ? `de-win" style="${ Cfg[name + 'WinX'] }; ${ Cfg[name + 'WinY'] }` : 'de-win-fixed" style="right: 0; bottom: 25px' ) + (name !== 'fav' ? '' : `; width: ${ Cfg.favWinWidth }px; `); win = $aBegin($id('de-main'), `
${ name === 'cfg' ? 'Dollchan Extension Tools' : Lng.panelBtn[name][lang] }
${ name !== 'fav' ? '' : `
` }
`); const winBody = $q('.de-win-body', win); if(name === 'cfg') { winBody.className = 'de-win-body ' + aib.cReply; } else { setTimeout(() => { const backColor = getComputedStyle(docBody).getPropertyValue('background-color'); winBody.style.backgroundColor = backColor !== 'transparent' ? backColor : '#EEE'; }, 100); } if(name === 'fav') { new WinResizer('fav', 'left', 'favWinWidth', win, win); new WinResizer('fav', 'right', 'favWinWidth', win, win); } el = $q('.de-win-buttons', win); el.onmouseover = e => { const el = fixEventEl(e.target); const parent = el.parentNode; switch(el.classList[0]) { case 'de-win-btn-close': parent.title = Lng.closeWindow[lang]; break; case 'de-win-btn-toggle': parent.title = Cfg[name + 'WinDrag'] ? Lng.toPanel[lang] : Lng.makeDrag[lang]; } }; el.lastElementChild.onclick = () => toggleWindow(name, false); $q('.de-win-btn-toggle', el).onclick = () => { toggleCfg(name + 'WinDrag'); const isDrag = Cfg[name + 'WinDrag']; if(!isDrag) { const temp = $q('.de-win-active.de-win-fixed', win.parentNode); if(temp) { toggleWindow(temp.id.substr(7), false); } } win.classList.toggle('de-win', isDrag); win.classList.toggle('de-win-fixed', !isDrag); const { width } = win.style; win.style.cssText = `${ isDrag ? `${ Cfg[name + 'WinX'] }; ${ Cfg[name + 'WinY'] }` : 'right: 0; bottom: 25px' }${ width ? '; width: ' + width : '' }`; updateWinZ(win.style); }; makeDraggable(name, win, $q('.de-win-head', win)); } updateWinZ(win.style); let isRemove = !isUpdate && isActive; if(!isRemove && !win.classList.contains('de-win') && (el = $q(`.de-win-active.de-win-fixed:not(#de-win-${ name })`, win.parentNode)) ) { toggleWindow(el.id.substr(7), false); } const isAnim = !noAnim && !isUpdate && Cfg.animation; let body = $q('.de-win-body', win); if(isAnim && body.hasChildNodes()) { win.addEventListener('animationend', function aEvent(e) { e.target.removeEventListener('animationend', aEvent); showWindow(win, body, name, isRemove, data, Cfg.animation); win = body = name = isRemove = data = null; }); win.classList.remove('de-win-open'); win.classList.add('de-win-close'); } else { showWindow(win, body, name, isRemove, data, isAnim); } } function showWindow(win, body, name, isRemove, data, isAnim) { body.innerHTML = ''; win.classList.toggle('de-win-active', !isRemove); if(isRemove) { win.classList.remove('de-win-close'); $hide(win); if(!Cfg.expandPanel && !$q('.de-win-active')) { $hide($id('de-panel-buttons')); } return; } if(!Cfg.expandPanel) { $show($id('de-panel-buttons')); } switch(name) { case 'fav': if(data) { showFavoritesWindow(body, data); break; } readFavorites().then(favObj => { showFavoritesWindow(body, favObj); $show(win); if(isAnim) { win.classList.add('de-win-open'); } }); return; case 'cfg': CfgWindow.initCfgWindow(body); break; case 'hid': showHiddenWindow(body); break; case 'vid': showVideosWindow(body); } $show(win); if(isAnim) { win.classList.add('de-win-open'); } } /* ==[ WindowVidHid.js ]====================================================================================== WINDOW: VIDEOS, HIDDEN THREADS =========================================================================================================== */ function showVideosWindow(body) { const els = $Q('.de-video-link'); if(!els.length) { body.innerHTML = `${ Lng.noVideoLinks[lang] }`; return; } // EXCLUDED FROM FIREFOX EXTENSION - START if(!$id('de-ytube-api')) { // YouTube APT script. We can't insert scripts directly as html. const script = doc.createElement('script'); script.type = 'text/javascript'; script.src = aib.prot + '//www.youtube.com/player_api'; doc.head.appendChild(script).id = 'de-ytube-api'; } // EXCLUDED FROM FIREFOX EXTENSION - END body.innerHTML = `
`; const linkList = $add(`
`); // EXCLUDED FROM FIREFOX EXTENSION - START // A script to detect the end of current video playback, and auto play next. Uses YouTube API. // The first video should not start automatically! const script = doc.createElement('script'); script.type = 'text/javascript'; script.textContent = `(function() { if('YT' in window && 'Player' in window.YT) { onYouTubePlayerAPIReady(); } else { window.onYouTubePlayerAPIReady = onYouTubePlayerAPIReady; } function onYouTubePlayerAPIReady() { window.de_addVideoEvents = addEvents.bind(document.querySelector('#de-win-vid > .de-win-body > .de-video-obj')); window.de_addVideoEvents(); } function addEvents() { var autoplay = true; if(this.hasAttribute('de-disableautoplay')) { autoplay = false; this.removeAttribute('de-disableautoplay'); } new YT.Player(this.firstChild, { events: { 'onError': gotoNextVideo, 'onReady': autoplay ? function(e) { e.target.playVideo(); } : Function.prototype, 'onStateChange': function(e) { if(e.data === 0) { gotoNextVideo(); } } }}); } function gotoNextVideo() { document.getElementById("de-video-btn-next").click(); } })();`; body.appendChild(script); // EXCLUDED FROM FIREFOX EXTENSION - END // Events for control buttons body.addEventListener('click', { linkList, currentLink : null, listHidden : false, player : body.firstElementChild, playerInfo : null, handleEvent(e) { const el = e.target; if(el.classList.contains('de-abtn')) { let node; switch(el.id) { case 'de-video-btn-hide': { // Fold/unfold list of links const isHide = this.listHidden = !this.listHidden; $toggle(this.linkList, !isHide); el.textContent = isHide ? '\u25BC' : '\u25B2'; break; } case 'de-video-btn-prev': // Play previous video node = this.currentLink.parentNode; node = node.previousElementSibling || node.parentNode.lastElementChild; node.lastElementChild.click(); break; case 'de-video-btn-next': // Play next video node = this.currentLink.parentNode; node = node.nextElementSibling || node.parentNode.firstElementChild; node.lastElementChild.click(); break; case 'de-video-btn-resize': { // Expand/collapse video player const exp = this.player.className === 'de-video-obj'; this.player.className = exp ? 'de-video-obj de-video-expanded' : 'de-video-obj'; this.linkList.style.maxWidth = `${ exp ? 894 : +Cfg.YTubeWidth + 40 }px`; this.linkList.style.maxHeight = `${ nav.viewportHeight() * 0.92 - (exp ? 562 : +Cfg.YTubeHeigh + 82) }px`; } } $pd(e); return; } else if(!el.classList.contains('de-video-link')) { // Clicking on ">" before link // Go to post that contains this link pByNum.get(+el.getAttribute('de-num')).selectAndScrollTo(); return; } const info = el.videoInfo; if(this.playerInfo !== info) { // Prevents same link clicking // Mark new link as a current and add player for it if(this.currentLink) { this.currentLink.classList.remove('de-current'); } this.currentLink = el; el.classList.add('de-current'); Videos.addPlayer(this, info, el.classList.contains('de-ytube'), true); } $pd(e); } }, true); // Copy all video links into videos list for(let i = 0, len = els.length; i < len; ++i) { updateVideoList(linkList, els[i], aib.getPostOfEl(els[i]).num); } body.appendChild(linkList); $q('.de-video-link', linkList).click(); } function updateVideoList(parent, link, num) { const el = link.cloneNode(true); el.videoInfo = link.videoInfo; $bEnd(parent, `
>>
`).appendChild(el).classList.remove('de-current'); el.setAttribute('onclick', 'window.de_addVideoEvents && window.de_addVideoEvents();'); } // HIDDEN THREADS WINDOW function showHiddenWindow(body) { const hThr = HiddenThreads.getRawData(); const hasThreads = !$isEmpty(hThr); if(hasThreads) { // Generate DOM for the list of hidden threads for(const b in hThr) { if($isEmpty(hThr[b])) { continue; } const block = $bEnd(body, `
/${ b }
`); block.firstChild.onclick = e => $each($Q('.de-entry > input', block), el => (el.checked = e.target.checked)); for(const tNum in hThr[b]) { $bEnd(block, `
${ tNum }
- ${ hThr[b][tNum][2] }
`); } } } const btns = $bEnd(body, (!hasThreads ? `
${ Lng.noHidThr[lang] }
` : '') + '
'); // "Edit" button. Calls a popup with editor to edit Hidden in JSON. btns.appendChild(getEditButton('hidden', fn => fn(HiddenThreads.getRawData(), true, data => { HiddenThreads.saveRawData(data); Thread.first.updateHidden(data[aib.b]); toggleWindow('hid', true); }))); // "Clear" button. Allows to clear 404'd threads. btns.appendChild($btn(Lng.clear[lang], Lng.clrDeleted[lang], async e => { // Sequentially load threads, and remove inaccessible const els = $Q('.de-entry[info]', e.target.parentNode.parentNode); for(let i = 0, len = els.length; i < len; ++i) { const [b, tNum] = els[i].getAttribute('info').split(';'); await $ajax(aib.getThrUrl(b, tNum)).catch(err => { if(err.code === 404) { HiddenThreads.removeStorage(tNum, b); HiddenPosts.removeStorage(tNum, b); } }); } toggleWindow('hid', true); })); // "Delete" button. Allows to delete selected threads btns.appendChild($btn(Lng.remove[lang], Lng.delEntries[lang], () => { $each($Q('.de-entry[info]', body), el => { if(!$q('input', el).checked) { return; } const [brd, tNum] = el.getAttribute('info').split(';'); const num = +tNum; if(pByNum.has(num)) { pByNum.get(num).setUserVisib(false); } else { sendStorageEvent('__de-post', { brd, num, hide: false, thrNum: num }); } HiddenThreads.removeStorage(num, brd); HiddenPosts.set(num, num, false); // Actually unhide thread by its oppost }); toggleWindow('hid', true); })); } /* ==[ WindowFavorites.js ]=================================================================================== WINDOW: FAVORITES =========================================================================================================== */ function saveRenewFavorites(favObj) { saveFavorites(favObj); toggleWindow('fav', true, favObj); } function removeFavEntry(favObj, h, b, num) { let f; if((h in favObj) && (b in favObj[h]) && (num in (f = favObj[h][b]))) { delete f[num]; if(!(Object.keys(f).length - +f.hasOwnProperty('url') - +f.hasOwnProperty('hide'))) { delete favObj[h][b]; if($isEmpty(favObj[h])) { delete favObj[h]; } } } } function toggleThrFavBtn(h, b, num, isEnable) { if(h === aib.host && b === aib.b && pByNum.has(num)) { const post = pByNum.get(num); post.toggleFavBtn(isEnable); post.thr.isFav = isEnable; } } function updateFavorites(num, value, mode) { readFavorites().then(favObj => { let isUpdate = false; let f = favObj[aib.host]; if(!f || !f[aib.b] || !(f = f[aib.b][num])) { return; } switch(mode) { case 'error': if(f.err !== value) { isUpdate = true; } f.err = value; break; case 'update': if(f.cnt !== value[0]) { isUpdate = true; } f.cnt = value[0]; f.new = f.you = 0; f.last = aib.anchor + value[1]; } const data = [aib.host, aib.b, num, value, mode]; if(isUpdate) { updateFavWindow(...data); saveFavorites(favObj); sendStorageEvent('__de-favorites', data); } }); } function updateFavWindow(h, b, num, value, mode) { if(mode === 'add' || mode === 'delete') { toggleThrFavBtn(h, b, num, mode === 'add'); toggleWindow('fav', true, value); return; } const winEl = $q('#de-win-fav > .de-win-body'); if(!winEl || !winEl.hasChildNodes()) { return; } const el = $q(`.de-entry[de-host="${ h }"][de-board="${ b }"][de-num="${ num }"] > .de-fav-inf`, winEl); if(!el) { return; } const [iconEl, youEl, newEl, oldEl] = [...el.children]; $hide(youEl); $hide(newEl); if(mode === 'error') { iconEl.firstElementChild.setAttribute('class', 'de-fav-inf-icon de-fav-unavail'); iconEl.title = value; return; } youEl.textContent = 0; newEl.textContent = 0; oldEl.textContent = value[0]; } // Delete previously marked entries from Favorites function cleanFavorites() { const els = $Q('.de-entry[de-removed]'); const len = els.length; if(!len) { return; } readFavorites().then(favObj => { for(let i = 0; i < len; ++i) { const el = els[i]; const h = el.getAttribute('de-host'); const b = el.getAttribute('de-board'); const num = +el.getAttribute('de-num'); removeFavEntry(favObj, h, b, num); toggleThrFavBtn(h, b, num, false); } saveRenewFavorites(favObj); }); } function showFavoritesWindow(body, favObj) { let html = ''; // Create the list of favorite threads for(const h in favObj) { for(const b in favObj[h]) { const f = favObj[h][b]; const hb = `de-host="${ h }" de-board="${ b }"`; const delBtn = ` `; let fArr, innerHtml = ''; switch(Cfg.favThrOrder) { case 0: fArr = Object.entries(f); break; case 1: fArr = Object.entries(f).reverse(); break; case 2: fArr = Object.entries(f).sort((a, b) => (a[1].time || 0) - (b[1].time || 0)); break; case 3: fArr = Object.entries(f).sort((a, b) => (b[1].time || 0) - (a[1].time || 0)); } for(let i = 0, len = fArr.length; i < len; ++i) { const tNum = fArr[i][0]; if(tNum === 'url' || tNum === 'hide') { continue; } const t = f[tNum]; if(!t.url.startsWith('http')) { // XXX: compatibility with older versions t.url = (h === aib.host ? aib.prot + '//' : 'http://') + h + t.url; } // Generate DOM for separate entry const favLinkHref = t.url + ( !t.last ? '' : t.last.startsWith('#') ? t.last : h === aib.host ? aib.anchor + t.last : ''); const favInfIwrapTitle = !t.err ? '' : t.err === 'Closed' ? `title="${ Lng.thrClosed[lang] }"` : `title="${ t.err }"`; const favInfIconClass = !t.err ? '' : t.err === 'Closed' || t.err === 'Archived' ? 'de-fav-closed' : 'de-fav-unavail'; const favInfYouDisp = t.you ? '' : ' style="display: none;"'; const favInfNewDisp = t.new ? '' : ' style="display: none;"'; innerHtml += `
${ delBtn } ${ tNum }
- ${ t.txt }
${ t.you || 0 } ${ t.new || 0 } ${ t.cnt }
`; } if(!innerHtml) { continue; } const isHide = f.hide === undefined ? h !== aib.host : f.hide; // Building a foldable block for specific board html += `
${ delBtn } ${ h }/${ b } ${ isHide ? '▼' : '▲' }
${ innerHtml }
`; } } // Appending DOM and events if(html) { $bEnd(body, `
${ html }
`).addEventListener('click', e => { let el = fixEventEl(e.target); let parentEl = el.parentNode; if(el.tagName.toLowerCase() === 'svg') { el = parentEl; parentEl = parentEl.parentNode; } switch(el.className) { case 'de-fav-link': sesStorage['de-fav-win'] = '1'; // Favorites will open again after following a link // We need to scroll to last seen post after following a link, // remembering of scroll position is no longer needed sesStorage.removeItem('de-scroll-' + parentEl.getAttribute('de-board') + (parentEl.getAttribute('de-num') || '')); break; case 'de-fav-del-btn': { const wasChecked = el.getAttribute('de-checked') === ''; const toggleFn = btnEl => toggleAttr(btnEl, 'de-checked', '', !wasChecked); toggleFn(el); if(parentEl.className === 'de-fav-header') { // Select/unselect all checkboxes in board block const entriesEl = parentEl.nextElementSibling; $each($Q('.de-fav-del-btn', entriesEl), toggleFn); if(!wasChecked && entriesEl.classList.contains('de-fav-entries-hide')) { entriesEl.classList.remove('de-fav-entries-hide'); } } const isShowDelBtns = !!$q('.de-entry > .de-fav-del-btn[de-checked]', body); $toggle($id('de-fav-buttons'), !isShowDelBtns); $toggle($id('de-fav-del-confirm'), isShowDelBtns); break; } case 'de-abtn de-fav-header-btn': { const entriesEl = parentEl.nextElementSibling; const isHide = !entriesEl.classList.contains('de-fav-entries-hide'); el.innerHTML = isHide ? '▼' : '▲'; favObj[entriesEl.getAttribute('de-host')][entriesEl.getAttribute('de-board')].hide = isHide; saveFavorites(favObj); $pd(e); entriesEl.classList.toggle('de-fav-entries-hide'); } } }); } else { $bEnd(body, `
${ Lng.noFavThr[lang] }
`); } const btns = $bEnd(body, '
'); // "Edit" button. Calls a popup with editor to edit Favorites in JSON. btns.appendChild(getEditButton('favor', fn => readFavorites().then(favObj => fn(favObj, true, saveRenewFavorites)))); // "Refresh" button. Updates counters of new posts for each thread entry. btns.appendChild($btn(Lng.refresh[lang], Lng.infoCount[lang], async () => { const favObj = await readFavorites(); if(!favObj[aib.host]) { return; } let isUpdate = false; let last404 = false; const myposts = JSON.parse(locStorage['de-myposts'] || '{}'); const els = $Q('.de-entry'); for(let i = 0, len = els.length; i < len; ++i) { const el = els[i]; const host = el.getAttribute('de-host'); const b = el.getAttribute('de-board'); const num = el.getAttribute('de-num'); const f = favObj[host][b][num]; // Updating doesn't works for other domains because of different posts structure // Updating is not needed in closed threads if(host !== aib.host || f.err === 'Closed' || f.err === 'Archived') { continue; } const [titleEl, youEl, countEl] = [...el.lastElementChild.children]; const iconEl = titleEl.firstElementChild; // setAttribute for class is used because of SVG (for correct work in some browsers) iconEl.setAttribute('class', 'de-fav-inf-icon de-fav-wait'); titleEl.title = Lng.updating[lang]; let form, isArchived; try { if(!aib.hasArchive) { form = await ajaxLoad(aib.getThrUrl(b, num)); } else { [form, isArchived] = await ajaxLoad(aib.getThrUrl(b, num), true, false, true); } last404 = false; } catch(err) { if((err instanceof AjaxError) && err.code === 404) { // Check for 404 error twice if(last404) { Thread.removeSavedData(b, num); // Not working yet } else { last404 = true; --i; // Repeat this cycle again continue; } } last404 = false; $hide(countEl); $hide(youEl); iconEl.setAttribute('class', 'de-fav-inf-icon de-fav-unavail'); f.err = titleEl.title = getErrorMessage(err); isUpdate = true; continue; } if(aib.qClosed && $q(aib.qClosed, form)) { // Check for closed thread iconEl.setAttribute('class', 'de-fav-inf-icon de-fav-closed'); titleEl.title = Lng.thrClosed[lang]; f.err = 'Closed'; isUpdate = true; } else if(isArchived) { iconEl.setAttribute('class', 'de-fav-inf-icon de-fav-closed'); titleEl.title = Lng.thrArchived[lang]; f.err = 'Archived'; isUpdate = true; } else { // Thread is available and not closed iconEl.setAttribute('class', 'de-fav-inf-icon'); titleEl.removeAttribute('title'); if(f.err) { // Cancel error status if existed delete f.err; isUpdate = true; } } // Updating a counter of new posts const posts = $Q(aib.qRPost, form); const cnt = posts.length + 1 - f.cnt; countEl.textContent = cnt; if(cnt === 0) { $hide(countEl); // Hide counter if no new posts $hide(youEl); } else { $show(countEl); f.new = cnt; isUpdate = true; // Check for replies to my posts if(myposts && myposts[b]) { f.you = 0; for(let j = 0; j < cnt; ++j) { const links = $Q(aib.qPostMsg.split(', ').join(' a, ') + ' a', posts[posts.length - 1 - j]); for(let a = 0, len = links.length; a < len; ++a) { const tc = links[a].textContent; if(tc[0] === '>' && tc[1] === '>' && myposts[b][tc.substr(2)]) { f.you++; } } } if(f.you) { youEl.textContent = f.you; $show(youEl); } } } } AjaxCache.clearCache(); if(isUpdate) { saveFavorites(favObj); } })); // "Page" button. Shows on which page every thread is existed. btns.appendChild($btn(Lng.page[lang], Lng.infoPage[lang], async () => { const els = $Q('.de-fav-current > .de-fav-entries > .de-entry'); const len = els.length; if(!len) { // Cancel if no existed entries return; } $popup('load-pages', Lng.loading[lang], true); // Create indexed array of entries and "waiting" SVG icon for each entry const thrInfo = []; for(let i = 0; i < len; ++i) { const el = els[i]; const iconEl = $q('.de-fav-inf-icon', el); const titleEl = iconEl.parentNode; thrInfo.push({ found : false, num : +el.getAttribute('de-num'), pageEl : $q('.de-fav-inf-page', el), iconClass : iconEl.getAttribute('class'), iconEl, iconTitle : titleEl.getAttribute('title'), titleEl }); iconEl.setAttribute('class', 'de-fav-inf-icon de-fav-wait'); titleEl.title = Lng.updating[lang]; } // Sequentially load pages and search for favorites threads // We cannot know a count of pages while in the thread const endPage = (aib.lastPage || 10) + 1; // Check up to 10 page, if we don't know let infoLoaded = 0; const updateInf = (inf, page) => { inf.iconEl.setAttribute('class', inf.iconClass); toggleAttr(inf.titleEl, 'title', inf.iconTitle, inf.iconTitle); inf.pageEl.textContent = '@' + page; }; for(let page = 0; page < endPage; ++page) { const tNums = new Set(); try { const form = await ajaxLoad(aib.getPageUrl(aib.b, page)); const els = DelForm.getThreads(form); for(let i = 0, len = els.length; i < len; ++i) { tNums.add(aib.getTNum(els[i])); } } catch(err) { continue; } // Search for threads on current page for(let i = 0; i < len; ++i) { const inf = thrInfo[i]; if(tNums.has(inf.num)) { updateInf(inf, page); inf.found = true; infoLoaded++; } } if(infoLoaded === len) { // Stop pages loading when all favorite threads checked break; } } // Process missed threads that not found for(let i = 0; i < len; ++i) { const inf = thrInfo[i]; if(!inf.found) { updateInf(inf, '?'); } } closePopup('load-pages'); })); // "Clear" button. Allows to clear 404'd threads. btns.appendChild($btn(Lng.clear[lang], Lng.clrDeleted[lang], async () => { // Sequentially load threads, and remove inaccessible let last404 = false; const els = $Q('.de-entry'); const parent = $q('.de-fav-table'); parent.classList.add('de-fav-table-unfold'); for(let i = 0, len = els.length; i < len; ++i) { const el = els[i]; const iconEl = $q('.de-fav-inf-icon', el); const titleEl = iconEl.parentNode; iconEl.setAttribute('class', 'de-fav-inf-icon de-fav-wait'); titleEl.title = Lng.updating[lang]; await $ajax(el.getAttribute('de-url'), null, true).then(xhr => { switch(el.getAttribute('de-host')) { // Makaba doesn't return 404 case '2ch.hk': case '2ch.pm': { const dc = $DOM(xhr.responseText); if(dc && $q('.message-title', dc)) { throw new AjaxError(404, 'Error'); } } } iconEl.setAttribute('class', 'de-fav-inf-icon'); titleEl.removeAttribute('title'); last404 = false; }).catch(err => { if(err.code === 404) { // Check for 404 error twice if(!last404) { last404 = true; --i; // Repeat this cycle again return; } Thread.removeSavedData(el.getAttribute('de-board'), // Not working yet +el.getAttribute('de-num')); el.setAttribute('de-removed', ''); // Mark an entry as deleted } iconEl.setAttribute('class', 'de-fav-inf-icon de-fav-unavail'); titleEl.title = getErrorMessage(err); last404 = false; }); } cleanFavorites(); // Delete marked entries parent.classList.remove('de-fav-table-unfold'); })); // Deletion confirm/cancel buttons const delBtns = $bEnd(body, ''); delBtns.appendChild($btn(Lng.remove[lang], Lng.delEntries[lang], () => { $each($Q('.de-entry > .de-fav-del-btn[de-checked]', body), el => el.parentNode.setAttribute('de-removed', '')); cleanFavorites(); // Delete marked entries $show(btns); $hide(delBtns); })); delBtns.appendChild($btn(Lng.cancel[lang], '', () => { $each($Q('.de-fav-del-btn', body), el => el.removeAttribute('de-checked')); $show(btns); $hide(delBtns); })); } /* ==[ WindowSettings.js ]==================================================================================== WINDOW: SETTINGS =========================================================================================================== */ const CfgWindow = { initCfgWindow(body) { body.addEventListener('click', this); body.addEventListener('mouseover', this); body.addEventListener('mouseout', this); body.addEventListener('change', this); body.addEventListener('keyup', this); body.addEventListener('keydown', this); body.addEventListener('scroll', this); // Create tab bar and bottom buttons let div = $bEnd(body, `
${ this._getTab('filters') + this._getTab('posts') + this._getTab('images') + this._getTab('links') + (pr.form || pr.oeForm ? this._getTab('form') : '') + this._getTab('common') + this._getTab('info') }
${ this._getSel('language') }
`); // Open default or current tab this._clickTab(Cfg.cfgTab); // "Edit" button. Calls a popup with editor to edit Settings in JSON. div.appendChild(getEditButton('cfg', fn => fn(Cfg, true, data => { saveCfgObj(aib.dm, data); deWindow.location.reload(); }))); // "Global" button. Allows to save/load global settings. nav.hasGlobalStorage && div.appendChild($btn(Lng.global[lang], Lng.globalCfg[lang], () => { const el = $popup('cfg-global', `${ Lng.globalCfg[lang] }:`); // "Load" button. Applies global settings for current domain. $bEnd(el, `
${ Lng.loadGlobal[lang] }
` ).firstElementChild.onclick = () => getStoredObj('DESU_Config').then(data => { if(data && ('global' in data) && !$isEmpty(data.global)) { saveCfgObj(aib.dm, data.global); deWindow.location.reload(); } else { $popup('err-noglobalcfg', Lng.noGlobalCfg[lang]); } }); // "Save" button. Copies the domain settings into global. div = $bEnd(el, `
${ Lng.saveGlobal[lang] }
` ).firstElementChild.onclick = () => getStoredObj('DESU_Config').then(data => { const obj = {}; const com = data[aib.dm]; for(const i in com) { if(i !== 'correctTime' && i !== 'timePattern' && i !== 'userCSS' && i !== 'userCSSTxt' && i !== 'stats' && com[i] !== defaultCfg[i] ) { obj[i] = com[i]; } } data.global = obj; saveCfgObj('global', data.global); toggleWindow('cfg', true); }); el.insertAdjacentHTML('beforeend', `
${ Lng.descrGlobal[lang] }`); })); // "File" button. Allows to save and load settings/favorites/hidden/etc from file. !nav.isPresto && div.appendChild($btn(Lng.file[lang], Lng.fileImpExp[lang], () => { const list = this._getList([ Lng.panelBtn.cfg[lang] + ' ' + Lng.allDomains[lang], Lng.panelBtn.fav[lang], Lng.hidPostThr[lang] + ` (${ aib.dm })`, Lng.myPosts[lang] + ` (${ aib.dm })` ]); // Create popup with controls $popup('cfg-file', `${ Lng.fileImpExp[lang] }:
${ Lng.fileToData[lang] }:

${ Lng.dataToFile[lang] }:
${ list }
`); // Import data from a file to the storage $id('de-import-file').onchange = e => { const file = e.target.files[0]; if(!file) { return; } readFile(file, true).then(({ data }) => { let obj; try { obj = JSON.parse(data); } catch(err) { $popup('err-invaliddata', Lng.invalidData[lang]); return; } const cfgObj = obj.settings; const favObj = obj.favorites; const dmObj = obj[aib.dm]; const isOldCfg = !cfgObj && !favObj && !dmObj; if(isOldCfg) { setStored('DESU_Config', data); } if(cfgObj) { try { setStored('DESU_Config', JSON.stringify(cfgObj)); setStored('DESU_keys', JSON.stringify(obj.hotkeys)); } catch(err) {} } if(favObj) { saveRenewFavorites(favObj); } if(dmObj) { if(dmObj.posts) { locStorage['de-posts'] = JSON.stringify(dmObj.posts); } if(dmObj.threads) { locStorage['de-threads'] = JSON.stringify(dmObj.threads); } if(dmObj.myposts) { locStorage['de-myposts'] = JSON.stringify(dmObj.myposts); } } if(cfgObj || dmObj || isOldCfg) { $popup('cfg-file', Lng.updating[lang], true); deWindow.location.reload(); return; } closePopup('cfg-file'); }); }; // Export data from a storage to the file. The file will be named by date and type of storage. // For example, like "DE_20160727_1540_Cfg+Fav+domain.com(Hid+You).json". const expFile = $id('de-export-file'); const els = $Q('input', expFile.nextElementSibling); els[0].checked = true; expFile.addEventListener('click', async e => { const name = [], nameDm = [], d = new Date(); let val = [], valDm = []; for(let i = 0, len = els.length; i < len; ++i) { if(!els[i].checked) { continue; } switch(i) { case 0: name.push('Cfg'); { const cfgData = await Promise.all([getStored('DESU_Config'), getStored('DESU_keys')]); val.push(`"settings":${ cfgData[0] }`, `"hotkeys":${ cfgData[1] || '""' }`); break; } case 1: name.push('Fav'); val.push(`"favorites":${ await getStored('DESU_Favorites') || '{}' }`); break; case 2: nameDm.push('Hid'); valDm.push(`"posts":${ locStorage['de-posts'] || '{}' }`, `"threads":${ locStorage['de-threads'] || '{}' }`); break; case 3: nameDm.push('You'); valDm.push(`"myposts":${ locStorage['de-myposts'] || '{}' }`); } } if((valDm = valDm.join(','))) { val.push(`"${ aib.dm }":{${ valDm }}`); name.push(`${ aib.dm } (${ nameDm.join('+') })`); } if((val = val.join(','))) { downloadBlob(new Blob([`{${ val }}`], { type: 'application/json' }), `DE_${ d.getFullYear() }${ pad2(d.getMonth() + 1) }${ pad2(d.getDate()) }_${ pad2(d.getHours()) }${ pad2(d.getMinutes()) }_${ name.join('+') }.json`); } $pd(e); }, true); })); // "Clear" button. Allows to clear settings/favorites/hidden/etc optionally. div.appendChild($btn(Lng.reset[lang] + '…', Lng.resetCfg[lang], () => $popup( 'cfg-reset', `${ Lng.resetData[lang] }:
` + `
${ aib.dm }:${ this._getList([Lng.panelBtn.cfg[lang], Lng.hidPostThr[lang], Lng.myPosts[lang]]) }

` + `
${ Lng.allDomains[lang] }:${ this._getList([Lng.panelBtn.cfg[lang], Lng.panelBtn.fav[lang]]) }

` ).appendChild($btn(Lng.clear[lang], '', e => { const els = $Q('input[type="checkbox"]', e.target.parentNode); for(let i = 1, len = els.length; i < len; ++i) { if(!els[i].checked) { continue; } switch(i) { case 1: locStorage.removeItem('de-posts'); locStorage.removeItem('de-threads'); break; case 2: locStorage.removeItem('de-myposts'); break; case 4: delStored('DESU_Favorites'); } } if(els[3].checked) { delStored('DESU_Config'); delStored('DESU_keys'); } else if(els[0].checked) { getStoredObj('DESU_Config').then(data => { delete data[aib.dm]; setStored('DESU_Config', JSON.stringify(data)); $popup('cfg-reset', Lng.updating[lang], true); deWindow.location.reload(); }); return; } $popup('cfg-reset', Lng.updating[lang], true); deWindow.location.reload(); })))); }, // Event handler for Setting window and its controls. handleEvent(e) { const { type, target: el } = e; const tag = el.tagName; if(type === 'click' && tag === 'DIV' && el.classList.contains('de-cfg-tab')) { const info = el.getAttribute('info'); this._clickTab(info); saveCfg('cfgTab', info); } if(type === 'change' && tag === 'SELECT') { const info = el.getAttribute('info'); saveCfg(info, el.selectedIndex); this._updateDependant(); switch(info) { case 'language': lang = el.selectedIndex; Panel.removeMain(); if(pr.form) { pr.addMarkupPanel(); pr.setPlaceholders(); pr.updateLanguage(); aib.updateSubmitBtn(pr.subm); if(pr.files) { $each($Q('.de-file-img, .de-file-txt-input', pr.form), el => (el.title = Lng.youCanDrag[lang])); } } this._updateCSS(); Panel.initPanel(DelForm.first.el); toggleWindow('cfg', false); break; case 'delHiddPost': { const isHide = Cfg.delHiddPost === 1 || Cfg.delHiddPost === 2; for(let post = Thread.first.op; post; post = post.next) { if(post.isHidden && !post.isOp) { post.wrap.classList.toggle('de-hidden', isHide); } } updateCSS(); break; } case 'postBtnsCSS': updateCSS(); if(nav.isPresto) { $q('.de-svg-icons').remove(); addSVGIcons(); } break; case 'thrBtns': case 'noSpoilers': case 'resizeImgs': updateCSS(); break; case 'expandImgs': updateCSS(); AttachedImage.closeImg(); break; case 'imgNames': if(Cfg.imgNames) { for(const { el } of DelForm) { processImgInfoLinks(el, 0, Cfg.imgNames); } } else { $each($Q('.de-img-name'), el => (el.textContent = el.getAttribute('de-img-name-old'))); } updateCSS(); break; case 'fileInputs': pr.files.changeMode(); pr.setPlaceholders(); updateCSS(); break; case 'addPostForm': pr.isBottom = Cfg.addPostForm === 1; pr.setReply(false, !aib.t || Cfg.addPostForm > 1); break; case 'addTextBtns': pr.addMarkupPanel(); /* falls through */ case 'scriptStyle': case 'panelCounter': this._updateCSS(); break; case 'favThrOrder': readFavorites().then(favObj => { const body = $q('#de-win-fav > .de-win-body'); body.innerHTML = ''; showFavoritesWindow(body, favObj); }); } return; } if(type === 'click' && tag === 'INPUT' && el.type === 'checkbox') { const info = el.getAttribute('info'); toggleCfg(info); this._updateDependant(); switch(info) { case 'expandTrunc': case 'showHideBtn': case 'showRepBtn': case 'widePosts': case 'noPostNames': case 'imgNavBtns': case 'strikeHidd': case 'removeHidd': case 'noBoardRule': case 'userCSS': updateCSS(); break; case 'hideBySpell': Spells.toggle(); break; case 'sortSpells': if(Cfg.sortSpells) { Spells.toggle(); } break; case 'hideRefPsts': for(let post = Thread.first.op; post; post = post.next) { if(!Cfg.hideRefPsts) { post.ref.unhideRef(); } else if(post.isHidden) { post.ref.hideRef(); } } break; case 'ajaxUpdThr': if(aib.t) { if(Cfg.ajaxUpdThr) { updater.enableUpdater(); } else { updater.disableUpdater(); } } break; case 'updCount': updater.toggleCounter(Cfg.updCount); break; case 'desktNotif': if(Cfg.desktNotif) { Notification.requestPermission(); } break; case 'markNewPosts': Post.clearMarks(); break; case 'useDobrAPI': aib.JsonBuilder = Cfg.useDobrAPI ? DobrochanPostsBuilder : null; break; case 'markMyPosts': case 'markMyLinks': if(!Cfg.markMyPosts && !Cfg.markMyLinks) { locStorage.removeItem('de-myposts'); MyPosts.purge(); } updateCSS(); break; case 'correctTime': DateTime.toggleSettings(el); break; case 'imgInfoLink': { const img = $q('.de-fullimg-wrap'); if(img) { img.click(); } updateCSS(); break; } case 'imgSrcBtns': if(Cfg.imgSrcBtns) { for(const { el } of DelForm) { processImgInfoLinks(el, 1, 0); $each($Q('.de-img-embed'), el => addImgSrcButtons(el.parentNode.nextSibling.nextSibling)); } } else { $delAll('.de-btn-src'); } break; case 'addSageBtn': PostForm.hideField($parent(pr.mail, 'LABEL') || pr.mail); setTimeout(() => pr.toggleSage(), 0); updateCSS(); break; case 'altCaptcha': pr.cap.initCapPromise(); break; case 'txtBtnsLoc': pr.addMarkupPanel(); updateCSS(); break; case 'userPassw': PostForm.setUserPassw(); break; case 'userName': PostForm.setUserName(); break; case 'noPassword': $toggle($qParent(pr.passw, aib.qFormTr)); break; case 'noName': PostForm.hideField(pr.name); break; case 'noSubj': PostForm.hideField(pr.subj); break; case 'inftyScroll': toggleInfinityScroll(); break; case 'hotKeys': if(Cfg.hotKeys) { HotKeys.enableHotKeys(); } else { HotKeys.disableHotKeys(); } } return; } if(type === 'click' && tag === 'INPUT' && el.type === 'button') { switch(el.id) { case 'de-cfg-button-pass': $q('input[info="passwValue"]').value = Math.round(Math.random() * 1e12).toString(32); PostForm.setUserPassw(); break; case 'de-cfg-button-keys': $pd(e); if($id('de-popup-edit-hotkeys')) { return; } Promise.resolve(HotKeys.readKeys()).then(keys => { const temp = KeyEditListener.getEditMarkup(keys); const el = $popup('edit-hotkeys', temp[1]); const fn = new KeyEditListener(el, keys, temp[0]); el.addEventListener('focus', fn, true); el.addEventListener('blur', fn, true); el.addEventListener('click', fn, true); el.addEventListener('keydown', fn, true); el.addEventListener('keyup', fn, true); }); break; case 'de-cfg-button-updnow': $popup('updavail', Lng.loading[lang], true); getStoredObj('DESU_Config') .then(data => checkForUpdates(true, data.lastUpd)) .then(html => $popup('updavail', html), emptyFn); break; case 'de-cfg-button-debug': { const perf = {}; const arr = Logger.getLogData(true); for(let i = 0, len = arr.length; i < len; ++i) { perf[arr[i][0]] = arr[i][1]; } $popup('cfg-debug', Lng.infoDebug[lang] + ':' ).firstElementChild.value = JSON.stringify({ version : version + '.' + commit, location : String(deWindow.location), nav, Cfg, sSpells : Spells.list.split('\n'), oSpells : sesStorage[`de-spells-${ aib.b }${ aib.t || '' }`], perf }, (key, value) => { switch(key) { case 'stats': case 'nameValue': case 'passwValue': case 'ytApiKey': return void 0; } return key in defaultCfg && value === defaultCfg[key] ? void 0 : value; }, '\t'); } } } if(type === 'keyup' && tag === 'INPUT' && el.type === 'text') { const info = el.getAttribute('info'); switch(info) { case 'postBtnsBack': { const isCheck = checkCSSColor(el.value); el.classList.toggle('de-input-error', !isCheck); if(isCheck) { saveCfg('postBtnsBack', el.value); updateCSS(); } break; } case 'limitPostMsg': saveCfg('limitPostMsg', Math.max(+el.value || 0, 50)); updateCSS(); break; case 'minImgSize': saveCfg('minImgSize', Math.max(+el.value, 1)); break; case 'zoomFactor': saveCfg('zoomFactor', Math.min(Math.max(+el.value, 1), 100)); break; case 'webmVolume': { const val = Math.min(+el.value || 0, 100); saveCfg('webmVolume', val); sendStorageEvent('__de-webmvolume', val); break; } case 'minWebmWidth': saveCfg('minWebmWidth', Math.max(+el.value, Cfg.minImgSize)); break; case 'maskVisib': saveCfg('maskVisib', Math.min(+el.value || 0, 100)); updateCSS(); break; case 'linksOver': saveCfg('linksOver', +el.value | 0); break; case 'linksOut': saveCfg('linksOut', +el.value | 0); break; case 'ytApiKey': saveCfg('ytApiKey', el.value.trim()); break; case 'passwValue': PostForm.setUserPassw(); break; case 'nameValue': PostForm.setUserName(); break; default: saveCfg(info, el.value); } return; } if(tag === 'A') { if(el.id === 'de-btn-spell-add') { switch(e.type) { case 'click': $pd(e); break; case 'mouseover': el.odelay = setTimeout(() => addMenu(el), Cfg.linksOver); break; case 'mouseout': clearTimeout(el.odelay); } return; } if(type === 'click') { switch(el.id) { case 'de-btn-spell-apply': $pd(e); saveCfg('hideBySpell', 1); $q('input[info="hideBySpell"]').checked = true; Spells.toggle(); break; case 'de-btn-spell-clear': $pd(e); if(!confirm(Lng.clear[lang] + '?')) { return; } $id('de-spell-txt').value = ''; Spells.toggle(); } } return; } if(tag === 'TEXTAREA' && el.id === 'de-spell-txt' && (type === 'keydown' || type === 'scroll')) { this._updateRowMeter(el); } }, // Switch content in Settings by clicking on tab _clickTab(info) { const el = $q(`.de-cfg-tab[info="${ info }"]`); if(el.hasAttribute('selected')) { return; } const prefTab = $q('.de-cfg-body'); if(prefTab) { prefTab.className = 'de-cfg-unvis'; $q('.de-cfg-tab[selected]').removeAttribute('selected'); } el.setAttribute('selected', ''); const id = el.getAttribute('info'); let newTab = $id('de-cfg-' + id); if(!newTab) { newTab = $aEnd($id('de-cfg-bar'), id === 'filters' ? this._getCfgFilters() : id === 'posts' ? this._getCfgPosts() : id === 'images' ? this._getCfgImages() : id === 'links' ? this._getCfgLinks() : id === 'form' ? this._getCfgForm() : id === 'common' ? this._getCfgCommon() : this._getCfgInfo()); if(id === 'filters') { this._updateRowMeter($id('de-spell-txt')); } if(id === 'common') { // XXX: remove and make insertion in this._getCfgCommon() $after($q('input[info="userCSS"]').parentNode, getEditButton( 'css', fn => fn(Cfg.userCSSTxt, false, function() { saveCfg('userCSSTxt', this.value); updateCSS(); toggleWindow('cfg', true); }), 'de-cfg-button' )); } } newTab.className = 'de-cfg-body'; if(id === 'filters') { $id('de-spell-txt').value = Spells.list; } this._updateDependant(); // Updates all inputs according to config const els = $Q('.de-cfg-chkbox, .de-cfg-inptxt, .de-cfg-select', newTab.parentNode); for(let i = 0, len = els.length; i < len; ++i) { const el = els[i]; const info = el.getAttribute('info'); if(el.tagName === 'INPUT') { if(el.type === 'checkbox') { el.checked = !!Cfg[info]; } else { el.value = Cfg[info]; } } else { el.selectedIndex = Cfg[info]; } } }, // "Filters" tab _getCfgFilters() { return `
${ this._getBox('hideBySpell') } ${ Lng.add[lang] } ${ Lng.apply[lang] } ${ Lng.clear[lang] } [?]
${ this._getBox('sortSpells') }
${ this._getBox('hideRefPsts') }
${ this._getBox('nextPageThr') }
${ this._getSel('delHiddPost') }
`; }, // "Posts" tab _getCfgPosts() { return `
${ localData ? '' : `${ this._getBox('ajaxUpdThr') } ${ this._getInp('updThrDelay') }
${ this._getBox('updCount') }
${ this._getBox('favIcoBlink') }
${ 'Notification' in deWindow ? this._getBox('desktNotif') + '
' : '' } ${ this._getBox('noErrInTitle') }
${ this._getBox('markNewPosts') }
${ aib.dobrochan ? this._getBox('useDobrAPI') : '' }
` } ${ this._getBox('markMyPosts') }
${ !localData ? `${ this._getBox('expandTrunc') }
` : '' } ${ this._getSel('showHideBtn') }
${ !localData ? this._getSel('showRepBtn') : '' }
${ this._getSel('postBtnsCSS') } ${ this._getInp('postBtnsBack', false, 8) }
${ !localData ? this._getSel('thrBtns') : '' }
${ this._getSel('noSpoilers') }
${ this._getInp('limitPostMsg', true, 5) }
${ this._getBox('widePosts') }
${ this._getBox('noPostNames') }
${ this._getBox('correctTime') } ${ this._getInp('timeOffset', true, 1) } [?]
${ this._getInp('timePattern', true, 24) }
${ this._getInp('timeRPattern', true, 24) }
`; }, // "Images" tab _getCfgImages() { return `
${ this._getSel('expandImgs') }
${ this._getBox('imgNavBtns') }
${ this._getBox('imgInfoLink') }
${ this._getSel('resizeImgs') }
${ Post.sizing.dPxRatio > 1 ? this._getBox('resizeDPI') + '
' : '' } ${ this._getInp('minImgSize') }
${ this._getInp('zoomFactor') }
${ this._getBox('webmControl') }
${ this._getBox('webmTitles') }
${ this._getInp('webmVolume') }
${ this._getInp('minWebmWidth') }
${ nav.isPresto ? '' : this._getSel('preLoadImgs') + '
' } ${ nav.isPresto || aib._4chan ? '' : `
${ this._getBox('findImgFile') }
` } ${ this._getSel('openImgs') }
${ this._getBox('imgSrcBtns') }
${ this._getSel('imgNames') }
${ this._getInp('maskVisib') }
`; }, // "Links" tab _getCfgLinks() { return ``; }, // "Form" tab _getCfgForm() { return `
${ this._getBox('ajaxPosting') }
${ pr.form ? `
${ this._getBox('postSameImg') }
${ this._getBox('removeEXIF') }
${ this._getSel('removeFName') }
${ this._getBox('sendErrNotif') }
${ this._getBox('scrAfterRep') }
${ pr.files && !nav.isPresto ? this._getSel('fileInputs') : '' }
` : '' } ${ pr.form ? this._getSel('addPostForm') + '
' : '' } ${ pr.txta ? this._getBox('spacedQuote') + '
' : '' } ${ this._getBox('favOnReply') }
${ pr.subj ? this._getBox('warnSubjTrip') + '
' : '' } ${ pr.mail ? `${ this._getBox('addSageBtn') } ${ this._getBox('saveSage') }
` : '' } ${ pr.cap ? `${ aib.hasAltCaptcha ? `${ this._getBox('altCaptcha') }
` : '' } ${ this._getInp('capUpdTime') }
${ this._getSel('captchaLang') }
` : '' } ${ pr.txta ? `${ this._getSel('addTextBtns') } ${ !aib._4chan ? this._getBox('txtBtnsLoc') : '' }
` : '' } ${ pr.passw ? `${ this._getInp('passwValue', false, 9) } ${ this._getBox('userPassw') }
` : '' } ${ pr.name ? `${ this._getInp('nameValue', false, 9) } ${ this._getBox('userName') }
` : '' } ${ pr.rules || pr.passw || pr.name ? Lng.hide[lang] + (pr.rules ? this._getBox('noBoardRule') : '') + (pr.passw ? this._getBox('noPassword') : '') + (pr.name ? this._getBox('noName') : '') + (pr.subj ? this._getBox('noSubj') : '') : '' }
`; }, // "Common" tab _getCfgCommon() { return `
${ this._getSel('scriptStyle') }
${ this._getBox('userCSS') } [?]
${ 'animation' in docBody.style ? this._getBox('animation') + '
' : '' } ${ this._getBox('hotKeys') }
${ this._getInp('loadPages') }
${ this._getSel('panelCounter') }
${ this._getBox('rePageTitle') }
${ !localData ? `${ this._getBox('inftyScroll') }
${ this._getBox('hideReplies') }
${ this._getBox('scrollToTop') }
` : '' } ${ this._getBox('saveScroll') }
${ this._getSel('favThrOrder') }
${ this._getBox('favWinOn') }
${ this._getBox('closePopups') }
`; }, // "Info" tab _getCfgInfo() { const statsTable = this._getInfoTable([ [Lng.thrViewed[lang], Cfg.stats.view], [Lng.thrCreated[lang], Cfg.stats.op], [Lng.thrHidden[lang], HiddenThreads.getCount()], [Lng.postsSent[lang], Cfg.stats.reply] ], false); return `
v${ version }.${ commit }` + `${ nav.isESNext ? '.es6' : '' } | Homepage | Github |
${ statsTable }
${ this._getInfoTable(Logger.getLogData(false), true) }
${ !nav.hasWebStorage && !nav.isPresto && !localData || nav.hasGMXHR ? `
>> <<
${ this._getSel('updDollchan') }` : '' }
`; }, // Creates a label with checkbox for option switching _getBox: id => ``, // Creates a table for Info tab _getInfoTable: (data, needMs) => data.map(val => `
${ val[0] } ${ val[1] + (needMs ? 'ms' : '') }
`).join(''), // Creates a text input for text option values _getInp(id, addText = true, size = 2) { const el = doc.createElement('div'); el.appendChild($txt(Cfg[id])); // Escape HTML return ``; }, // Creates a menu with a list of checkboxes. Uses for popup window. _getList : arr => arrTags(arr, ''), // Creates a select for multiple option values _getSel : id => ``, // Creates a tab for tab bar _getTab: id => `
${ Lng.cfgTab[id][lang] }
`, // Switching the dependent inputs according to their parents _toggleDependant(state, arr) { let i = arr.length; const nState = !state; while(i--) { const el = $q(arr[i]); if(el) { el.disabled = nState; } } }, _updateCSS() { $delAll('#de-css, #de-css-dynamic, #de-css-user', doc.head); scriptCSS(); }, _updateDependant() { const fn = this._toggleDependant; fn(Cfg.ajaxUpdThr, [ 'input[info="updThrDelay"]', 'input[info="updCount"]', 'input[info="favIcoBlink"]', 'input[info="markNewPosts"]', 'input[info="desktNotif"]', 'input[info="noErrInTitle"]' ]); fn(Cfg.postBtnsCSS === 2, ['input[info="postBtnsBack"]']); fn(Cfg.expandImgs, [ 'input[info="imgNavBtns"]', 'input[info="imgInfoLink"]', 'input[info="resizeDPI"]', 'select[info="resizeImgs"]', 'input[info="minImgSize"]', 'input[info="zoomFactor"]', 'input[info="webmControl"]', 'input[info="webmTitles"]', 'input[info="webmVolume"]', 'input[info="minWebmWidth"]' ]); fn(Cfg.preLoadImgs, ['input[info="findImgFile"]']); fn(Cfg.linksNavig, [ 'input[info="linksOver"]', 'input[info="linksOut"]', 'input[info="markViewed"]', 'input[info="strikeHidd"]', 'input[info="noNavigHidd"]' ]); fn(Cfg.strikeHidd && Cfg.linksNavig, ['input[info="removeHidd"]']); fn(Cfg.embedYTube, [ 'input[info="YTubeWidth"]', 'input[info="YTubeHeigh"]', 'input[info="YTubeTitles"]', 'input[info="ytApiKey"]', 'input[info="addVimeo"]' ]); fn(Cfg.YTubeTitles, ['input[info="ytApiKey"]']); fn(Cfg.ajaxPosting, [ 'input[info="postSameImg"]', 'input[info="removeEXIF"]', 'select[info="removeFName"]', 'input[info="sendErrNotif"]', 'input[info="scrAfterRep"]', 'select[info="fileInputs"]' ]); fn(Cfg.addSageBtn, ['input[info="saveSage"]']); fn(Cfg.addTextBtns, ['input[info="txtBtnsLoc"]']); fn(Cfg.hotKeys, ['input[info="loadPages"]']); }, // Updates row counter in spells editor _updateRowMeter(node) { const top = node.scrollTop; const el = node.previousElementSibling; let num = el.numLines || 1; let i = 19; if(num - i < ((top / 12) | 0 + 1)) { let str = ''; while(i--) { str += `${ num++ }
`; } el.insertAdjacentHTML('beforeend', str); el.numLines = num; } el.scrollTop = top; } }; /* ==[ MenuPopups.js ]======================================================================================== POPUPS & MENU =========================================================================================================== */ function closePopup(data) { const el = typeof data === 'string' ? $id('de-popup-' + data) : data; if(el) { el.closeTimeout = null; if(Cfg.animation) { $animate(el, 'de-close', true); } else { el.remove(); } } } function $popup(id, txt, isWait = false) { let el = $id('de-popup-' + id); const buttonHTML = isWait ? '' : '\u2716 '; if(el) { $q('div', el).innerHTML = txt.trim(); $q('span', el).innerHTML = buttonHTML; if(!isWait && Cfg.animation) { $animate(el, 'de-blink'); } } else { el = $bEnd($id('de-wrapper-popup'), `
${ buttonHTML }
${ txt.trim() }
`); el.onclick = e => { let el = fixEventEl(e.target); el = el.tagName.toLowerCase() === 'svg' ? el.parentNode : el; if(el.className === 'de-popup-btn') { closePopup(el.parentNode); } }; if(Cfg.animation) { $animate(el, 'de-open'); } } if(Cfg.closePopups && !isWait && !id.includes('edit') && !id.includes('cfg')) { el.closeTimeout = setTimeout(closePopup, 6e3, el); } return el.lastElementChild; } // Adds button that calls a popup with the text editor. Useful to edit settings. function getEditButton(name, getDataFn, className = 'de-button') { return $btn(Lng.edit[lang], Lng.editInTxt[lang], () => getDataFn((val, isJSON, saveFn) => { // Create popup window with textarea. const el = $popup('edit-' + name, `${ Lng.editor[name][lang] }`); const ta = el.lastChild; ta.value = isJSON ? JSON.stringify(val, null, '\t') : val; // "Save" button. If there a JSON data, parses and saves on success. el.appendChild($btn(Lng.save[lang], Lng.saveChanges[lang], !isJSON ? saveFn.bind(ta) : () => { let data; try { data = JSON.parse(ta.value.trim().replace(/[\n\r\t]/g, '') || '{}'); } finally { if(!data) { $popup('err-invaliddata', Lng.invalidData[lang]); return; } saveFn(data); closePopup('edit-' + name); closePopup('err-invaliddata'); } })); }), className); } class Menu { constructor(parentEl, html, clickFn, isFixed = true) { this.onout = null; this.onover = null; this.onremove = null; this._closeTO = 0; const el = $bEnd(docBody, ``); const cr = parentEl.getBoundingClientRect(); const { style, offsetWidth: w, offsetHeight: h } = el; style.left = (isFixed ? 0 : deWindow.pageXOffset) + (cr.left + w < Post.sizing.wWidth ? cr.left : cr.right - w) + 'px'; style.top = (isFixed ? 0 : deWindow.pageYOffset) + (cr.bottom + h < Post.sizing.wHeight ? cr.bottom - 0.5 : cr.top - h + 0.5) + 'px'; style.removeProperty('visibility'); this._clickFn = clickFn; this._el = el; this.parentEl = parentEl; el.addEventListener('mouseover', this, true); el.addEventListener('mouseout', this, true); el.addEventListener('click', this); parentEl.addEventListener('mouseout', this); } static getMenuImgSrc(data) { let p; if(typeof data === 'string') { p = encodeURIComponent(data) + '" target="_blank">' + Lng.frameSearch[lang]; } else { const link = data.nextSibling; p = encodeURIComponent(data.getAttribute('de-href') || link.getAttribute('de-href') || link.href) + '" target="_blank">' + Lng.searchIn[lang]; } return arrTags([ `de-src-google" href="https://www.google.com/searchbyimage?image_url=${ p }Google`, `de-src-yandex" href="https://yandex.com/images/search?rpt=imageview&img_url=${ p }Yandex`, `de-src-tineye" href="https://tineye.com/search/?url=${ p }TinEye`, `de-src-saucenao" href="https://saucenao.com/search.php?url=${ p }SauceNAO`, `de-src-iqdb" href="https://iqdb.org/?url=${ p }IQDB`, `de-src-tracemoe" href="https://trace.moe/?auto&url=${ p }TraceMoe` ], '', ''); switch(el.id) { case 'de-btn-spell-add': return new Menu(el, `
${ fn('#words,#exp,#exph,#imgn,#ihash,#subj,#name,#trip,#img,#sage'.split(',')) }
${ fn('#op,#tlen,#all,#video,#vauthor,#num,#wipe,#rep,#outrep,
'.split(',')) }
`, ({ textContent: s }) => insertText($id('de-spell-txt'), s + (!aib.t || s === '#op' || s === '#rep' || s === '#outrep' ? '' : `[${ aib.b },${ aib.t }]`) + (Spells.needArg[Spells.names.indexOf(s.substr(1))] ? '(' : ''))); case 'de-panel-refresh': return new Menu(el, fn(Lng.selAjaxPages[lang]), el => Pages.loadPages(aProto.indexOf.call(el.parentNode.children, el) + 1)); case 'de-panel-savethr': return new Menu(el, fn($q(aib.qPostImg, DelForm.first.el) ? Lng.selSaveThr[lang] : [Lng.selSaveThr[lang][0]]), el => { if($id('de-popup-savethr')) { return; } const imgOnly = !!aProto.indexOf.call(el.parentNode.children, el); if(ContentLoader.isLoading) { $popup('savethr', Lng.loading[lang], true); ContentLoader.afterFn = () => ContentLoader.downloadThread(imgOnly); ContentLoader.popupId = 'savethr'; } else { ContentLoader.downloadThread(imgOnly); } }); case 'de-panel-audio-off': return new Menu(el, fn(Lng.selAudioNotif[lang]), el => { updater.enableUpdater(); updater.toggleAudio([3e4, 6e4, 12e4, 3e5][aProto.indexOf.call(el.parentNode.children, el)]); $id('de-panel-audio-off').id = 'de-panel-audio-on'; }); } } /* ==[ Hotkeys.js ]=========================================================================================== HOTKEYS =========================================================================================================== */ const HotKeys = { cPost : null, enabled : false, gKeys : null, lastPageOffset : 0, ntKeys : null, tKeys : null, version : 7, clearCPost() { this.cPost = null; this.lastPageOffset = 0; }, disableHotKeys() { if(this.enabled) { this.enabled = false; if(this.cPost) { this.cPost.unselect(); } this.clearCPost(); this.gKeys = this.ntKeys = this.tKeys = null; doc.removeEventListener('keydown', this, true); } }, enableHotKeys() { if(!this.enabled) { this.enabled = true; this._paused = false; Promise.resolve(this.readKeys()).then(keys => { if(this.enabled) { [,, this.gKeys, this.ntKeys, this.tKeys] = keys; doc.addEventListener('keydown', this, true); } }); } }, getDefaultKeys: () => [HotKeys.version, nav.isFirefox, [ // GLOBAL KEYS /* One post/thread above */ 0x004B /* = K */, /* One post/thread below */ 0x004A /* = J */, /* Reply or create thread */ 0x0052 /* = R */, /* Hide selected thread/post */ 0x0048 /* = H */, /* Open previous page/image */ 0x1025 /* = Ctrl+Left */, /* Send post (txt) */ 0x900D /* = Ctrl+Enter */, /* Open/close "Favorites" */ 0x4046 /* = Alt+F */, /* Open/close "Hidden" */ 0x4048 /* = Alt+H */, /* Open/close panel */ 0x0050 /* = P */, /* Mask/unmask images */ 0x0042 /* = B */, /* Open/close "Settings" */ 0x4053 /* = Alt+S */, /* Expand current image */ 0x0049 /* = I */, /* Bold text */ 0xC042 /* = Alt+B */, /* Italic text */ 0xC049 /* = Alt+I */, /* Strike text */ 0xC054 /* = Alt+T */, /* Spoiler text */ 0xC050 /* = Alt+P */, /* Code text */ 0xC043 /* = Alt+C */, /* Open next page/image */ 0x1027 /* = Ctrl+Right */, /* Open/close "Video" */ 0x4056 /* = Alt+V */ ], [// NON-THREAD KEYS /* One post above */ 0x004D /* = M */, /* One post below */ 0x004E /* = N */, /* Open thread */ 0x0056 /* = V */, /* Expand thread */ 0x0045 /* = E */ ], [// THREAD KEYS /* Update thread */ 0x0055 /* = U */ ]], handleEvent(e) { if(this._paused || e.metaKey) { return; } let idx; const isThr = aib.t; const el = e.target; const tag = el.tagName; const kc = e.keyCode | (e.ctrlKey ? 0x1000 : 0) | (e.shiftKey ? 0x2000 : 0) | (e.altKey ? 0x4000 : 0) | (tag === 'TEXTAREA' || tag === 'INPUT' && (el.type === 'text' || el.type === 'password') ? 0x8000 : 0); if(kc === 0x74 || kc === 0x8074) { // F5 if(isThr || $id('de-popup-load-pages')) { return; } AttachedImage.closeImg(); Pages.loadPages(+Cfg.loadPages); } else if(kc === 0x1B) { // ESC if(AttachedImage.viewer) { AttachedImage.closeImg(); return; } if(this.cPost) { this.cPost.unselect(); this.cPost = null; } if(isThr) { Post.clearMarks(); } this.lastPageOffset = 0; } else if(kc === 0x801B) { // ESC (txt) el.blur(); } else { let post; const globIdx = this.gKeys.indexOf(kc); switch(globIdx) { case 2: // Quick reply if(pr.form) { post = this.cPost || this._getFirstVisPost(false, true) || Thread.first.op; this.cPost = post; pr.showQuickReply(post, post.num, true, false); post.select(); } break; case 3: // Hide selected thread/post post = this._getFirstVisPost(false, true) || this._getNextVisPost(null, true, false); if(post) { post.setUserVisib(!post.isHidden); this._scroll(post, false, post.isOp); } break; case 4: // Open previous page/image if(AttachedImage.viewer) { AttachedImage.viewer.navigate(false); } else if(isThr || aib.page !== aib.firstPage) { deWindow.location.pathname = aib.getPageUrl(aib.b, isThr ? 0 : aib.page - 1); } break; case 5: // Send post (txt) if(el !== pr.txta && el !== pr.cap.textEl) { return; } pr.subm.click(); break; case 6: // Open/close "Favorites" toggleWindow('fav', false); break; case 7: // Open/close "Hidden" toggleWindow('hid', false); break; case 8: // Open/close panel $toggle($id('de-panel-buttons')); break; case 9: // Mask/unmask images toggleCfg('maskImgs'); updateCSS(); break; case 10: // Open/close "Settings" toggleWindow('cfg', false); break; case 11: // Expand current image post = this._getFirstVisPost(false, true) || this._getNextVisPost(null, true, false); if(post) { post.toggleImages(); } break; case 12: // Bold text (txt) if(el !== pr.txta) { return; } $id('de-btn-bold').click(); break; case 13: // Italic text (txt) if(el !== pr.txta) { return; } $id('de-btn-italic').click(); break; case 14: // Strike text (txt) if(el !== pr.txta) { return; } $id('de-btn-strike').click(); break; case 15: // Spoiler text (txt) if(el !== pr.txta) { return; } $id('de-btn-spoil').click(); break; case 16: // Code text (txt) if(el !== pr.txta) { return; } $id('de-btn-code').click(); break; case 17: // Open next page/image if(AttachedImage.viewer) { AttachedImage.viewer.navigate(true); } else if(!isThr) { const pageNum = DelForm.last.pageNum + 1; if(pageNum <= aib.lastPage) { deWindow.location.pathname = aib.getPageUrl(aib.b, pageNum); } } break; case 18: // Open/close "Videos" toggleWindow('vid', false); break; case -1: if(isThr) { idx = this.tKeys.indexOf(kc); if(idx === 0) { // Update thread updater.forceLoad(null); break; } return; } idx = this.ntKeys.indexOf(kc); if(idx === -1) { return; } else if(idx === 2) { // Open thread post = this._getFirstVisPost(false, true) || this._getNextVisPost(null, true, false); if(post) { if(typeof GM_openInTab === 'function') { GM_openInTab(aib.getThrUrl(aib.b, post.tNum), false, true); } else { deWindow.open(aib.getThrUrl(aib.b, post.tNum), '_blank'); } } break; } else if(idx === 3) { // Expand/collapse thread post = this._getFirstVisPost(false, true) || this._getNextVisPost(null, true, false); if(post) { if(post.thr.loadCount !== 0 && post.thr.op.next.count === 1) { const nextThr = post.thr.nextNotHidden; post.thr.loadPosts(visPosts, !!nextThr); post = (nextThr || post.thr).op; } else { post.thr.loadPosts('all'); post = post.thr.op; } scrollTo(deWindow.pageXOffset, deWindow.pageYOffset + post.top); if(this.cPost && this.cPost !== post) { this.cPost.unselect(); this.cPost = post; } } break; } /* falls through */ default: { const scrollToThr = !isThr && (globIdx === 0 || globIdx === 1); this._scroll(this._getFirstVisPost(scrollToThr, false), globIdx === 0 || idx === 0, scrollToThr); } } } $pd(e); e.stopPropagation(); }, pauseHotKeys() { this._paused = true; }, async readKeys() { const str = await getStored('DESU_keys'); if(!str) { return this.getDefaultKeys(); } let keys; try { keys = JSON.parse(str); } finally { if(!keys) { return this.getDefaultKeys(); } if(keys[0] !== this.version) { const tKeys = this.getDefaultKeys(); switch(keys[0]) { case 1: keys[2][11] = tKeys[2][11]; keys[4] = tKeys[4]; /* falls through */ case 2: keys[2][12] = tKeys[2][12]; keys[2][13] = tKeys[2][13]; keys[2][14] = tKeys[2][14]; keys[2][15] = tKeys[2][15]; keys[2][16] = tKeys[2][16]; /* falls through */ case 3: keys[2][17] = keys[3][3]; keys[3][3] = keys[3].splice(4, 1)[0]; /* falls through */ case 4: case 5: case 6: keys[2][18] = tKeys[2][18]; } keys[0] = this.version; setStored('DESU_keys', JSON.stringify(keys)); } if(keys[1] ^ nav.isFirefox) { const mapFunc = nav.isFirefox ? key => key === 189 ? 173 : key === 187 ? 61 : key === 186 ? 59 : key : key => key === 173 ? 189 : key === 61 ? 187 : key === 59 ? 186 : key; keys[1] = nav.isFirefox; keys[2] = keys[2].map(mapFunc); keys[3] = keys[3].map(mapFunc); setStored('DESU_keys', JSON.stringify(keys)); } return keys; } }, resume(keys) { [,, this.gKeys, this.ntKeys, this.tKeys] = keys; this._paused = false; }, _paused: false, _getNextVisPost(cPost, isOp, toUp) { if(isOp) { const thr = cPost ? toUp ? cPost.thr.prevNotHidden : cPost.thr.nextNotHidden : Thread.first.isHidden ? Thread.first.nextNotHidden : Thread.first; return thr ? thr.op : null; } return cPost ? cPost.getAdjacentVisPost(toUp) : Thread.first.isHidden || Thread.first.op.isHidden ? Thread.first.op.getAdjacentVisPost(toUp) : Thread.first.op; }, _getFirstVisPost(getThread, getFull) { if(this.lastPageOffset !== deWindow.pageYOffset) { let post = getThread ? Thread.first : Thread.first.op; while(post.top < 1) { const tPost = post.next; if(!tPost) { break; } post = tPost; } if(this.cPost) { this.cPost.unselect(); } this.cPost = getThread ? getFull ? post.op : post.op.prev : getFull ? post : post.prev; this.lastPageOffset = deWindow.pageYOffset; } return this.cPost; }, _scroll(post, toUp, toThread) { const next = this._getNextVisPost(post, toThread, toUp); if(!next) { if(!aib.t) { const pageNum = toUp ? DelForm.first.pageNum - 1 : DelForm.last.pageNum + 1; if(toUp ? pageNum >= aib.firstPage : pageNum <= aib.lastPage) { deWindow.location.pathname = aib.getPageUrl(aib.b, pageNum); } } return; } if(post) { post.unselect(); } if(toThread) { next.el.scrollIntoView(); } else { scrollTo(0, deWindow.pageYOffset + next.el.getBoundingClientRect().top - Post.sizing.wHeight / 2 + next.el.clientHeight / 2); } this.lastPageOffset = deWindow.pageYOffset; next.select(); this.cPost = next; } }; class KeyEditListener { constructor(popupEl, keys, allKeys) { this.cEl = null; this.cKey = -1; this.errorInput = false; const aInputs = [...$Q('.de-input-key', popupEl)]; for(let i = 0, len = allKeys.length; i < len; ++i) { const k = allKeys[i]; if(k !== 0) { for(let j = i + 1; j < len; ++j) { if(k === allKeys[j]) { aInputs[i].classList.add('de-input-error'); aInputs[j].classList.add('de-input-error'); break; } } } } this.popupEl = popupEl; this.keys = keys; this.initKeys = JSON.parse(JSON.stringify(keys)); this.allKeys = allKeys; this.allInputs = aInputs; this.errCount = $Q('.de-input-error', popupEl).length; if(this.errCount !== 0) { this.saveButton.disabled = true; } } static getEditMarkup(keys) { const allKeys = []; return [allKeys, `${ Lng.hotKeyEdit[lang].join('') .replace(/%l/g, '') .replace(/%i([2-4])([0-9]+)(t)?/g, (all, id1, id2, isText) => { const key = keys[+id1][+id2]; allKeys.push(key); return ``; }) }` + ``]; } static getStrKey(key) { return (key & 0x1000 ? 'Ctrl+' : '') + (key & 0x2000 ? 'Shift+' : '') + (key & 0x4000 ? 'Alt+' : '') + KeyEditListener.keyCodes[key & 0xFFF]; } static setTitle(el, idx) { let title = el.getAttribute('de-title'); if(!title) { title = el.getAttribute('title'); el.setAttribute('de-title', title); } if(HotKeys.enabled && idx !== -1) { title += ` [${ KeyEditListener.getStrKey(HotKeys.gKeys[idx]) }]`; } el.title = title; } get saveButton() { const value = $id('de-keys-save'); Object.defineProperty(this, 'saveButton', { value, configurable: true }); return value; } handleEvent(e) { let key, el = e.target; switch(e.type) { case 'blur': if(HotKeys.enabled && this.errCount === 0) { HotKeys.resume(this.keys); } el.classList.remove('de-input-selected'); this.cEl = null; return; case 'focus': if(HotKeys.enabled) { HotKeys.pauseHotKeys(); } el.classList.add('de-input-selected'); this.cEl = el; return; case 'click': { let keys; if(el.id === 'de-keys-reset') { this.keys = HotKeys.getDefaultKeys(); this.initKeys = HotKeys.getDefaultKeys(); if(HotKeys.enabled) { HotKeys.resume(this.keys); } [this.allKeys, this.popupEl.innerHTML] = KeyEditListener.getEditMarkup(this.keys); this.allInputs = [...$Q('.de-input-key', this.popupEl)]; this.errCount = 0; delete this.saveButton; break; } else if(el.id === 'de-keys-save') { ({ keys } = this); setStored('DESU_keys', JSON.stringify(keys)); } else if(el.className === 'de-popup-btn') { keys = this.initKeys; } else { return; } if(HotKeys.enabled) { HotKeys.resume(keys); } closePopup('edit-hotkeys'); break; } case 'keydown': { if(!this.cEl) { return; } key = e.keyCode; if(key === 0x1B || key === 0x2E) { // ESC, DEL this.cEl.value = ''; this.cKey = 0; this.errorInput = false; break; } const keyStr = KeyEditListener.keyCodes[key]; if(keyStr === undefined) { this.cKey = -1; return; } let str = ''; if(e.ctrlKey) { str += 'Ctrl+'; } if(e.shiftKey) { str += 'Shift+'; } if(e.altKey) { str += 'Alt+'; } if(key === 16 || key === 17 || key === 18) { this.errorInput = true; this.cKey = 0; } else { this.cKey = key | (e.ctrlKey ? 0x1000 : 0) | (e.shiftKey ? 0x2000 : 0) | (e.altKey ? 0x4000 : 0) | (this.cEl.hasAttribute('de-text') ? 0x8000 : 0); this.errorInput = false; str += keyStr; } this.cEl.value = str; break; } case 'keyup': { el = this.cEl; key = this.cKey; if(!el || key === -1) { return; } let rEl; const isError = el.classList.contains('de-input-error'); if(!this.errorInput && key !== -1) { let idx = this.allInputs.indexOf(el); const oKey = this.allKeys[idx]; if(oKey === key) { this.errorInput = false; break; } const rIdx = key === 0 ? -1 : this.allKeys.indexOf(key); this.allKeys[idx] = key; if(isError) { idx = this.allKeys.indexOf(oKey); if(idx !== -1 && this.allKeys.indexOf(oKey, idx + 1) === -1) { rEl = this.allInputs[idx]; if(rEl.classList.contains('de-input-error')) { this.errCount--; rEl.classList.remove('de-input-error'); } } if(rIdx === -1) { this.errCount--; el.classList.remove('de-input-error'); } } if(rIdx === -1) { this.keys[+el.getAttribute('de-id1')][+el.getAttribute('de-id2')] = key; if(this.errCount === 0) { this.saveButton.disabled = false; } this.errorInput = false; break; } rEl = this.allInputs[rIdx]; if(!rEl.classList.contains('de-input-error')) { this.errCount++; rEl.classList.add('de-input-error'); } } if(!isError) { this.errCount++; el.classList.add('de-input-error'); } if(this.errCount !== 0) { this.saveButton.disabled = true; } } } $pd(e); } } // Browsers have different codes for these keys (see HotKeys.readKeys): // Firefox - '-' - 173, '=' - 61, ';' - 59 // Chrome/Opera: '-' - 189, '=' - 187, ';' - 186 /* eslint-disable comma-spacing, comma-style, no-sparse-arrays */ KeyEditListener.keyCodes = [ '',,,,,,,,'Backspace','Tab',,,,'Enter',,,'Shift','Ctrl','Alt',/* Pause/Break */,/* Caps Lock */,,,,,,, /* Esc */,,,,,'Space',/* PgUp */,/* PgDn */,/* End */,/* Home */,'←','↑','→','↓',,,,,/* Insert */, /* Del */,,'0','1','2','3','4','5','6','7','8','9',,';',,'=',,,,'A','B','C','D','E','F','G','H','I','J', 'K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',/* Left WIN */,/* Right WIN */, /* Select */,,,'Num 0','Num 1','Num 2','Num 3','Num 4','Num 5','Num 6','Num 7','Num 8','Num 9','Num *', 'Num +',,'Num -','Num .','Num /',/* F1 */,/* F2 */,/* F3 */,/* F4 */,/* F5 */,/* F6 */,/* F7 */,/* F8 */, /* F9 */,/* F10 */,/* F11 */,/* F12 */,,,,,,,,,,,,,,,,,,,,,/* Num Lock */,/* Scroll Lock */,,,,,,,,,,,,,,, ,,,,,,,,,,,,,'-',,,,,,,,,,,,,';','=',',','-','.','/','`',,,,,,,,,,,,,,,,,,,,,,,,,,,'[','\\',']',"'" ]; /* eslint-enable comma-spacing, comma-style, no-sparse-arrays */ /* ==[ ContentLoad.js ]======================================================================================= CONTENT DOWNLOADING images/video preloading, rarjpeg detecting, thread/images downloading =========================================================================================================== */ const ContentLoader = { afterFn : null, isLoading : false, popupId : null, downloadThread(imgOnly) { let progress, counter, current = 1, warnings = '', tar = new TarBuilder(); const dc = imgOnly ? doc : doc.documentElement.cloneNode(true); let els = [...$Q(aib.qPostImg, $q('[de-form]', dc))]; let count = els.length; this._thrPool = new TasksPool(4, (num, data) => this.loadImgData(data[0]).then(imgData => { const [url, fName, el, imgLink] = data; let safeName = fName.replace(/[\\/:*?"<>|]/g, '_'); progress.value = counter.innerHTML = current++; if(imgLink) { let thumbName = safeName.replace(/\.[a-z]+$/, '.png'); if(imgOnly) { thumbName = 'thumb-' + thumbName; } else { thumbName = 'thumbs/' + thumbName; safeName = imgData ? 'images/' + safeName : thumbName; imgLink.href = $q('a[de-href], ' + aib.qImgNameLink, aib.getImgWrap(el)).href = safeName; } if(imgData) { tar.addFile(safeName, imgData); } else { warnings += `
${ Lng.cantLoad[lang] }
${ url }` + `
${ Lng.willSavePview[lang] }`; $popup('err-files', Lng.loadErrors[lang] + warnings); if(imgOnly) { return this.getDataFromImg(el).then(data => tar.addFile(thumbName, data), emptyFn); } } return imgOnly ? null : this.getDataFromImg(el).then(data => { el.src = thumbName; tar.addFile(thumbName, data); }, () => (el.src = safeName)); } else if(imgData && imgData.length > 0) { tar.addFile(el.href = el.src = 'data/' + safeName, imgData); } else { $del(el); } }), () => { const docName = `${ aib.dm }-${ aib.b.replace(/[\\/:*?"<>|]/g, '') }-${ aib.t }`; if(!imgOnly) { $q('head', dc).insertAdjacentHTML('beforeend', ''); const dcBody = $q('body', dc); dcBody.classList.remove('de-runned'); dcBody.classList.add('de-mode-local'); $delAll('#de-css, #de-css-dynamic, #de-css-user', dc); tar.addString('data/dollscript.js', `${ nav.isESNext ? `(${ String(deMainFuncInner) })(window, null, null, (x, y) => window.scrollTo(x, y), ` : `(${ String(/* global deMainFuncOuter */ deMainFuncOuter) })(` }${ JSON.stringify({ dm: aib.dm, b: aib.b, t: aib.t }) });`); const dt = doc.doctype; tar.addString(docName + '.html', '' + dc.outerHTML); } downloadBlob(tar.get(), docName + (imgOnly ? '-images.tar' : '.tar')); closePopup('load-files'); this._thrPool = tar = warnings = count = current = imgOnly = progress = counter = null; }); els.forEach(el => { const imgLink = $parent(el, 'A'); if(imgLink) { const url = imgLink.href; this._thrPool.runTask([url, imgLink.getAttribute('download') || url.substring(url.lastIndexOf('/') + 1), el, imgLink]); } }); if(!imgOnly) { $delAll('#de-main, .de-parea, .de-post-btns, .de-btn-src, .de-refmap, .de-thr-buttons, ' + '.de-video-obj, #de-win-reply, link[rel="alternate stylesheet"], script, ' + aib.qForm, dc); $each($Q('a', dc), el => { let num; const tc = el.textContent; if(tc[0] === '>' && tc[1] === '>' && (num = +tc.substr(2)) && pByNum.has(num)) { el.href = aib.anchor + num; if(!el.classList.contains('de-link-postref')) { el.className = 'de-link-postref ' + el.className; } } else { el.href = getAbsLink(el.href); } }); $each($Q(aib.qRPost, dc), (el, i) => el.setAttribute('de-num', i ? aib.getPNum(el) : aib.t)); const files = []; const urlRegex = new RegExp(`^\\/\\/?|^https?:\\/\\/([^\\/]*\\.)?${ quoteReg(aib._4chan ? '4cdn.org' : aib.dm) }\\/`, 'i'); $each($Q('link, *[src]', dc), el => { if(els.indexOf(el) !== -1) { return; } let url = el.tagName === 'LINK' ? el.href : el.src; if(!urlRegex.test(url)) { el.remove(); return; } let fName = url.substring(url.lastIndexOf('/') + 1) .replace(/[\\/:*?"<>|]/g, '_').toLowerCase(); if(files.indexOf(fName) !== -1) { let temp = url.lastIndexOf('.'); const ext = url.substring(temp); url = url.substring(0, temp); fName = fName.substring(0, fName.lastIndexOf('.')); for(let i = 0; ; ++i) { temp = `${ fName }(${ i })${ ext }`; if(files.indexOf(temp) === -1) { break; } } fName = temp; } files.push(fName); this._thrPool.runTask([url, fName, el, null]); count++; }); } $popup('load-files', `${ imgOnly ? Lng.loadImage[lang] : Lng.loadFile[lang] }:
1/${ count }`, true); progress = $id('de-loadprogress'); counter = progress.nextElementSibling; this._thrPool.completeTasks(); els = null; }, getDataFromImg(el) { try { const cnv = this._canvas || (this._canvas = doc.createElement('canvas')); cnv.width = el.width || el.videoWidth; cnv.height = el.height || el.videoHeight; cnv.getContext('2d').drawImage(el, 0, 0); return Promise.resolve(new Uint8Array(atob(cnv.toDataURL('image/png').split(',')[1]) .split('').map(a => a.charCodeAt()))); } catch(err) { return this.loadImgData(el.src); } }, loadImgData: (url, repeatOnError = true) => $ajax( url, { responseType: 'arraybuffer' }, !url.startsWith('blob') ).then(xhr => { if('response' in xhr) { try { return nav.getUnsafeUint8Array(xhr.response); } catch(err) {} } const txt = xhr.responseText; return new Uint8Array(txt.length).map((val, i) => txt.charCodeAt(i) & 0xFF); }, err => err.code !== 404 && repeatOnError ? ContentLoader.loadImgData(url, false) : null), preloadImages(data) { if(!Cfg.preLoadImgs && !Cfg.openImgs && !isPreImg) { return; } let preloadPool; const isPost = data instanceof AbstractPost; const els = $Q(aib.qPostImg, isPost ? data.el : data); const len = els.length; if(isPreImg || Cfg.preLoadImgs) { let cImg = 1; const mReqs = isPost ? 1 : 4; const rarJpgFinder = (isPreImg || Cfg.findImgFile) && new WorkerPool(mReqs, this._detectImgFile, err => console.error('File detector error:', `line: ${ err.lineno } - ${ err.message }`)); preloadPool = new TasksPool(mReqs, (num, data) => this.loadImgData(data[0]).then(imageData => { const [url, imgLink, iType, isRepToOrig, el, isVideo] = data; if(imageData) { const fName = url.substring(url.lastIndexOf('/') + 1); const nameLink = $q(aib.qImgNameLink, aib.getImgWrap(el)); imgLink.setAttribute('download', fName); if(!Cfg.imgNames) { nameLink.setAttribute('download', fName); nameLink.setAttribute('de-href', nameLink.href); } imgLink.href = nameLink.href = deWindow.URL.createObjectURL(new Blob([imageData], { type: iType })); if(isVideo) { el.setAttribute('de-video', ''); } if(isRepToOrig) { el.src = imgLink.href; } if(rarJpgFinder) { rarJpgFinder.runWorker(imageData.buffer, [imageData.buffer], info => this._addImgFileIcon(nameLink, fName, info)); } } if(this.popupId) { $popup(this.popupId, `${ Lng.loadImage[lang] }: ${ cImg }/${ len }`, true); } cImg++; }), () => { this.isLoading = false; if(this.afterFn) { this.afterFn(); this.afterFn = this.popupId = null; } if(rarJpgFinder) { rarJpgFinder.clearWorkers(); } }); this.isLoading = true; } for(let i = 0; i < len; ++i) { const el = els[i]; const imgLink = $parent(el, 'A'); if(!imgLink) { continue; } let isRepToOrig = !!Cfg.openImgs; const url = imgLink.href; const type = getFileType(url); const isVideo = type && (type === 'video/webm' || type === 'video/mp4' || type === 'video/ogv'); if(!type || isVideo && Cfg.preLoadImgs === 2) { continue; } else if(type === 'image/gif') { isRepToOrig &= Cfg.openImgs !== 3; } else { if(isVideo) { isRepToOrig = false; } isRepToOrig &= Cfg.openImgs !== 2; } if(preloadPool) { preloadPool.runTask([url, imgLink, type, isRepToOrig, el, isVideo]); } else if(isRepToOrig) { el.src = url; } } if(preloadPool) { preloadPool.completeTasks(); } }, _canvas : null, _thrPool : null, _addImgFileIcon(nameLink, fName, info) { const { type } = info; if(typeof type === 'undefined') { return; } const ext = ['7z', 'zip', 'rar', 'ogg', 'mp3'][type]; nameLink.insertAdjacentHTML('afterend', `.${ ext }`); }, // Finds built-in files in jpg and png _detectImgFile: arrBuf => { let i, j; const dat = new Uint8Array(arrBuf); let len = dat.length; /* JPG [ff d8 ff e0] = [яШяа] */ if(dat[0] === 0xFF && dat[1] === 0xD8) { for(i = 0, j = 0; i < len - 1; ++i) { if(dat[i] === 0xFF) { /* Built-in JPG */ if(dat[i + 1] === 0xD8) { j++; /* JPG end [ff d9] */ } else if(dat[i + 1] === 0xD9 && --j === 0) { i += 2; break; } } } /* PNG [89 50 4e 47] = [‰PNG] */ } else if(dat[0] === 0x89 && dat[1] === 0x50) { for(i = 0; i < len - 7; ++i) { /* PNG end [49 45 4e 44 ae 42 60 82] */ if(dat[i] === 0x49 && dat[i + 1] === 0x45 && dat[i + 2] === 0x4E && dat[i + 3] === 0x44) { i += 8; break; } } } else { return {}; } if(i === len || len - i <= 60) { // Ignore small files (<60 bytes) return {}; } for(len = i + 90; i < len; ++i) { /* 7Z [37 7a bc af] = [7zјЇ] */ if(dat[i] === 0x37 && dat[i + 1] === 0x7A && dat[i + 2] === 0xBC) { return { type: 0, idx: i, data: arrBuf }; /* ZIP [50 4b 03 04] = [PK..] */ } else if(dat[i] === 0x50 && dat[i + 1] === 0x4B && dat[i + 2] === 0x03) { return { type: 1, idx: i, data: arrBuf }; /* RAR [52 61 72 21] = [Rar!] */ } else if(dat[i] === 0x52 && dat[i + 1] === 0x61 && dat[i + 2] === 0x72) { return { type: 2, idx: i, data: arrBuf }; /* OGG [4f 67 67 53] = [OggS] */ } else if(dat[i] === 0x4F && dat[i + 1] === 0x67 && dat[i + 2] === 0x67) { return { type: 3, idx: i, data: arrBuf }; /* MP3 [0x49 0x44 0x33] = [ID3] */ } else if(dat[i] === 0x49 && dat[i + 1] === 0x44 && dat[i + 2] === 0x33) { return { type: 4, idx: i, data: arrBuf }; } } return {}; } }; /* ==[ TimeCorrection.js ]==================================================================================== TIME CORRECTION =========================================================================================================== */ class DateTime { constructor(pattern, rPattern, diff, dtLang, onRPat) { this.pad2 = pad2; this.genDateTime = null; this.onRPat = null; if(DateTime.checkPattern(pattern)) { this.disabled = true; return; } this.regex = pattern .replace(/(?:[sihdny]\?){2,}/g, str => `(?:${ str.replace(/\?/g, '') })?`) .replace(/-/g, '[^<]') .replace(/\+/g, '[^0-9<]') .replace(/([sihdny]+)/g, '($1)') .replace(/[sihdny]/g, '\\d') .replace(/m|w/g, '([a-zA-Zа-яА-Я]+)'); this.pattern = pattern.replace(/[?\-+]+/g, '').replace(/([a-z])\1+/g, '$1'); this.diff = parseInt(diff, 10); this.arrW = Lng.week[dtLang]; this.arrM = Lng.month[dtLang]; this.arrFM = Lng.fullMonth[dtLang]; if(rPattern) { this.genDateTime = this.genRFunc(rPattern); } else { this.onRPat = onRPat; } } static checkPattern(val) { return !val.includes('i') || !val.includes('h') || !val.includes('d') || !val.includes('y') || !(val.includes('n') || val.includes('m')) || /[^?\-+sihdmwny]|mm|ww|\?\?|([ihdny]\?)\1+/.test(val); } static toggleSettings(el) { if(el.checked && (!/^[+-]\d{1,2}$/.test(Cfg.timeOffset) || DateTime.checkPattern(Cfg.timePattern))) { $popup('err-correcttime', Lng.cTimeError[lang]); saveCfg('correctTime', 0); el.checked = false; } } genRFunc(rPattern) { return dtime => rPattern.replace('_o', (this.diff < 0 ? '' : '+') + this.diff) .replace('_s', () => this.pad2(dtime.getSeconds())) .replace('_i', () => this.pad2(dtime.getMinutes())) .replace('_h', () => this.pad2(dtime.getHours())) .replace('_d', () => this.pad2(dtime.getDate())) .replace('_w', () => this.arrW[dtime.getDay()]) .replace('_n', () => this.pad2(dtime.getMonth() + 1)) .replace('_m', () => this.arrM[dtime.getMonth()]) .replace('_M', () => this.arrFM[dtime.getMonth()]) .replace('_y', () => ('' + dtime.getFullYear()).substring(2)) .replace('_Y', () => dtime.getFullYear()); } getRPattern(txt) { const m = txt.match(new RegExp(this.regex)); if(!m) { this.disabled = true; return false; } let rPattern = ''; for(let i = 1, len = m.length, j = 0, str = m[0]; i < len;) { const a = m[i++]; if(!a) { continue; } let p = this.pattern[i - 2]; if((p === 'm' || p === 'y') && a.length > 3) { p = p.toUpperCase(); } const k = str.indexOf(a, j); rPattern += str.substring(j, k) + '_' + p; j = k + a.length; } if(this.onRPat) { this.onRPat(rPattern); } this.genDateTime = this.genRFunc(rPattern); return true; } fix(txt) { if(this.disabled || (!this.genDateTime && !this.getRPattern(txt))) { return txt; } return txt.replace(new RegExp(this.regex, 'g'), (str, ...args) => { let second, minute, hour, day, month, year; for(let i = 0; i < 7; ++i) { const a = args[i]; switch(this.pattern[i]) { case 's': second = a; break; case 'i': minute = a; break; case 'h': hour = a; break; case 'd': day = a; break; case 'n': month = a - 1; break; case 'y': year = a; break; case 'm': month = Lng.monthDict[a.slice(0, 3).toLowerCase()] || 0; break; } } const dtime = new Date(year.length === 2 ? '20' + year : year, month, day, hour, minute, second || 0); dtime.setHours(dtime.getHours() + this.diff); return this.genDateTime(dtime); }); } } /* ==[ Players.js ]=========================================================================================== PLAYERS / LINKS EMBEDDERS youtube, vimeo, mp3, vocaroo embedding players =========================================================================================================== */ class Videos { constructor(post, player = null, playerInfo = null) { this.currentLink = null; this.hasLinks = false; this.linksCount = 0; this.loadedLinksCount = 0; this.playerInfo = null; this.post = post; this.titleLoadFn = null; this.vData = [[], []]; if(player && playerInfo) { Object.defineProperty(this, 'player', { value: player }); this.playerInfo = playerInfo; } } static addPlayer(obj, m, isYtube, enableJsapi = false) { const el = obj.player; obj.playerInfo = m; let txt; if(isYtube) { const list = m[0].match(/list=[^&#]+/); txt = `'; } else { const id = m[1] + (m[2] ? m[2] : ''); txt = ``; } el.innerHTML = txt + (enableJsapi ? '' : ``); $show(el); if(!enableJsapi) { el.lastChild.onclick = e => e.target.parentNode.classList.toggle('de-video-expanded'); } } static setLinkData(link, data, isCloned = false) { const [title, author, views, publ, duration] = data; if(Panel.isVidEnabled && !isCloned) { const clonedLink = $q(`.de-entry > .de-video-link[href="${ link.href }"]:not(title)`); if(clonedLink) { Videos.setLinkData(clonedLink, data, true); } } link.textContent = title; link.classList.add('de-video-title'); link.setAttribute('de-author', author); link.title = (duration ? Lng.duration[lang] + duration : '') + (publ ? `, ${ Lng.published[lang] + publ }\n` : '') + Lng.author[lang] + author + (views ? ', ' + Lng.views[lang] + views : ''); } get player() { const { post } = this; const value = aib.insertYtPlayer(post.msg, `
`); Object.defineProperty(this, 'player', { value }); return value; } addLink(m, loader, link, isYtube) { this.hasLinks = true; this.linksCount++; if(this.playerInfo === null) { if(Cfg.embedYTube === 1) { this._addThumb(m, isYtube); } } else if(!link && $q(`.de-video-link[href*="${ m[1] }"]`, this.post.msg)) { return; } let dataObj; if(loader && (dataObj = Videos._global.vData[+!isYtube][m[1]])) { this.vData[+!isYtube].push(dataObj); } let time = ''; [time, m[2], m[3], m[4]] = Videos._fixTime(m[4], m[3], m[2]); if(link) { link.href = link.href.replace(/^http:/, 'https:'); if(time) { link.setAttribute('de-time', time); } link.className = `de-video-link ${ isYtube ? 'de-ytube' : 'de-vimeo' }`; } else { const src = isYtube ? `${ aib.prot }//www.youtube.com/watch?v=${ m[1] }${ time ? '#t=' + time : '' }` : `${ aib.prot }//vimeo.com/${ m[1] }`; link = $bEnd(this.post.msg, `

${ dataObj ? '' : src }

`).firstChild; } if(dataObj) { Videos.setLinkData(link, dataObj); } if(this.playerInfo === null || this.playerInfo === m) { this.currentLink = link; } link.videoInfo = m; let vidListEl; if(Panel.isVidEnabled && (vidListEl = $id('de-video-list'))) { updateVideoList(vidListEl, link, this.post.num); } if(loader && !dataObj) { loader.runTask([link, isYtube, this, m[1]]); } } clickLink(el, mode) { const m = el.videoInfo; if(this.playerInfo !== m) { this.currentLink.classList.remove('de-current'); this.currentLink = el; if(mode === 1) { this._addThumb(m, el.classList.contains('de-ytube')); } else { el.classList.add('de-current'); this.setPlayer(m, el.classList.contains('de-ytube')); } return; } if(mode === 1) { if($q('.de-video-thumb', this.player)) { el.classList.add('de-current'); this.setPlayer(m, el.classList.contains('de-ytube')); } else { el.classList.remove('de-current'); this._addThumb(m, el.classList.contains('de-ytube')); } } else { el.classList.remove('de-current'); $hide(this.player); this.player.innerHTML = ''; this.playerInfo = null; } } setPlayer(m, isYtube) { Videos.addPlayer(this, m, isYtube); } toggleFloatedThumb(linkEl, isOutEvent) { let el = $id('de-video-thumb-floated'); if(isOutEvent) { $del(el); return; } if(!el) { el = $bEnd(docBody, ``); } const cr = linkEl.getBoundingClientRect(); const pvHeight = Cfg.YTubeHeigh; const isTop = cr.top + cr.height + pvHeight < nav.viewportHeight(); el.style.cssText = `position: absolute; left: ${ deWindow.pageXOffset + cr.left }px; top: ${ deWindow.pageYOffset + (isTop ? cr.top + cr.height : cr.top - pvHeight) }px; width: ${ Cfg.YTubeWidth }px; height: ${ pvHeight }px; z-index: 9999;`; } updatePost(oldLinks, newLinks, cloned) { const loader = !cloned && Videos._getTitlesLoader(); let j = 0; for(let i = 0, len = newLinks.length; i < len; ++i) { const el = newLinks[i]; const link = oldLinks[j]; if(link && link.classList.contains('de-current')) { this.currentLink = el; } if(cloned) { el.videoInfo = link.videoInfo; j++; } else { const m = el.href.match(Videos.ytReg); if(m) { this.addLink(m, loader, el, true); j++; } } } this.currentLink = this.currentLink || newLinks[0]; if(loader) { loader.completeTasks(); } } static _fixTime(seconds = 0, minutes = 0, hours = 0) { if(seconds >= 60) { minutes += Math.floor(seconds / 60); seconds %= 60; } if(minutes >= 60) { hours += Math.floor(seconds / 60); minutes %= 60; } return [ (hours ? hours + 'h' : '') + (minutes ? minutes + 'm' : '') + (seconds ? seconds + 's' : ''), hours, minutes, seconds ]; } static _getTitlesLoader() { return Cfg.YTubeTitles && new TasksPool(4, (num, info) => { const [, isYtube,, id] = info; if(isYtube) { return Cfg.ytApiKey ? Videos._getYTInfoAPI(info, num, id) : Videos._getYTInfoOembed(info, num, id); } return $ajax(`${ aib.prot }//vimeo.com/api/v2/video/${ id }.json`, null, true).then(xhr => { const entry = JSON.parse(xhr.responseText)[0]; return Videos._titlesLoaderHelper( info, num, entry.title, entry.user_name, entry.stats_number_of_plays, /(.*)\s(.*)?/.exec(entry.upload_date)[1], Videos._fixTime(entry.duration)[0]); }).catch(() => Videos._titlesLoaderHelper(info, num)); }, () => (sesStorage['de-videos-data2'] = JSON.stringify(Videos._global.vData))); } static _getYTInfoAPI(info, num, id) { return $ajax( `https://www.googleapis.com/youtube/v3/videos?key=${ Cfg.ytApiKey }&id=${ id }` + '&part=snippet,statistics,contentDetails&fields=items/snippet/title,items/snippet/publishedAt,' + 'items/snippet/channelTitle,items/statistics/viewCount,items/contentDetails/duration', null, true ).then(xhr => { const items = JSON.parse(xhr.responseText).items[0]; return Videos._titlesLoaderHelper( info, num, items.snippet.title, items.snippet.channelTitle, items.statistics.viewCount, items.snippet.publishedAt.substr(0, 10), items.contentDetails.duration.substr(2).toLowerCase()); }).catch(() => Videos._getYTInfoOembed(info, num, id)); } static _getYTInfoOembed(info, num, id) { const canSendCORS = nav.hasGMXHR || nav.canUseFetch; return (canSendCORS ? $ajax(`https://www.youtube.com/oembed?url=http%3A//youtube.com/watch%3Fv%3D${ id }&format=json`, null, true) : $ajax(`https://noembed.com/embed?url=http%3A//youtube.com/watch%3Fv%3D${ id }&callback=?`) ).then(xhr => { const res = xhr.responseText; const json = JSON.parse(canSendCORS ? res : res.replace(/^[^{]+|\)$/g, '')); return Videos._titlesLoaderHelper(info, num, json.title, json.author_name, null, null, null); }).catch(() => Videos._titlesLoaderHelper(info, num)); } static _titlesLoaderHelper([link, isYtube, videoObj, id], num, ...data) { if(data.length !== 0) { Videos.setLinkData(link, data); Videos._global.vData[+!isYtube][id] = data; videoObj.vData[+!isYtube].push(data); if(videoObj.titleLoadFn) { videoObj.titleLoadFn(data); } } videoObj.loadedLinksCount++; // Wait for 3 sec every 30 links if(num % 30 === 0) { return Promise.reject(new TasksPool.PauseError(3e3)); } return new Promise(resolve => setTimeout(resolve, 250)); } _addThumb(m, isYtube) { const el = this.player; this.playerInfo = m; el.classList.remove('de-video-expanded'); $show(el); const str = `` + ``; return; } el.innerHTML = `${ str }//vimeo.com/${ m[1] }" target="_blank">` + ''; $ajax(`${ aib.prot }//vimeo.com/api/v2/video/${ m[1] }.json`, null, true).then(xhr => { el.firstChild.firstChild.setAttribute('src', JSON.parse(xhr.responseText)[0].thumbnail_large); }).catch(emptyFn); } } Videos.ytReg = /^https?:\/\/(?:www\.|m\.)?youtu(?:be\.com\/(?:watch\?.*?v=|v\/|embed\/)|\.be\/)([a-zA-Z0-9-_]+).*?(?:t(?:ime)?=(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?)?$/; Videos.vimReg = /^https?:\/\/(?:www\.)?vimeo\.com\/(?:[^?]+\?clip_id=|.*?\/)?(\d+).*?(#t=\d+)?$/; Videos._global = { get vData() { let value; try { value = Cfg.YTubeTitles ? JSON.parse(sesStorage['de-videos-data2'] || '[{}, {}]') : [{}, {}]; } catch(err) { value = [{}, {}]; } Object.defineProperty(this, 'vData', { value }); return value; } }; class VideosParser { constructor() { this._loader = Videos._getTitlesLoader(); } endParser() { if(this._loader) { this._loader.completeTasks(); } } parse(data) { const isPost = data instanceof AbstractPost; const loader = this._loader; VideosParser._parserHelper('a[href*="youtu"]', data, loader, isPost, true, Videos.ytReg); if(Cfg.addVimeo) { VideosParser._parserHelper('a[href*="vimeo.com"]', data, loader, isPost, false, Videos.vimReg); } const vids = aib.fixVideo(isPost, data); for(let i = 0, len = vids.length; i < len; ++i) { const [post, m, isYtube] = vids[i]; if(post) { post.videos.addLink(m, loader, null, isYtube); } } return this; } static _parserHelper(qPath, data, loader, isPost, isYtube, reg) { const links = $Q(qPath, isPost ? data.el : data); for(let i = 0, len = links.length; i < len; ++i) { const link = links[i]; const m = link.href.match(reg); if(m) { const mPost = isPost ? data : aib.getPostOfEl(link); if(mPost) { mPost.videos.addLink(m, loader, link, isYtube); } } } } } // Embed .mp3 and Vocaroo links function embedAudioLinks(data) { const isPost = data instanceof AbstractPost; if(Cfg.addMP3) { const els = $Q('a[href*=".mp3"]', isPost ? data.el : data); for(let i = 0, len = els.length; i < len; ++i) { const link = els[i]; if((link.target !== '_blank' && link.rel !== 'nofollow') || !link.pathname.includes('.mp3')) { continue; } const src = link.href; const el = (isPost ? data : aib.getPostOfEl(link)).mp3Obj; if(nav.canPlayMP3) { if(!$q(`audio[src="${ src }"]`, el)) { el.insertAdjacentHTML('beforeend', `

`); } // Flash plugin for old browsers that not support HTML5 audio } else if(!$q(`object[FlashVars*="${ src }"]`, el)) { el.insertAdjacentHTML('beforeend', '
`); } } } if(Cfg.addVocaroo) { const els = $Q('a[href*="vocaroo.com"]', isPost ? data.el : data); for(let i = 0, len = els.length; i < len; ++i) { const link = els[i]; const el = link.previousSibling; if(!el || el.className !== 'de-vocaroo') { // Don't embed already embedded links link.insertAdjacentHTML('beforebegin', `
`); } } } } /* ==[ Ajax.js ]============================================================================================== AJAX FUNCTIONS =========================================================================================================== */ // Main AJAX util function $ajax(url, params = null, isCORS = false) { let resolve, reject, cancelFn; const needTO = params ? params.useTimeout : false; const WAITING_TIME = 5e3; if(((isCORS ? !nav.hasGMXHR : !nav.canUseNativeXHR) || aib.hasRefererErr && nav.canUseFetch) && (nav.canUseFetchBlob || !url.startsWith('blob')) ) { if(!params) { params = {}; } params.referrer = doc.referrer.startsWith(aib.prot + '//' + aib.host) ? doc.referrer : deWindow.location; if(params.data) { params.body = params.data; delete params.data; } if(isCORS) { params.mode = 'cors'; } url = getAbsLink(url); // Chrome-extension: avoid CORS in content script. Sending data to background.js if(isCORS && nav.isChrome && nav.scriptHandler === 'WebExtension') { if(params.body) { // Converting image as Uint8Array to text data for sending in POST request from background.js let textData = ''; const arrData = params.body.arr; for(let i = 0, len = arrData.length; i < len; ++i) { textData += String.fromCharCode(arrData[i]); } params.body.arr = textData; } chrome.runtime.sendMessage({ 'de-messsage': 'corsRequest', url, params }, res => { const { answer } = res; if(res.isError || !aib.isAjaxStatusOK(res.status)) { reject(res.statusText ? new AjaxError(res.status, res.statusText) : getErrorMessage(answer)); return; } const obj = {}; switch(params.responseType) { case 'arraybuffer': case 'blob': { // Converting text data from the background.js response to arraybuffer/blob const buf = new ArrayBuffer(answer.length); const bufView = new Uint8Array(buf); for(let i = 0, len = answer.length; i < len; ++i) { bufView[i] = answer.charCodeAt(i); } obj.response = params.responseType === 'blob' ? new Blob([buf]) : buf; break; } default: obj.responseText = answer; } resolve(obj); }); } else { const controller = new AbortController(); params.signal = controller.signal; const loadTO = needTO && setTimeout(() => { reject(AjaxError.Timeout); try { controller.abort(); } catch(err) {} }, WAITING_TIME); cancelFn = () => { if(needTO) { clearTimeout(loadTO); } controller.abort(); }; fetch(url, params).then(async res => { if(!aib.isAjaxStatusOK(res.status)) { reject(new AjaxError(res.status, res.statusText)); return; } switch(params.responseType) { case 'arraybuffer': res.response = await res.arrayBuffer(); break; case 'blob': res.response = await res.blob(); break; default: res.responseText = await res.text(); } resolve(res); }).catch(err => reject(getErrorMessage(err))); } } else if((isCORS || !nav.canUseNativeXHR) && nav.hasGMXHR) { let gmxhr; const timeoutFn = () => { reject(AjaxError.Timeout); try { gmxhr.abort(); } catch(err) {} }; let loadTO = needTO && setTimeout(timeoutFn, WAITING_TIME); const obj = { method : (params && params.method) || 'GET', url : nav.fixLink(url), onreadystatechange(e) { if(needTO) { clearTimeout(loadTO); } if(e.readyState === 4) { if(aib.isAjaxStatusOK(e.status)) { resolve(e); } else { reject(new AjaxError(e.status, e.statusText)); } } else if(needTO) { loadTO = setTimeout(timeoutFn, WAITING_TIME); } } }; if(params) { if(params.onprogress) { obj.upload = { onprogress: params.onprogress }; delete params.onprogress; } delete params.method; Object.assign(obj, params); } if(nav.hasNewGM) { GM.xmlHttpRequest(obj); cancelFn = emptyFn; // GreaseMonkey 4 cannot cancel xhr's } else { gmxhr = GM_xmlhttpRequest(obj); cancelFn = () => { if(needTO) { clearTimeout(loadTO); } try { gmxhr.abort(); } catch(err) {} }; } } else if(nav.canUseNativeXHR) { const xhr = new XMLHttpRequest(); const timeoutFn = () => { reject(AjaxError.Timeout); xhr.abort(); }; let loadTO = needTO && setTimeout(timeoutFn, WAITING_TIME); if(params && params.onprogress) { xhr.upload.onprogress = params.onprogress; } xhr.onreadystatechange = ({ target }) => { if(needTO) { clearTimeout(loadTO); } if(target.readyState === 4) { if(aib.isAjaxStatusOK(target.status)) { resolve(target); } else { reject(new AjaxError(target.status, target.statusText)); } } else if(needTO) { loadTO = setTimeout(timeoutFn, WAITING_TIME); } }; try { xhr.open((params && params.method) || 'GET', getAbsLink(url), true); if(params) { if(params.responseType) { xhr.responseType = params.responseType; } const { headers } = params; if(headers) { for(const h in headers) { if(headers.hasOwnProperty(h)) { xhr.setRequestHeader(h, headers[h]); } } } } xhr.send(params && params.data || null); cancelFn = () => { if(needTO) { clearTimeout(loadTO); } xhr.abort(); }; } catch(err) { clearTimeout(loadTO); nav.canUseNativeXHR = false; return $ajax(url, params); } } else { reject(new AjaxError(0, 'Ajax error: Can`t send any type of request.')); } return new CancelablePromise((res, rej) => { resolve = res; reject = rej; }, cancelFn); } class AjaxError { constructor(code, message) { this.code = code; this.message = message; } toString() { return this.code <= 0 ? String(this.message || Lng.noConnect[lang]) : `HTTP [${ this.code }] ${ this.message }`; } } AjaxError.Success = new AjaxError(200, 'OK'); AjaxError.Locked = new AjaxError(-1, { toString: () => Lng.thrClosed[lang] }); AjaxError.Timeout = new AjaxError(0, { toString: () => Lng.noConnect[lang] + ' (timeout)' }); const AjaxCache = { clearCache() { this._data = new Map(); }, fixURL: url => `${ url }${ url.includes('?') ? '&' : '?' }nocache=${ Math.random() }`, runCachedAjax(url, useCache) { const { hasCacheControl, params } = this._data.get(url) || {}; const ajaxURL = hasCacheControl === false ? this.fixURL(url) : url; return $ajax(ajaxURL, useCache && params || { useTimeout: true }, aib._4chan).then(xhr => this.saveData(url, xhr) ? xhr : $ajax(this.fixURL(url), useCache && params, aib._4chan)); }, saveData(url, xhr) { let ETag = null; let LastModified = null; let i = 0; let hasCacheControl = false; let headers = 'getAllResponseHeaders' in xhr ? xhr.getAllResponseHeaders() : xhr.responseHeaders; headers = headers ? /* usual xhr */ headers.split('\r\n') : /* fetch */ xhr.headers; for(const idx in headers) { if(!headers.hasOwnProperty(idx)) { continue; } let header = headers[idx]; if(typeof header === 'string') { // usual xhr const сIdx = header.indexOf(':'); if(сIdx === -1) { continue; } const name = header.substring(0, сIdx); const value = header.substring(сIdx + 2, header.length); header = [name, value]; } const hName = header[0].toLowerCase(); let matched = true; switch(hName) { case 'cache-control': hasCacheControl = true; break; case 'last-modified': LastModified = header[1]; break; case 'etag': ETag = header[1]; break; default: matched = false; } if(matched && ++i === 3) { break; } } headers = null; if(ETag || LastModified) { headers = {}; if(ETag) { headers['If-None-Match'] = ETag; } if(LastModified) { headers['If-Modified-Since'] = LastModified; } } const hasUrl = this._data.has(url); this._data.set(url, { hasCacheControl, params: headers ? { headers, useTimeout: true } : { useTimeout: true } }); return hasUrl || hasCacheControl; }, _data: new Map() }; function ajaxLoad(url, returnForm = true, useCache = false, checkArch = false) { return AjaxCache.runCachedAjax(url, useCache).then(xhr => { let el; const text = xhr.responseText; if(text.includes('')) { el = returnForm ? $q(aib.qDForm, $DOM(text)) : $DOM(text); } return !el ? CancelablePromise.reject(new AjaxError(0, Lng.errCorruptData[lang])) : checkArch ? [el, (xhr.responseURL || '').includes('/arch/')] : el; }, err => err.code === 304 ? null : CancelablePromise.reject(err)); } function ajaxPostsLoad(brd, tNum, useCache, useJson = true) { if(useJson && aib.JsonBuilder) { return AjaxCache.runCachedAjax(aib.getJsonApiUrl(brd, tNum), useCache).then(xhr => { try { return new aib.JsonBuilder(JSON.parse(xhr.responseText), brd); } catch(err) { if(err instanceof AjaxError) { return CancelablePromise.reject(err); } console.warn(`API error: ${ err }. Switching to DOM parsing!`); aib.JsonBuilder = null; return ajaxPostsLoad(brd, tNum, useCache); } }, err => err.code === 304 ? null : CancelablePromise.reject(err)); } return aib.hasArchive ? ajaxLoad(aib.getThrUrl(brd, tNum), true, useCache, true) .then(data => data && data[0] ? new DOMPostsBuilder(data[0], data[1]) : null) : ajaxLoad(aib.getThrUrl(brd, tNum), true, useCache) .then(form => form ? new DOMPostsBuilder(form) : null); } function infoLoadErrors(err, showError = true) { const isAjax = err instanceof AjaxError; const eCode = isAjax ? err.code : 0; if(eCode === 200) { closePopup('newposts'); } else if(isAjax && eCode === 0) { $popup('newposts', err.message ? String(err.message) : `${ Lng.noConnect[lang] }: \n${ getErrorMessage(err) }`); } else { $popup('newposts', `${ Lng.thrNotFound[lang] } (№${ aib.t }): \n${ getErrorMessage(err) }`); if(showError) { doc.title = `{${ eCode }} ${ doc.title }`; } } } /* ==[ Pages.js ]============================================================================================= PAGES LOADER =========================================================================================================== */ const Pages = { addPage(needThreads = 0, pageNum = DelForm.last.pageNum + 1) { if(this._isAdding || pageNum > aib.lastPage || needThreads && pageNum > 4) { return; } this._isAdding = true; DelForm.last.el.insertAdjacentHTML('beforeend', `

${ Lng.loading[lang] }
`); MyPosts.purge(); this._addingPromise = ajaxLoad(aib.getPageUrl(aib.b, pageNum)).then(async formEl => { const newForm = this._addForm(formEl, pageNum); if(newForm.firstThr) { if(!needThreads) { return this._updateForms(DelForm.last); } $hide(newForm.el); await this._updateForms(DelForm.last); const firstForm = DelForm.first; let thr = newForm.firstThr; do { if(thr.isHidden) { DelForm.tNums.delete(thr.num); } else { const oldLastThr = firstForm.lastThr; $after(oldLastThr.el, thr.el); newForm.firstThr = thr.next; thr.prev = oldLastThr; thr.form = firstForm; firstForm.lastThr = oldLastThr.next = thr; needThreads--; } thr = thr.next; } while(needThreads && thr); DelForm.last = firstForm; firstForm.next = firstForm.lastThr.next = null; newForm.el.remove(); this._endAdding(); if(needThreads) { this.addPage(needThreads, pageNum + 1); } return CancelablePromise.reject(new CancelError()); } this._endAdding(); this.addPage(); return CancelablePromise.reject(new CancelError()); }).then(() => this._endAdding()).catch(err => { if(!(err instanceof CancelError)) { $popup('add-page', getErrorMessage(err)); this._endAdding(); } }); }, async loadPages(count) { $popup('load-pages', Lng.loading[lang], true); if(this._addingPromise) { this._addingPromise.cancelPromise(); this._endAdding(); } PviewsCache.purge(); isExpImg = false; pByEl = new Map(); pByNum = new Map(); Post.hiddenNums = new Set(); AttachedImage.closeImg(); if(pr.isQuick) { pr.clearForm(); } DelForm.tNums = new Set(); for(const form of DelForm) { $each($Q('a[href^="blob:"]', form.el), el => URL.revokeObjectURL(el.href)); $hide(form.el); if(form === DelForm.last) { break; } form.el.remove(); } DelForm.first = DelForm.last; for(let i = aib.page, len = Math.min(aib.lastPage + 1, aib.page + count); i < len; ++i) { try { this._addForm(await ajaxLoad(aib.getPageUrl(aib.b, i)), i); } catch(err) { $popup('load-pages', getErrorMessage(err)); } } const { first } = DelForm; if(first !== DelForm.last) { DelForm.first = first.next; first.el.remove(); await this._updateForms(DelForm.first); closePopup('load-pages'); } }, _isAdding : false, _addingPromise : null, _addForm(formEl, pageNum) { formEl = doc.adoptNode(formEl); $hide(formEl = aib.fixHTML(formEl)); $after(DelForm.last.el, formEl); const form = new DelForm(formEl, +pageNum, DelForm.last); DelForm.last = form; form.addStuff(); if(pageNum !== aib.page && form.firstThr) { formEl.insertAdjacentHTML('afterbegin', `
${ Lng.page[lang] } ${ pageNum }

`); } $show(formEl); return form; }, _endAdding() { $q('.de-addpage-wait').remove(); this._isAdding = false; this._addingPromise = null; }, async _updateForms(newForm) { readPostsData(newForm.firstThr.op, await readFavorites()); if(pr.passw) { PostForm.setUserPassw(); } embedPostMsgImages(newForm.el); if(HotKeys.enabled) { HotKeys.clearCPost(); } } }; function toggleInfinityScroll() { if(!aib.t) { const evtName = 'onwheel' in doc.defaultView ? 'wheel' : 'mousewheel'; if(Cfg.inftyScroll) { doc.defaultView.addEventListener(evtName, toggleInfinityScroll.onwheel); } else { doc.defaultView.removeEventListener(evtName, toggleInfinityScroll.onwheel); } } } toggleInfinityScroll.onwheel = e => { if((e.type === 'wheel' ? e.deltaY : -('wheelDeltaY' in e ? e.wheelDeltaY : e.wheelDelta)) > 0) { deWindow.requestAnimationFrame(() => { if(Thread.last.bottom - 150 < Post.sizing.wHeight) { Pages.addPage(); } }); } }; /* ==[ Spells.js ]============================================================================================ SPELLS =========================================================================================================== */ const Spells = Object.create({ hash: null, get hiders() { this._initSpells(); return this.hiders; }, get list() { if(Cfg.spells === null) { return '#wipe(samelines,samewords,longwords,symbols,numbers,whitespace)'; } let data; try { data = JSON.parse(Cfg.spells); } catch(err) { return ''; } const [, s, reps, oreps] = data; let str = s ? this._decompileScope(s, '')[0].join('\n') : ''; if(reps || oreps) { if(str) { str += '\n\n'; } if(reps) { for(const rep of reps) { str += this._decompileRep(rep, false) + '\n'; } } if(oreps) { for(const orep of oreps) { str += this._decompileRep(orep, true) + '\n'; } } str = str.substr(0, str.length - 1); } return str; }, get names() { return [ 'words', 'exp', 'exph', 'imgn', 'ihash', 'subj', 'name', 'trip', 'img', 'sage', 'op', 'tlen', 'all', 'video', 'wipe', 'num', 'vauthor' ]; }, get needArg() { return [ /* words */ true, /* exp */ true, /* exph */ true, /* imgn */ true, /* ihash */ true, /* subj */ false, /* name */ true, /* trip */ false, /* img */ false, /* sage */ false, /* op */ false, /* tlen */ false, /* all */ false, /* video */ false, /* wipe */ false, /* num */ true, /* vauthor */ true ]; }, get outreps() { this._initSpells(); return this.outreps; }, get reps() { this._initSpells(); return this.reps; }, addSpell(type, arg, isNeg) { const fld = $id('de-spell-txt'); const val = fld && fld.value; const chk = $q('input[info="hideBySpell"]'); let spells = val && this.parseText(val); if(!val || spells) { if(!spells) { try { spells = JSON.parse(Cfg.spells); } catch(err) {} spells = spells || [Date.now(), [], null, null]; } let idx, isAdded = true; const scope = aib.t ? [aib.b, aib.t] : null; if(spells[1]) { const sScope = String(scope); const sArg = String(arg); spells[1].some(scope && isNeg ? (spell, i) => { let data; if(spell[0] === 0xFF && ((data = spell[1]) instanceof Array) && data.length === 2 && data[0][0] === 0x20C && data[1][0] === type && data[1][2] == null && String(data[1][1]) === sArg && String(data[0][2]) === sScope ) { idx = i; return true; } return (spell[0] & 0x200) !== 0; } : (spell, i) => { if(spell[0] === type && String(spell[1]) === sArg && String(spell[2]) === sScope) { idx = i; return true; } return (spell[0] & 0x200) !== 0; }); } else { spells[1] = []; } if(typeof idx === 'undefined') { if(scope && isNeg) { spells[1].unshift([0xFF, [[0x20C, '', scope], [type, arg, void 0]], void 0]); } else { spells[1].unshift([type, arg, scope]); } } else if(Cfg.hideBySpell) { if(spells[1].length === 1) { spells[1] = null; } else { spells[1].splice(idx, 1); } isAdded = false; } if(isAdded) { saveCfg('hideBySpell', 1); if(chk) { chk.checked = true; } } else if(!spells[1] && !spells[2] && !spells[3]) { saveCfg('hideBySpell', 0); if(chk) { chk.checked = false; } } saveCfg('spells', JSON.stringify(spells)); this.setSpells(spells, true); if(fld) { fld.value = this.list; } Pview.updatePosition(true); return; } if(chk) { chk.checked = false; } }, decompileSpell(type, neg, val, scope, wipeMsg = null) { let spell = (neg ? '!#' : '#') + this.names[type] + (scope ? `[${ scope[0] }${ scope[1] ? `,${ scope[1] === -1 ? '' : scope[1] }` : '' }]` : ''); if(!val) { return spell; } // #img if(type === 8) { return spell + '(' + (val[0] === 2 ? '>' : val[0] === 1 ? '<' : '=') + (val[1] ? val[1][0] + (val[1][1] === val[1][0] ? '' : '-' + val[1][1]) : '') + (val[2] ? '@' + val[2][0] + (val[2][0] === val[2][1] ? '' : '-' + val[2][1]) + 'x' + val[2][2] + (val[2][2] === val[2][3] ? '' : '-' + val[2][3]) : '') + ')'; // #wipe } else if(type === 14) { if(val === 0x3F && !wipeMsg) { return spell; } const [msgBit, msgData] = wipeMsg || []; const names = []; const bits = { 1 : 'samelines', 2 : 'samewords', 4 : 'longwords', 8 : 'symbols', 16 : 'capslock', 32 : 'numbers', 64 : 'whitespace' }; for(const bit in bits) { if(+bit !== msgBit && (val & +bit)) { names.push(bits[bit]); } } if(msgBit) { names.push(bits[msgBit].toUpperCase() + (msgData ? ': ' + msgData : '')); } return `${ spell }(${ names.join(',') })`; // #num, #tlen } else if(type === 15 || type === 11) { let temp_, temp = val[1].length - 1; if(temp !== -1) { for(temp_ = []; temp >= 0; --temp) { temp_.push(val[1][temp][0] + '-' + val[1][temp][1]); } temp_.reverse(); } spell += '('; if(val[0].length) { spell += val[0].join(',') + (temp_ ? ',' : ''); } if(temp_) { spell += temp_.join(','); } return spell + ')'; // #words, #name, #trip, #vauthor } else if(type === 0 || type === 6 || type === 7 || type === 16) { return `${ spell }(${ val.replace(/([)\\])/g, '\\$1').replace(/\n/g, '\\n') })`; } else { return `${ spell }(${ String(val) })`; } }, disableSpells() { const value = null; const configurable = true; Object.defineProperties(this, { hiders : { configurable, value }, outreps : { configurable, value }, reps : { configurable, value } }); saveCfg('hideBySpell', 0); }, outReplace(txt) { for(const orep of this.outreps) { txt = txt.replace(orep[0], orep[1]); } return txt; }, parseText(text) { const codeGen = new SpellsCodegen(text); const data = codeGen.generate(); if(codeGen.hasError) { $popup('err-spell', Lng.error[lang] + ': ' + codeGen.errorSpell); } else if(data) { if(data[0] && Cfg.sortSpells) { this._sort(data[0]); } return [Date.now(), ...data]; } return null; }, replace(txt) { for(const rep of this.reps) { txt = txt.replace(rep[0], rep[1]); } return txt; }, setSpells(spells, sync) { if(sync) { this._sync(spells); } if(!Cfg.hideBySpell) { SpellsRunner.unhideAll(); this.disableSpells(); return; } this._optimize(spells); if(this.hiders) { const sRunner = new SpellsRunner(); for(let post = Thread.first.op; post; post = post.next) { sRunner.runSpells(post); } sRunner.endSpells(); } else { SpellsRunner.unhideAll(); } }, toggle() { let spells; const fld = $id('de-spell-txt'); const val = fld.value; if(val && (spells = this.parseText(val))) { closePopup('err-spell'); this.setSpells(spells, true); saveCfg('spells', JSON.stringify(spells)); fld.value = this.list; } else { if(!val) { closePopup('err-spell'); SpellsRunner.unhideAll(); this.disableSpells(); saveCfg('spells', JSON.stringify([Date.now(), null, null, null])); sendStorageEvent('__de-spells', '{ hide: false, data: null }'); } $q('input[info="hideBySpell"]').checked = false; } }, _decompileRep(rep, isOrep) { return (isOrep ? '#outrep' : '#rep') + (rep[0] ? `[${ rep[0] }${ rep[1] ? `,${ rep[1] === -1 ? '' : rep[1] }` : '' }]` : '') + `(${ rep[2] },${ rep[3].replace(/([)\\])/g, '\\$1').replace(/\n/g, '\\n') })`; }, _decompileScope(scope, indent) { const dScope = []; let hScope = false; for(let i = 0, j = 0, len = scope.length; i < len; ++i, ++j) { const spell = scope[i]; const type = spell[0] & 0xFF; if(type === 0xFF) { hScope = true; const temp = this._decompileScope(spell[1], indent + ' '); if(temp[1]) { const str = `${ spell[0] & 0x100 ? '!(\n' : '(\n' }${ indent } ` + `${ temp[0].join(`\n${ indent } `) }\n${ indent })`; if(j === 0) { dScope[0] = str; } else { dScope[--j] += ' ' + str; } } else { dScope[j] = `${ spell[0] & 0x100 ? '!(' : '(' }${ temp[0].join(' ') })`; } } else { dScope[j] = this.decompileSpell(type, spell[0] & 0x100, spell[1], spell[2]); } if(i !== len - 1) { dScope[j] += spell[0] & 0x200 ? ' &' : ' |'; } } return [dScope, dScope.length > 2 || hScope]; }, _initSpells() { if(!Cfg.hideBySpell) { const value = null; const configurable = true; Object.defineProperties(this, { hiders : { configurable, value }, outreps : { configurable, value }, reps : { configurable, value } }); return; } let spells, data; try { spells = JSON.parse(Cfg.spells); data = JSON.parse(sesStorage[`de-spells-${ aib.b }${ aib.t || '' }`]); } catch(err) {} if(data && spells && data[0] === spells[0]) { this.hash = data[0]; this._setData(data[1], data[2], data[3]); return; } if(spells) { this._optimize(spells); } else { this.disableSpells(); } }, _initHiders(data) { if(data) { for(const item of data) { const val = item[1]; if(val) { switch(item[0] & 0xFF) { case 1: case 2: case 3: case 5: case 13: item[1] = toRegExp(val, true); break; case 0xFF: this._initHiders(val); } } } } return data; }, _initReps(data) { if(data) { for(const item of data) { item[0] = toRegExp(item[0], false); } } return data; }, _optimize(data) { const arr = [ data[1] ? this._optimizeSpells(data[1]) : null, data[2] ? this._optimizeReps(data[2]) : null, data[3] ? this._optimizeReps(data[3]) : null ]; sesStorage[`de-spells-${ aib.b }${ aib.t || '' }`] = JSON.stringify([data[0], ...arr]); this.hash = data[0]; this._setData(...arr); }, _optimizeReps(data) { const rv = []; for(const [r0, r1, r2, r3] of data) { if(!r0 || (r0 === aib.b && (r1 === -1 ? !aib.t : !r1 || +r1 === aib.t))) { rv.push([r2, r3]); } } return !rv.length ? null : rv; }, _optimizeSpells(spells) { let neg, lastSpell = -1; let newSpells = []; for(let i = 0, len = spells.length; i < len; ++i) { let j; const spell = spells[i]; let flags = spell[0]; const type = flags & 0xFF; neg = (flags & 0x100) !== 0; if(type === 0xFF) { const parensSpells = this._optimizeSpells(spell[1]); if(parensSpells) { if(parensSpells.length !== 1) { newSpells.push([flags, parensSpells]); lastSpell++; continue; } else if((parensSpells[0][0] & 0xFF) !== 12) { newSpells.push([(parensSpells[0][0] | (flags & 0x200)) ^ (flags & 0x100), parensSpells[0][1]]); lastSpell++; continue; } flags = parensSpells[0][0]; neg = !(neg ^ ((flags & 0x100) !== 0)); } } else { const scope = spell[2]; if(!scope || ( scope[0] === aib.b && (scope[1] === -1 ? !aib.t : !scope[1] || +scope[1] === aib.t) )) { if(type === 12) { neg = !neg; } else { newSpells.push([flags, spell[1]]); lastSpell++; continue; } } } for(j = lastSpell; j >= 0 && (((newSpells[j][0] & 0x200) !== 0) ^ neg); --j) /* empty */; if(j !== lastSpell) { newSpells = newSpells.slice(0, j + 1); lastSpell = j; } if(neg && j !== -1) { newSpells[j][0] &= 0x1FF; } if(((flags & 0x200) !== 0) ^ neg) { break; } } return lastSpell === -1 ? neg ? [[12, '']] : null : newSpells; }, _setData(hiders, reps, outreps) { const configurable = true; Object.defineProperties(this, { hiders : { configurable, value: this._initHiders(hiders) }, outreps : { configurable, value: this._initReps(outreps) }, reps : { configurable, value: this._initReps(reps) } }); }, _sort(sp) { // Wraps AND-spells with brackets for proper sorting for(let i = 0, len = sp.length - 1; i < len; ++i) { if(sp[i][0] > 0x200) { const temp = [0xFF, []]; do { temp[1].push(sp.splice(i, 1)[0]); len--; } while(sp[i][0] > 0x200); temp[1].push(sp.splice(i, 1)[0]); sp.splice(i, 0, temp); } } sp = sp.sort(); for(let i = 0, len = sp.length - 1; i < len; ++i) { // Removes duplicates and weaker spells const j = i + 1; if(sp[i][0] === sp[j][0] && sp[i][1] <= sp[j][1] && sp[i][1] >= sp[j][1] && (sp[i][2] === null || // Stronger spell with 3 parameters sp[i][2] === undefined || // Equal spells with 2 parameters (sp[i][2] <= sp[j][2] && sp[i][2] >= sp[j][2])) ) { // Equal spells with 3 parameters sp.splice(j, 1); i--; len--; // Moves brackets to the end of the list } else if(sp[i][0] === 0xFF) { sp.push(sp.splice(i, 1)[0]); i--; len--; } } }, _sync(data) { sendStorageEvent('__de-spells', { hide: !!Cfg.hideBySpell, data }); } }); class SpellsCodegen { constructor(sList) { this.TYPE_UNKNOWN = 0; this.TYPE_ANDOR = 1; this.TYPE_NOT = 2; this.TYPE_SPELL = 3; this.TYPE_PARENTHESES = 4; this.TYPE_REPLACER = 5; this.hasError = false; this._col = 1; this._errMsg = ''; this._errMsgArg = null; this._line = 1; this._sList = sList; } get errorSpell() { return !this.hasError ? '' : (this._errMsgArg ? this._errMsg.replace('%s', this._errMsgArg) : this._errMsg) + Lng.seRow[lang] + this._line + Lng.seCol[lang] + this._col + ')'; } generate() { return this._sList ? this._generate(this._sList, false) : null; } static _getScope(str) { const m = str.match(/^\[([a-z0-9/]+)(?:(,)|,(\s*[0-9]+))?\]/); return m ? [m[0].length, [m[1], m[3] ? +m[3] : m[2] ? -1 : false]] : null; } static _getText(str, haveBracket) { if(haveBracket && (str[0] !== '(')) { return [0, '']; } let rv = ''; for(let i = haveBracket ? 1 : 0, len = str.length; i < len; ++i) { const ch = str[i]; if(ch === '\\') { if(i === len - 1) { return null; } switch(str[i + 1]) { case 'n': rv += '\n'; break; case '\\': rv += '\\'; break; case ')': rv += ')'; break; default: return null; } ++i; } else if(ch === ')') { return [i + 1, rv]; } else { rv += ch; } } return null; } _generate(sList, inParens) { const spellsArr = []; let reps = []; let outreps = []; let lastType = this.TYPE_UNKNOWN; let hasReps = false; for(let i = 0, len = sList.length; i < len; i++, this._col++) { let res; switch(sList[i]) { case '\n': this._line++; this._col = 0; /* falls through */ case '\r': case ' ': continue; case '#': { let name = ''; i++; this._col++; while((sList[i] >= 'a' && sList[i] <= 'z') || (sList[i] >= 'A' && sList[i] <= 'Z')) { name += sList[i].toLowerCase(); i++; this._col++; } if(name === 'rep' || name === 'outrep') { if(!hasReps) { if(inParens) { this._col -= 1 + name.length; this._setError(Lng.seRepsInParens[lang], '#' + name); return null; } if(lastType === this.TYPE_ANDOR || lastType === this.TYPE_NOT) { i -= 1 + name.length; this._col -= 1 + name.length; lookBack: while(i >= 0) { switch(sList[i]) { case '\n': case '\r': case ' ': i--; this._col--; break; default: break lookBack; } } this._setError(Lng.seOpInReps[lang], sList[i]); return null; } hasReps = true; } res = this._doRep(name, sList.substr(i)); if(!res) { return null; } (name === 'rep' ? reps : outreps).push(res[1]); i += res[0] - 1; this._col += res[0] - 1; lastType = this.TYPE_REPLACER; } else { if(lastType === this.TYPE_SPELL || lastType === this.TYPE_PARENTHESES) { this._setError(Lng.seMissOp[lang], null); return null; } res = this._doSpell(name, sList.substr(i), lastType === this.TYPE_NOT); if(!res) { return null; } i += res[0] - 1; this._col += res[0] - 1; spellsArr.push(res[1]); lastType = this.TYPE_SPELL; } break; } case '(': if(hasReps) { this._setError(Lng.seUnexpChar[lang], '('); return null; } if(lastType === this.TYPE_SPELL || lastType === this.TYPE_PARENTHESES) { this._setError(Lng.seMissOp[lang], null); return null; } res = this._generate(sList.substr(i + 1), true); if(!res) { return null; } i += res[0] + 1; spellsArr.push([lastType === this.TYPE_NOT ? 0x1FF : 0xFF, res[1]]); lastType = this.TYPE_PARENTHESES; break; case '|': case '&': if(hasReps) { this._setError(Lng.seUnexpChar[lang], sList[i]); return null; } if(lastType !== this.TYPE_SPELL && lastType !== this.TYPE_PARENTHESES) { this._setError(Lng.seMissSpell[lang], null); return null; } if(sList[i] === '&') { spellsArr[spellsArr.length - 1][0] |= 0x200; } lastType = this.TYPE_ANDOR; break; case '!': if(hasReps) { this._setError(Lng.seUnexpChar[lang], '!'); return null; } if(lastType !== this.TYPE_ANDOR && lastType !== this.TYPE_UNKNOWN) { this._setError(Lng.seMissOp[lang], null); return null; } lastType = this.TYPE_NOT; break; case ')': if(hasReps) { this._setError(Lng.seUnexpChar[lang], ')'); return null; } if(lastType === this.TYPE_ANDOR || lastType === this.TYPE_NOT) { this._setError(Lng.seMissSpell[lang], null); return null; } if(inParens) { return [i, spellsArr]; } /* falls through */ default: this._setError(Lng.seUnexpChar[lang], sList[i]); return null; } } if(inParens) { this._setError(Lng.seMissClBkt[lang], null); return null; } if(lastType !== this.TYPE_SPELL && lastType !== this.TYPE_PARENTHESES && lastType !== this.TYPE_REPLACER ) { this._setError(Lng.seMissSpell[lang], null); return null; } if(!reps.length) { reps = false; } if(!outreps.length) { outreps = false; } return [spellsArr, reps, outreps]; } _getRegex(str, haveComma) { const m = str.match(/^\((\/.*?[^\\]\/[igm]*)(?:\)|\s*(,))/); if(!m || haveComma !== Boolean(m[2])) { return null; } const val = m[1]; try { toRegExp(val, true); } catch(err) { this._setError(Lng.seErrRegex[lang], val); return null; } return [m[0].length, val]; } _doRep(name, str) { let scope = SpellsCodegen._getScope(str); if(scope) { str = str.substring(scope[0]); } else { scope = [0, ['', '']]; } const regex = this._getRegex(str, true); if(regex) { str = str.substring(regex[0]); if(str[0] === ')') { return [regex[0] + scope[0] + 1, [scope[1][0], scope[1][1], regex[1], '']]; } const val = SpellsCodegen._getText(str, false); if(val) { return [val[0] + regex[0] + scope[0], [scope[1][0], scope[1][1], regex[1], val[1]]]; } } this._setError(Lng.seSyntaxErr[lang], name); return null; } _doSpell(name, str, isNeg) { let m, val, scope = null, i = 0; const spellIdx = Spells.names.indexOf(name); if(spellIdx === -1) { this._setError(Lng.seUnknown[lang], name); return null; } let temp = SpellsCodegen._getScope(str); if(temp) { i += temp[0]; str = str.substring(temp[0]); scope = temp[1]; } const spellType = isNeg ? spellIdx | 0x100 : spellIdx; if(str[0] !== '(' || str[1] === ')') { if(Spells.needArg[spellIdx]) { this._setError(Lng.seMissArg[lang], name); return null; } return [str[0] === '(' ? i + 2 : i, [spellType, spellIdx === 14 ? 0x3F : '', scope]]; } switch(spellIdx) { // #ihash case 4: m = str.match(/^\((\d+)\)/); if(!isNaN(+m[1])) { return [i + m[0].length, [spellType, +m[1], scope]]; } break; // #img case 8: m = str.match(/^\(([><=])(?:(\d+(?:\.\d+)?)(?:-(\d+(?:\.\d+)?))?)?(?:@(\d+)(?:-(\d+))?x(\d+)(?:-(\d+))?)?\)/); if(m && (m[2] || m[4])) { return [i + m[0].length, [spellType, [ m[1] === '=' ? 0 : m[1] === '<' ? 1 : 2, m[2] && [+m[2], m[3] ? +m[3] : +m[2]], m[4] && [+m[4], m[5] ? +m[5] : +m[4], +m[6], m[7] ? +m[7] : +m[6]] ], scope]]; } break; // #wipe case 14: m = str.match(/^\(([a-z, ]+)\)/); if(m) { let val = 0; const arr = m[1].split(/, */); for(let i = 0, len = arr.length; i < len; ++i) { switch(arr[i]) { case 'samelines': val |= 1; break; case 'samewords': val |= 2; break; case 'longwords': val |= 4; break; case 'symbols': val |= 8; break; case 'capslock': val |= 16; break; case 'numbers': val |= 32; break; case 'whitespace': val |= 64; break; default: val = -1; } } if(val !== -1) { return [i + m[0].length, [spellType, val, scope]]; } } break; // #tlen, #num case 11: case 15: m = str.match(/^\(([\d-, ]+)\)/); if(m) { m[1].split(/, */).forEach(function(v) { if(v.includes('-')) { const nums = v.split('-'); nums[0] = +nums[0]; nums[1] = +nums[1]; this[1].push(nums); } else { this[0].push(+v); } }, val = [[], []]); return [i + m[0].length, [spellType, val, scope]]; } break; // #exp, #exph, #imgn, #subj, #video case 1: case 2: case 3: case 5: case 13: temp = this._getRegex(str, false); if(temp) { return [i + temp[0], [spellType, temp[1], scope]]; } break; // #sage, #op, #all, #trip, #name, #words, #vauthor default: temp = SpellsCodegen._getText(str, true); if(temp) { return [i + temp[0], [spellType, spellIdx === 0 ? temp[1].toLowerCase() : temp[1], scope]]; } } this._setError(Lng.seSyntaxErr[lang], name); return null; } _setError(msg, arg) { this.hasError = true; this._errMsg = msg; this._errMsgArg = arg; } } class SpellsRunner { constructor() { this.hasNumSpell = false; this._endPromise = null; this._spells = Spells.hiders; if(!this._spells) { this.runSpells = SpellsRunner._unhidePost; SpellsRunner.cachedData = null; } } static unhideAll() { if(aib.t) { sesStorage['de-hidden-' + aib.b + aib.t] = null; } for(let post = Thread.first.op; post; post = post.next) { if(post.spellHidden) { post.spellUnhide(); } } } endSpells() { if(this._endPromise) { this._endPromise.then(() => this._savePostsHelper()); } else { this._savePostsHelper(); } } runSpells(post) { let res = (new SpellsInterpreter(post, this._spells)).runInterpreter(); if(res instanceof Promise) { res = res.then(val => this._checkRes(post, val)); this._endPromise = this._endPromise ? this._endPromise.then(() => res) : res; return 0; } return this._checkRes(post, res); } static _unhidePost(post) { if(post.spellHidden) { post.spellUnhide(); if(SpellsRunner.cachedData && !post.isDeleted) { SpellsRunner.cachedData[post.count] = [false, null]; } } return 0; } _checkRes(post, [hasNumSpell, val, msg]) { this.hasNumSpell |= hasNumSpell; if(val) { post.spellHide(msg); if(SpellsRunner.cachedData && !post.isDeleted) { SpellsRunner.cachedData[post.count] = [true, msg]; } return 1; } return SpellsRunner._unhidePost(post); } _savePostsHelper() { if(this._spells) { if(aib.t) { const lPost = Thread.first.lastNotDeleted; let data = null; if(Spells.hiders) { if(SpellsRunner.cachedData) { data = SpellsRunner.cachedData; } else { data = []; for(let post = Thread.first.op; post; post = post.nextNotDeleted) { data.push(post.spellHidden ? [true, Post.Note.text] : [false, null]); } SpellsRunner.cachedData = data; } } sesStorage['de-hidden-' + aib.b + aib.t] = !data ? null : JSON.stringify({ hash : Cfg.hideBySpell ? Spells.hash : 0, lastCount : lPost.count, lastNum : lPost.num, data }); } toggleWindow('hid', true); } ImagesHashStorage.endFn(); } } SpellsRunner.cachedData = null; class SpellsInterpreter { constructor(post, spells) { this.hasNumSpell = false; this._ctx = [spells.length, spells, 0, false]; this._deep = 0; this._lastTSpells = []; this._post = post; this._triggeredSpellsStack = [this._lastTSpells]; this._wipeMsg = null; } runInterpreter() { let rv, stopCheck; let isNegScope = this._ctx.pop(); let i = this._ctx.pop(); let scope = this._ctx.pop(); let len = this._ctx.pop(); while(true) { if(i < len) { const type = scope[i][0] & 0xFF; if(type === 0xFF) { this._deep++; this._ctx.push(len, scope, i, isNegScope); isNegScope = !!(((scope[i][0] & 0x100) !== 0) ^ isNegScope); scope = scope[i][1]; len = scope.length; i = 0; this._lastTSpells = []; this._triggeredSpellsStack.push(this._lastTSpells); continue; } const val = this._runSpell(type, scope[i][1]); if(val instanceof Promise) { this._ctx.push(len, scope, ++i, isNegScope); return val.then(v => this._asyncContinue(v)); } [rv, stopCheck] = this._checkRes(scope[i], val, isNegScope); if(!stopCheck) { i++; continue; } } if(this._deep !== 0) { this._deep--; isNegScope = this._ctx.pop(); i = this._ctx.pop(); scope = this._ctx.pop(); len = this._ctx.pop(); if(((scope[i][0] & 0x200) === 0) ^ rv) { i++; this._triggeredSpellsStack.pop(); this._lastTSpells = this._triggeredSpellsStack[this._triggeredSpellsStack.length - 1]; continue; } } return [this.hasNumSpell, rv, rv ? this._getMsg() : null]; } } static _tlenNum_helper(val, num) { for(let arr = val[0], i = arr.length - 1; i >= 0; --i) { if(arr[i] === num) { return true; } } for(let arr = val[1], i = arr.length - 1; i >= 0; --i) { if(num >= arr[i][0] && num <= arr[i][1]) { return true; } } return false; } _asyncContinue(val) { const cl = this._ctx.length; const spell = this._ctx[cl - 3][this._ctx[cl - 2] - 1]; const [rv, stopCheck] = this._checkRes(spell, val, this._ctx[cl - 1]); return stopCheck ? [this.hasNumSpell, rv, rv ? this._getMsg() : null] : this.runInterpreter(); } _checkRes(spell, val, isNegScope) { const flags = spell[0]; const isAndSpell = ((flags & 0x200) !== 0) ^ isNegScope; const isNegSpell = ((flags & 0x100) !== 0) ^ isNegScope; if(isNegSpell ^ val) { this._lastTSpells.push([isNegSpell, spell, (spell[0] & 0xFF) === 14 ? this._wipeMsg : null]); return [true, !isAndSpell]; } this._lastTSpells.length = 0; return [false, isAndSpell]; } _getMsg() { const rv = []; for(const spellEls of this._triggeredSpellsStack) { for(const [isNeg, spell, wipeMsg] of spellEls) { rv.push(Spells.decompileSpell(spell[0] & 0xFF, isNeg, spell[1], spell[2], wipeMsg)); } } return rv.join(' & '); } _runSpell(spellId, val) { switch(spellId) { case 0: return this._words(val); case 1: return this._exp(val); case 2: return this._exph(val); case 3: return this._imgn(val); case 4: return this._ihash(val); case 5: return this._subj(val); case 6: return this._name(val); case 7: return this._trip(val); case 8: return this._img(val); case 9: return this._sage(val); case 10: return this._op(val); case 11: return this._tlen(val); case 12: return this._all(val); case 13: return this._video(val); case 14: return this._wipe(val); case 15: this.hasNumSpell = true; return this._num(val); case 16: return this._vauthor(val); } } _all() { return true; } _exp(val) { return val.test(this._post.text); } _exph(val) { return val.test(this._post.html); } async _ihash(val) { for(const image of this._post.images) { if((image instanceof AttachedImage) && await ImagesHashStorage.getHash(image) === val) { return true; } } return false; } _img(val) { const { images } = this._post; const [compareRule, weightVals, sizeVals] = val; if(!val) { return images.hasAttachments; } for(const image of images) { if(!(image instanceof AttachedImage)) { continue; } if(weightVals) { const w = image.weight; let isHide; switch(compareRule) { case 0: isHide = w >= weightVals[0] && w <= weightVals[1]; break; case 1: isHide = w < weightVals[0]; break; case 2: isHide = w > weightVals[0]; break; } if(!isHide) { continue; } else if(!sizeVals) { return true; } } if(sizeVals) { const { height: h, width: w } = image; switch(compareRule) { case 0: if(w >= sizeVals[0] && w <= sizeVals[1] && h >= sizeVals[2] && h <= sizeVals[3]) { return true; } break; case 1: if(w < sizeVals[0] && h < sizeVals[3]) { return true; } break; case 2: if(w > sizeVals[0] && h > sizeVals[3]) { return true; } } } } return false; } _imgn(val) { for(const image of this._post.images) { if((image instanceof AttachedImage) && val.test(image.name)) { return true; } } return false; } _name(val) { const pName = this._post.posterName; return pName ? !val || pName.includes(val) : false; } _num(val) { return SpellsInterpreter._tlenNum_helper(val, this._post.count + 1); } _op() { return this._post.isOp; } _sage() { return this._post.sage; } _subj(val) { const pSubj = this._post.subj; return pSubj ? !val || val.test(pSubj) : false; } _tlen(val) { const text = this._post.text.replace(/\s+(?=\s)|\n/g, ''); return !val ? !!text : SpellsInterpreter._tlenNum_helper(val, text.length); } _trip(val) { const pTrip = this._post.posterTrip; return pTrip ? !val || pTrip.includes(val) : false; } _vauthor(val) { return this._videoVauthor(val, true); } _video(val) { return this._videoVauthor(val, false); } _videoVauthor(val, isAuthorSpell) { const { videos } = this._post; if(!val) { return !!videos.hasLinks; } if(!videos.hasLinks || !Cfg.YTubeTitles) { return false; } for(const siteData of videos.vData) { for(const data of siteData) { if(isAuthorSpell ? val === data[1] : val.test(data[0])) { return true; } } } if(videos.linksCount === videos.loadedLinksCount) { return false; } return new Promise(resolve => (videos.titleLoadFn = data => { if(isAuthorSpell ? val === data[1] : val.test(data[0])) { resolve(true); } else if(videos.linksCount === videos.loadedLinksCount) { resolve(false); } else { return; } videos.titleLoadFn = null; })); } _wipe(val) { let arr, len, x; const txt = this._post.text; // (1 << 0): samelines if(val & 1) { arr = txt.replace(/>/g, '').split(/\s*\n\s*/); if((len = arr.length) > 5) { arr.sort(); for(let i = 0, n = len / 4; i < len;) { x = arr[i]; let j = 0; while(arr[i++] === x) { j++; } if(j > 4 && j > n && x) { this._wipeMsg = [1, `"${ x.substr(0, 20) }" x${ j + 1 }`]; return true; } } } } // (1 << 1): samewords if(val & 2) { arr = txt.replace(/[\s.?!,>]+/g, ' ').toUpperCase().split(' '); if((len = arr.length) > 3) { arr.sort(); let keys = 0; let pop = 0; for(let i = 0, n = len / 4; i < len; keys++) { x = arr[i]; let j = 0; while(arr[i++] === x) { j++; } if(len > 25) { if(j > pop && x.length > 2) { pop = j; } if(pop >= n) { this._wipeMsg = [2, `same "${ x.substr(0, 20) }" x${ pop + 1 }`]; return true; } } } x = keys / len; if(x < 0.25) { this._wipeMsg = [2, `uniq ${ (x * 100).toFixed(0) }%`]; return true; } } } // (1 << 2): longwords if(val & 4) { arr = txt.replace(/https*:\/\/.*?(\s|$)/g, '').replace(/[\s.?!,>:;-]+/g, ' ').split(' '); if(arr[0].length > 50 || ((len = arr.length) > 1 && arr.join('').length / len > 10)) { this._wipeMsg = [4, null]; return true; } } // (1 << 3): symbols if(val & 8) { const _txt = txt.replace(/\s+/g, ''); if((len = _txt.length) > 30 && (x = _txt.replace(/[0-9a-zа-я.?!,]/ig, '').length / len) > 0.4) { this._wipeMsg = [8, `${ (x * 100).toFixed(0) }%`]; return true; } } // (1 << 4): capslock if(val & 16) { arr = txt.replace(/[\s.?!;,-]+/g, ' ').trim().split(' '); if((len = arr.length) > 4) { let n = 0; let capsw = 0; let casew = 0; for(let i = 0; i < len; ++i) { x = arr[i]; if((x.match(/[a-zа-я]/ig) || []).length < 5) { continue; } if((x.match(/[A-ZА-Я]/g) || []).length > 2) { casew++; } if(x === x.toUpperCase()) { capsw++; } n++; } if(capsw / n >= 0.3 && n > 4) { this._wipeMsg = [16, `CAPS ${ capsw / arr.length * 100 }%`]; return true; } else if(casew / n >= 0.3 && n > 8) { this._wipeMsg = [16, `cAsE ${ casew / arr.length * 100 }%`]; return true; } } } // (1 << 5): numbers if(val & 32) { const _txt = txt.replace(/\s+/g, ' ').replace(/>>\d+|https*:\/\/.*?(?: |$)/g, ''); if((len = _txt.length) > 30 && (x = (len - _txt.replace(/\d/g, '').length) / len) > 0.4) { this._wipeMsg = [32, `${ Math.round(x * 100) }%`]; return true; } } // (1 << 5): whitespace if(val & 64) { if(/(?:\n\s*){10}/i.test(txt)) { this._wipeMsg = [64, null]; return true; } } return false; } _words(val) { return this._post.text.toLowerCase().includes(val) || this._post.subj.toLowerCase().includes(val); } } /* ==[ Form.js ]============================================================================================== POSTFORM postform improving, quick reply window, markup text panel, sage button, etc =========================================================================================================== */ class PostForm { constructor(form, oeForm = null, ignoreForm = false) { this.isBottom = false; this.isHidden = false; this.isQuick = false; this.lastQuickPNum = -1; this.pArea = []; this.pForm = null; this.qArea = null; this._pBtn = []; const qOeForm = 'form[name="oeform"], form[action*="paint"]'; this.oeForm = oeForm || $q(qOeForm); if(!ignoreForm && !form) { if(this.oeForm) { ajaxLoad(aib.getThrUrl(aib.b, Thread.first.num), false).then(loadedDoc => { const form = $q(aib.qForm, loadedDoc); const oeForm = $q(qOeForm, loadedDoc); pr = new PostForm(form && doc.adoptNode(form), oeForm && doc.adoptNode(oeForm), true); }, () => (pr = new PostForm(null, null, true))); } else { this.form = null; } return; } this.tNum = aib.t; this.form = form; this.files = null; this.txta = $q(aib.qFormTxta, form); this.subm = $q(aib.qFormSubm, form); this.name = $q(aib.qFormName, form); this.mail = $q(aib.qFormMail, form); this.subj = $q(aib.qFormSubj, form); this.passw = $q(aib.qFormPassw, form); this.rules = $q(aib.qFormRules, form); this.video = $q('tr input[name="video"], tr input[name="embed"]', form); this._initFileInputs(); this._makeHideableContainer(); this._makeWindow(); if(!form || !this.txta) { return; } form.style.display = 'inline-block'; form.style.textAlign = 'left'; const { qArea, txta } = this; new WinResizer('reply', 'top', 'textaHeight', qArea, txta); new WinResizer('reply', 'left', 'textaWidth', qArea, txta); new WinResizer('reply', 'right', 'textaWidth', qArea, txta); new WinResizer('reply', 'bottom', 'textaHeight', qArea, txta); this._initTextarea(); this.addMarkupPanel(); this.setPlaceholders(); this.updateLanguage(); this._initCaptcha(); this._initSubmit(); if(Cfg.ajaxPosting) { this._initAjaxPosting(); } if(Cfg.addSageBtn && this.mail) { PostForm.hideField($parent(this.mail, 'LABEL') || this.mail); setTimeout(() => this.toggleSage(), 0); } if(Cfg.noPassword && this.passw) { $hide($qParent(this.passw, aib.qFormTr)); } if(Cfg.noName && this.name) { PostForm.hideField(this.name); } if(Cfg.noSubj && this.subj) { PostForm.hideField(this.subj); } if(Cfg.userName && this.name) { setTimeout(PostForm.setUserName, 0); } if(this.passw) { setTimeout(PostForm.setUserPassw, 0); } } static hideField(el) { const next = el.nextElementSibling; $toggle(next && (next.style.display !== 'none') || el.previousElementSibling ? el : $qParent(el, aib.qFormTr)); } static setUserName() { const el = $q('input[info="nameValue"]'); if(el) { saveCfg('nameValue', el.value); } pr.name.value = Cfg.userName ? Cfg.nameValue : ''; } static setUserPassw() { if(!Cfg.userPassw) { return; } const el = $q('input[info="passwValue"]'); if(el) { saveCfg('passwValue', el.value); } const value = pr.passw.value = Cfg.passwValue; for(const { passEl } of DelForm) { if(passEl) { passEl.value = value; } } } get isVisible() { if(!this.isHidden && this.isBottom && $q(':focus', this.pForm)) { const cr = this.pForm.getBoundingClientRect(); return cr.bottom > 0 && cr.top < nav.viewportHeight(); } return false; } get sageBtn() { const value = $aEnd(this.subm, '' + ''); value.onclick = () => { toggleCfg('sageReply'); this.toggleSage(); }; Object.defineProperty(this, 'sageBtn', { value }); return value; } get top() { return this.pForm.getBoundingClientRect().top; } addMarkupPanel() { let el = $id('de-txt-panel'); if(!Cfg.addTextBtns) { $del(el); return; } if(!el) { el = $add(''); el.addEventListener('click', this); el.addEventListener('mouseover', this); } el.style.cssFloat = Cfg.txtBtnsLoc ? 'none' : 'right'; $after(Cfg.txtBtnsLoc ? $id('de-resizer-text') || this.txta : this.subm, el); const id = ['bold', 'italic', 'under', 'strike', 'spoil', 'code', 'sup', 'sub']; const val = ['B', 'i', 'U', 'S', '%', 'C', 'x\u00b2', 'x\u2082']; const mode = Cfg.addTextBtns; let html = ''; for(let i = 0, len = aib.markupTags.length; i < len; ++i) { const tag = aib.markupTags[i]; if(tag) { html += `
${ mode === 2 ? `${ !html ? '[' : '' } ${ val[i] } /` : mode === 3 ? `` : `` }
`; } } el.innerHTML = `${ html }
${ mode === 2 ? ' > ]' : mode === 3 ? '' : '' }`; } clearForm() { if(this.txta) { this.txta.value = ''; } if(this.files) { this.files.clearInputs(); } if(this.video) { this.video.value = ''; } } closeReply() { if(this.isQuick) { this.isQuick = false; this.lastQuickPNum = -1; if(!aib.t) { this._toggleQuickReply(false); this.tNum = false; } this.setReply(false, !aib.t || Cfg.addPostForm > 1); } } handleEvent(e) { let el = e.target; if(el.tagName !== 'DIV') { el = el.parentNode; } const { id } = el; if(!id.startsWith('de-btn')) { return; } if(e.type === 'mouseover') { if(id === 'de-btn-quote') { quotetxt = deWindow.getSelection().toString(); } let key = -1; if(HotKeys.enabled) { switch(id.substr(7)) { case 'bold': key = 12; break; case 'italic': key = 13; break; case 'strike': key = 14; break; case 'spoil': key = 15; break; case 'code': key = 16; } } KeyEditListener.setTitle(el, key); return; } const txtaEl = pr.txta; const { selectionStart: start, selectionEnd: end } = txtaEl; const quote = Cfg.spacedQuote ? '> ' : '>'; if(id === 'de-btn-quote') { insertText(txtaEl, quote + (start === end ? quotetxt : txtaEl.value.substring(start, end)) .replace(/\n/gm, '\n' + quote)); quotetxt = ''; } else { const { scrtop } = txtaEl; const val = PostForm._wrapText(el.getAttribute('de-tag'), txtaEl.value.substring(start, end)); const len = start + val[0]; txtaEl.value = txtaEl.value.substr(0, start) + val[1] + txtaEl.value.substr(end); txtaEl.setSelectionRange(len, len); txtaEl.focus(); txtaEl.scrollTop = scrtop; } $pd(e); e.stopPropagation(); } refreshCap(isErr = false) { if(this.cap) { this.cap.refreshCaptcha(isErr, isErr, this.tNum); } } setPlaceholders() { if(aib.kusaba || !aib.multiFile && Cfg.fileInputs === 2) { return; } this._setPlaceholder('name'); this._setPlaceholder('subj'); this._setPlaceholder('mail'); this._setPlaceholder('video'); if(this.cap) { this._setPlaceholder('cap'); } } setReply(isQuick, needToHide) { if(isQuick) { $after(this.qArea.firstChild, this.pForm); } else { $after(this.pArea[+this.isBottom], this.qArea); $after(this._pBtn[+this.isBottom], this.pForm); } this.isHidden = needToHide; $toggle(this.qArea, isQuick); $toggle(this.pForm, !needToHide); this.updatePAreaBtns(); } showMainReply(isBottom, e) { this.closeReply(); if(!aib.t) { this.tNum = false; this.refreshCap(); } if(this.isBottom === isBottom) { $toggle(this.pForm, this.isHidden); this.isHidden = !this.isHidden; this.updatePAreaBtns(); } else { this.isBottom = isBottom; this.setReply(false, false); } if(e) { $pd(e); } } showQuickReply(post, pNum, isCloseReply, isNumClick, isNoLink = false) { if(!this.isQuick) { this.isQuick = true; this.setReply(true, false); $q('a', this._pBtn[+this.isBottom]).className = `de-abtn de-parea-btn-${ aib.t ? 'reply' : 'thr' }`; } else if(isCloseReply && !quotetxt && post.wrap.nextElementSibling === this.qArea) { this.closeReply(); return; } $after(post.wrap, this.qArea); if(this.qArea.classList.contains('de-win')) { updateWinZ(this.qArea.style); } const qNum = post.thr.num; if(!aib.t) { this._toggleQuickReply(qNum); } if(!this.form) { return; } if(!aib.t && this.tNum !== qNum) { this.tNum = qNum; this.refreshCap(); } this.tNum = qNum; const txt = this.txta.value; const isOnNewLine = txt === '' || txt.slice(-1) === '\n'; const link = isNoLink || post.isOp && !Cfg.addOPLink && !aib.t && !isNumClick ? '' : isNumClick ? `>>${ pNum }${ isOnNewLine ? '\n' : '' }` : (isOnNewLine ? '' : '\n') + (this.lastQuickPNum === pNum && txt.includes('>>' + pNum) ? '' : `>>${ pNum }\n`); const quote = !quotetxt ? '' : `${ quotetxt.replace(/^\n|\n$/g, '') .replace(/(^|\n)(.)/gm, `$1>${ Cfg.spacedQuote ? ' ' : '' }$2`) }\n`; insertText(this.txta, link + quote); const winTitle = post.thr.op.title.trim(); $q('.de-win-title', this.qArea).textContent = (winTitle.length < 28 ? winTitle : `${ winTitle.substr(0, 30) }\u2026`) || `#${ pNum }`; this.lastQuickPNum = pNum; } toggleSage() { if(!Cfg.addSageBtn || !this.mail) { return; } const isSage = Cfg.sageReply; this.sageBtn.style.opacity = isSage ? '1' : '.3'; this.sageBtn.title = isSage ? 'SAGE!' : Lng.noSage[lang]; if(this.mail.type === 'text') { this.mail.value = isSage ? 'sage' : aib._4chan ? 'noko' : ''; } else { this.mail.checked = isSage; } } updateLanguage() { this.txta.title = Lng.pasteImage[lang]; aib.updateSubmitBtn(this.subm); } updatePAreaBtns() { const txt = 'de-abtn de-parea-btn-'; const rep = aib.t ? 'reply' : 'thr'; $q('a', this._pBtn[+this.isBottom]).className = txt + (!this.pForm.style.display ? 'close' : rep); $q('a', this._pBtn[+!this.isBottom]).className = txt + rep; } static _wrapText(tag, text) { let isBB = aib.markupBB; if(tag.startsWith('[')) { tag = tag.substr(1); isBB = true; } if(isBB) { if(text.includes('\n')) { const str = `[${ tag }]${ text }[/${ tag }]`; return [str.length, str]; } const m = text.match(/^(\s*)(.*?)(\s*)$/); const str = `${ m[1] }[${ tag }]${ m[2] }[/${ tag }]${ m[3] }`; return [!m[2].length ? m[1].length + tag.length + 2 : str.length, str]; } let m, rv = '', i = 0; const arr = text.split('\n'); for(let len = arr.length; i < len; ++i) { m = arr[i].match(/^(\s*)(.*?)(\s*)$/); rv += '\n' + m[1] + (tag === '^H' ? m[2] + '^H'.repeat(m[2].length) : tag + m[2] + tag) + m[3]; } return [i === 1 && !m[2].length && tag !== '^H' ? m[1].length + tag.length : rv.length - 1, rv.slice(1)]; } _initAjaxPosting() { let el; if(aib.qFormRedir && (el = $q(aib.qFormRedir, this.form))) { aib.disableRedirection(el); } this.form.onsubmit = e => { $pd(e); $popup('upload', Lng.sending[lang], true); html5Submit(this.form, this.subm, true).then(checkUpload) .catch(err => $popup('upload', getErrorMessage(err))); }; } _initCaptcha() { const capEl = $q('input[type="text"][name*="aptcha"], *[id*="captcha"], *[class*="captcha"]', this.form); if(!capEl) { this.cap = null; return; } this.cap = new Captcha(capEl, this.tNum); const updCapFn = () => { this.cap.addCaptcha(); this.cap.updateOutdated(); }; this.txta.addEventListener('focus', updCapFn); if(this.files) { this.files.onchange = updCapFn; } this.form.addEventListener('click', () => this.cap.addCaptcha(), true); } _initFileInputs() { const fileEl = $q(aib.qFormFile, this.form); if(!fileEl) { return; } if(aib.fixFileInputs) { aib.fixFileInputs($qParent(fileEl, aib.qFormTd)); } this.files = new Files(this, $q(aib.qFormFile, this.form)); // We need to clear file inputs in case if session was restored. deWindow.addEventListener('load', () => setTimeout(() => !this.files.filesCount && this.files.clearInputs(), 0)); } _initSubmit() { this.subm.addEventListener('click', e => { if(aib.makaba && !aib._2channel && !Cfg.altCaptcha) { if(!this.cap.isSubmitWait) { $pd(e); $popup('upload', 'reCaptcha...', true); this.cap.isSubmitWait = true; this.refreshCap(); return; } this.cap.isSubmitWait = false; } if(Cfg.warnSubjTrip && this.subj && /#.|##./.test(this.subj.value)) { $pd(e); $popup('upload', Lng.subjHasTrip[lang]); return; } let val = this.txta.value; if(Spells.outreps) { val = Spells.outReplace(val); } if(this.tNum && pByNum.get(this.tNum).subj === 'Dollchan Extension Tools') { const temp = `\n\n${ PostForm._wrapText(aib.markupTags[5], `${ '-'.repeat(50) }\n${ nav.ua }\nv${ version }.${ commit }${ nav.isESNext ? '.es6' : '' } [${ nav.scriptHandler }]` )[1] }`; if(!val.includes(temp)) { val += temp; } } this.txta.value = val; this.toggleSage(); if(Cfg.ajaxPosting) { $popup('upload', Lng.checking[lang], true); } if(this.video && (val = this.video.value) && (val = val.match(Videos.ytReg))) { this.video.value = 'http://www.youtube.com/watch?v=' + val[1]; } if(this.isQuick) { $hide(this.pForm); $hide(this.qArea); $after(this._pBtn[+this.isBottom], this.pForm); } updater.pauseUpdater(); }); } _initTextarea() { const el = this.txta; if(aib.dobrochan) { el.removeAttribute('id'); } el.classList.add('de-textarea'); const { style } = el; style.setProperty('width', Cfg.textaWidth + 'px', 'important'); style.setProperty('height', Cfg.textaHeight + 'px', 'important'); // Allow to scroll page on PgUp/PgDn el.addEventListener('keypress', e => { const code = e.charCode || e.keyCode; if((code === 33 /* PgUp */ || code === 34 /* PgDn */) && e.which === 0) { e.target.blur(); deWindow.focus(); } }); // Add image from clipboard to file inputs on Ctrl+V el.addEventListener('paste', e => { if('clipboardData' in e) { for(const item of e.clipboardData.items) { if(item.kind === 'file') { const inputs = this.files._inputs; for(let i = 0, len = inputs.length; i < len; ++i) { const input = inputs[i]; if(!input.hasFile) { const file = item.getAsFile(); input._addUrlFile(URL.createObjectURL(file), file); break; } } } } } }); // Make textarea resizer if(nav.isFirefox || nav.isWebkit) { el.addEventListener('mouseup', ({ target }) => { const s = target.style; const { width, height } = s; s.setProperty('width', width + 'px', 'important'); s.setProperty('height', height + 'px', 'important'); saveCfg('textaWidth', parseInt(width, 10)); saveCfg('textaHeight', parseInt(height, 10)); }); return; } $aEnd(el, '
').addEventListener('mousedown', { _el : el, _elStyle : style, handleEvent(e) { switch(e.type) { case 'mousedown': docBody.addEventListener('mousemove', this); docBody.addEventListener('mouseup', this); $pd(e); return; case 'mousemove': { const cr = this._el.getBoundingClientRect(); this._elStyle.setProperty('width', (e.clientX - cr.left) + 'px', 'important'); this._elStyle.setProperty('height', (e.clientY - cr.top) + 'px', 'important'); return; } default: // mouseup docBody.removeEventListener('mousemove', this); docBody.removeEventListener('mouseup', this); saveCfg('textaWidth', parseInt(this._elStyle.width, 10)); saveCfg('textaHeight', parseInt(this._elStyle.height, 10)); } } }); } _makeHideableContainer() { this.pForm = $add('
'); if(this.form) { this.pForm.appendChild(this.form); } if(this.oeForm) { this.pForm.appendChild(this.oeForm); } const html = '
[]

'; this.pArea = [ $bBegin(DelForm.first.el, html), $aEnd(aib._4chan ? $q('.board', DelForm.first.el) : DelForm.first.el, html) ]; this._pBtn = [this.pArea[0].firstChild, this.pArea[1].firstChild]; this._pBtn[0].firstElementChild.onclick = e => this.showMainReply(false, e); this._pBtn[1].firstElementChild.onclick = e => this.showMainReply(true, e); this.qArea = $add(``); this.isBottom = Cfg.addPostForm === 1; this.setReply(false, !aib.t || Cfg.addPostForm > 1); } _makeWindow() { makeDraggable('reply', this.qArea, $aBegin(this.qArea, `
`)); const buttons = $q('.de-win-buttons', this.qArea); buttons.onmouseover = ({ target }) => { const el = target.parentNode; switch(fixEventEl(target).classList[0]) { case 'de-win-btn-clear': el.title = Lng.clearForm[lang]; break; case 'de-win-btn-close': el.title = Lng.closeReply[lang]; break; case 'de-win-btn-toggle': el.title = Cfg.replyWinDrag ? Lng.underPost[lang] : Lng.makeDrag[lang]; } }; const [clearBtn, toggleBtn, closeBtn] = [...buttons.children]; clearBtn.onclick = () => { saveCfg('sageReply', 0); this.toggleSage(); this.files.clearInputs(); [this.txta, this.name, this.mail, this.subj, this.video, this.cap && this.cap.textEl].forEach( el => el && (el.value = '')); }; toggleBtn.onclick = () => { toggleCfg('replyWinDrag'); if(Cfg.replyWinDrag) { this.qArea.className = aib.cReply + ' de-win'; updateWinZ(this.qArea.style); } else { this.qArea.className = aib.cReply + ' de-win-inpost'; this.txta.focus(); } }; closeBtn.onclick = () => this.closeReply(); } _setPlaceholder(val) { const el = val === 'cap' ? this.cap.textEl : this[val]; if(el) { toggleAttr(el, 'placeholder', Lng[val][lang], aib.multiFile || Cfg.fileInputs !== 2); } } _toggleQuickReply(tNum) { if(this.oeForm) { $del($q('input[name="oek_parent"]', this.oeForm)); if(tNum) { this.oeForm.insertAdjacentHTML('afterbegin', ``); } } if(this.form) { if(aib.changeReplyMode && tNum !== this.tNum) { aib.changeReplyMode(this.form, tNum); } $del($q(`input[name="${ aib.formParent }"]`, this.form)); if(tNum) { this.form.insertAdjacentHTML('afterbegin', ``); } } } } /* ==[ FormSubmit.js ]======================================================================================== SUBMIT postform/delform html5/iframe submit, images and webms parsing, duplicate files posting, EXIF clearing =========================================================================================================== */ function getSubmitError(dc) { if(!dc.body.hasChildNodes() || $q(aib.qDForm, dc)) { return null; } const err = [...$Q(aib.qError, dc)].map(str => str.innerHTML + '\n').join('') .replace(/]+>Назад.+| AjaxError.Success, err => err).then(err => { infoLoadErrors(err); if(Cfg.scrAfterRep) { scrollTo(0, deWindow.pageYOffset + Thread.first.last.el.getBoundingClientRect().top); } updater.continueUpdater(true); closePopup('upload'); }); } else { pByNum.get(tNum).thr.loadPosts('new', false, false).then(() => closePopup('upload')); } pr.closeReply(); pr.refreshCap(); } async function checkDelete(data) { const err = getSubmitError(data instanceof HTMLDocument ? data : $DOM(data)); if(err) { $popup('delete', Lng.errDelete[lang] + ':\n' + err); updater.sendErrNotif(); return; } const els = $Q(`[de-form] ${ aib.qRPost.split(', ').join(' input:checked, [de-form] ') } input:checked`); const threads = new Set(); const isThr = aib.t; for(let i = 0, len = els.length; i < len; ++i) { const el = els[i]; el.checked = false; if(!isThr) { threads.add(aib.getPostOfEl(el).thr); } } if(isThr) { Post.clearMarks(); await Thread.first.loadNewPosts().catch(err => infoLoadErrors(err)); } else { await Promise.all([...threads].map(thr => thr.loadPosts('new', false, false))); } $popup('delete', Lng.succDeleted[lang]); } // https://html.spec.whatwg.org/multipage/forms.html#concept-fe-disabled function isFormElDisabled(el) { switch(el.tagName.toLowerCase()) { case 'button': case 'input': case 'select': case 'textarea': if(el.hasAttribute('disabled')) { return true; } /* falls through */ default: if(nav.matchesSelector(el, 'fieldset[disabled] > :not(legend):not(:first-of-type) *')) { return true; } } return false; } // https://html.spec.whatwg.org/multipage/forms.html#constructing-form-data-set function * getFormElements(form, submitter) { const controls = $Q('button, input, keygen, object, select, textarea', form); const fixName = name => name ? name.replace(/([^\r])\n|\r([^\n])/g, '$1\r\n$2') : ''; constructSet: for(let i = 0, len = controls.length; i < len; ++i) { const field = controls[i]; const tagName = field.tagName.toLowerCase(); const type = field.getAttribute('type'); const name = field.getAttribute('name'); if($parent(field, 'DATALIST', form) || isFormElDisabled(field) || field !== submitter && ( tagName === 'button' || tagName === 'input' && (type === 'submit' || type === 'reset' || type === 'button') ) || tagName === 'input' && ( type === 'checkbox' && !field.checked || type === 'radio' && !field.checked || type === 'image' && !name ) || tagName === 'object' ) { continue; } if(tagName === 'select') { const options = $Q('select > option, select > optgrout > option', field); for(let j = 0, jlen = options.length; j < jlen; ++j) { const option = options[j]; if(option.selected && !isFormElDisabled(option)) { yield { type, el: field, name: fixName(name), value: option.value }; } } } else if(tagName === 'input') { switch(type) { case 'image': throw new Error('input[type="image"] is not supported'); case 'checkbox': case 'radio': yield { type, el: field, name: fixName(name), value: field.value || 'on' }; continue constructSet; case 'file': { let img; if(field.files.length > 0) { const { files } = field; for(let j = 0, jlen = files.length; j < jlen; ++j) { yield { name, type, el: field, value: files[j] }; } } else if(field.obj && (img = field.obj.imgFile)) { yield { name, type, el : field, value : new File([img.data], img.name, { type: img.type }) }; } else { yield { el : field, name : fixName(name), type : 'application/octet-stream', value : new File([''], '') }; } continue constructSet; } } } if(type === 'textarea') { yield { type, el: field, name: name || '', value: field.value }; } else { yield { type, el: field, name: fixName(name), value: field.value }; } const dirname = field.getAttribute('dirname'); if(dirname) { yield { el : field, name : fixName(dirname), type : 'direction', value : nav.matchesSelector(field, ':dir(rtl)') ? 'rtl' : 'ltr' }; } } } function getUploadFunc() { $popup('upload', Lng.sending[lang] + '
' + ' / ()
', true); let isInited = false; const beginTime = Date.now(); const progress = $id('de-uploadprogress'); const counterWrap = progress.nextElementSibling; const [counterEl, totalEl, speedEl] = [...counterWrap.children]; return ({ total, loaded: i }) => { if(!isInited) { progress.setAttribute('max', total); $show(progress); totalEl.textContent = prettifySize(total); $show(counterWrap); isInited = true; } progress.value = i; counterEl.textContent = prettifySize(i); speedEl.textContent = `${ prettifySize(1e3 * i / (Date.now() - beginTime)) }/${ Lng.second[lang] }`; }; } async function html5Submit(form, submitter, needProgress = false) { const data = new FormData(); let hasFiles = false; for(const { name, value, type, el } of getFormElements(form, submitter)) { let val = value; if(name === 'de-file-txt') { continue; } if(type === 'file') { hasFiles = true; const fileName = value.name; const fileExt = fileName.substring(fileName.lastIndexOf('.')); const newFileName = !Cfg.removeFName || el.obj && el.obj.imgFile && el.obj.imgFile.isConstName ? fileName : ( Cfg.removeFName === 1 ? '' : // 5 years = 5*365*24*60*60*1e3 = 15768e7 Date.now() - (Cfg.removeFName === 2 ? 0 : Math.round(Math.random() * 15768e7)) ) + fileExt; const mime = value.type; if((Cfg.postSameImg || Cfg.removeEXIF) && ( mime === 'image/jpeg' || mime === 'image/png' || mime === 'image/gif' || mime === 'video/webm' && !aib.makaba) ) { const cleanData = cleanFile((await readFile(value)).data, el.obj ? el.obj.extraFile : null); if(!cleanData) { return Promise.reject(new Error(Lng.fileCorrupt[lang] + ': ' + fileName)); } val = new File(cleanData, newFileName, { type: mime }); } else if(Cfg.removeFName) { val = new File([value], newFileName, { type: mime }); } } data.append(name, val); } if(aib.sendHTML5Post) { return aib.sendHTML5Post(form, data, needProgress, hasFiles); } const ajaxParams = { data, method: 'POST' }; if(needProgress && hasFiles) { ajaxParams.onprogress = getUploadFunc(); } return $ajax(form.action, ajaxParams) .then(xhr => aib.jsonSubmit ? xhr.responseText : $DOM(xhr.responseText)) .catch(err => Promise.reject(err)); } function cleanFile(data, extraData) { const img = nav.getUnsafeUint8Array(data); const rand = Cfg.postSameImg && String(Math.round(Math.random() * 1e6)); const rv = extraData ? rand ? [img, extraData, rand] : [img, extraData] : rand ? [img, rand] : [img]; const rExif = !!Cfg.removeEXIF; if(!rand && !rExif && !extraData) { return rv; } let i, len, val, lIdx, jpgDat; const subarray = (begin, end) => nav.getUnsafeUint8Array(data, begin, end - begin); // JPG if(img[0] === 0xFF && img[1] === 0xD8) { let deep = 1; for(i = 2, len = img.length - 1, val = [null, null], lIdx = 2, jpgDat = null; i < len;) { if(img[i] === 0xFF) { if(rExif) { // Remove exif data if(!jpgDat && deep === 1) { if(img[i + 1] === 0xE1 && img[i + 4] === 0x45) { jpgDat = readExif(data, i + 10, (img[i + 2] << 8) + img[i + 3]); } else if(img[i + 1] === 0xE0 && img[i + 7] === 0x46 && (img[i + 2] !== 0 || img[i + 3] >= 0x0E || img[i + 15] !== 0xFF) ) { jpgDat = subarray(i + 11, i + 16); } } if(((img[i + 1] >> 4) === 0xE && img[i + 1] !== 0xEE) || img[i + 1] === 0xFE) { if(lIdx !== i) { val.push(subarray(lIdx, i)); } i += 2 + (img[i + 2] << 8) + img[i + 3]; lIdx = i; continue; } } else if(img[i + 1] === 0xD8) { // Jpg start marker [0xFFD8] deep++; i++; continue; } if(img[i + 1] === 0xD9 && --deep === 0) { // Jpg end marker [0xFFD9] break; } } i++; } i += 2; if(!extraData && len - i > 75) { i = len; } if(lIdx === 2) { // Remove data after the end marker if(i !== len) { rv[0] = nav.getUnsafeUint8Array(data, 0, i); } return rv; } val[0] = new Uint8Array([0xFF, 0xD8, 0xFF, 0xE0, 0, 0x0E, 0x4A, 0x46, 0x49, 0x46, 0, 1, 1]); val[1] = jpgDat || new Uint8Array([0, 0, 1, 0, 1]); val.push(subarray(lIdx, i)); if(extraData) { val.push(extraData); } if(rand) { val.push(rand); } return val; } // PNG if(img[0] === 0x89 && img[1] === 0x50) { // Search for end marker [0x49454e44] for(i = 0, len = img.length - 7; i < len && ( img[i] !== 0x49 || img[i + 1] !== 0x45 || img[i + 2] !== 0x4E || img[i + 3] !== 0x44 ); ++i) /* empty */; i += 8; // Remove data after the end marker if(i !== len && (extraData || len - i <= 75)) { rv[0] = nav.getUnsafeUint8Array(data, 0, i); } return rv; } // GIF if(img[0] === 0x47 && img[1] === 0x49 && img[2] === 0x46) { // Search for last frame end marker [0x003B] i = len = img.length; while(i && img[--i - 1] !== 0x00 && img[i] !== 0x3B) /* empty */; // Remove data after the end marker if(++i !== len) { rv[0] = nav.getUnsafeUint8Array(data, 0, i); } return rv; } // WEBM if(img[0] === 0x1a && img[1] === 0x45 && img[2] === 0xDF && img[3] === 0xA3) { return new WebmParser(data).addWebmData(rand).getWebmData(); } return null; } function readExif(data, off, len) { let xRes = 0; let yRes = 0; let resT = 0; const dv = nav.getUnsafeDataView(data, off); const le = String.fromCharCode(dv.getUint8(0), dv.getUint8(1)) !== 'MM'; if(dv.getUint16(2, le) !== 0x2A) { return null; } const i = dv.getUint32(4, le); if(i > len) { return null; } for(let j = 0, tgLen = dv.getUint16(i, le); j < tgLen; ++j) { let dE = i + 2 + 12 * j; const tag = dv.getUint16(dE, le); if(tag === 0x0128) { resT = dv.getUint16(dE + 8, le) - 1; } else if(tag === 0x011A || tag === 0x011B) { dE = dv.getUint32(dE + 8, le); if(dE > len) { return null; } if(tag === 0x11A) { xRes = Math.round(dv.getUint32(dE, le) / dv.getUint32(dE + 4, le)); } else { yRes = Math.round(dv.getUint32(dE, le) / dv.getUint32(dE + 4, le)); } } } xRes = xRes || yRes; yRes = yRes || xRes; return new Uint8Array([resT & 0xFF, xRes >> 8, xRes & 0xFF, yRes >> 8, yRes & 0xFF]); } /* ==[ FormFile.js ]========================================================================================== FILE INPUTS image/video files in postform: preview, adding by url, drag-n-drop, deleting =========================================================================================================== */ class Files { constructor(form, fileEl) { this.filesCount = 0; this.fileTr = $qParent(fileEl, aib.qFormTr); this.onchange = null; this._form = form; this._inputs = []; const els = $Q('input[type="file"]', this.fileTr); for(let i = 0, len = els.length; i < len; ++i) { this._inputs.push(new FileInput(this, els[i])); } this._files = []; this.hideEmpty(); } get rarInput() { const value = $bEnd(docBody, ''); Object.defineProperty(this, 'rarInput', { value }); return value; } get thumbsEl() { let value; if(aib.multiFile) { value = $aEnd(this.fileTr, '
'); } else { value = $qParent(this._form.txta, aib.qFormTd).previousElementSibling; value.innerHTML = `
${ value.innerHTML }
`; value = value.lastChild; } Object.defineProperty(this, 'thumbsEl', { value }); return value; } changeMode() { const isThumbMode = Cfg.fileInputs === 2; for(const inp of this._inputs) { inp.changeMode(isThumbMode); } this.hideEmpty(); } clearInputs() { for(const inp of this._inputs) { inp.clearInp(); } this.hideEmpty(); } hideEmpty() { for(let els = this._inputs, i = els.length - 1; i > 0; --i) { const inp = els[i]; if(inp.hasFile) { break; } else if(els[i - 1].hasFile) { inp.showInp(); break; } inp.hideInp(); } } } class FileInput { constructor(parent, el) { this.extraFile = null; this.hasFile = false; this.imgFile = null; this._input = el; this._isTxtEditable = false; this._isTxtEditName = false; this._mediaEl = null; this._parent = parent; this._rarMsg = null; this._spoilEl = $q(aib.qFormSpoiler, el.parentNode); this._thumb = null; this._utils = $add(`
`); [this._btnRar, this._btnSpoil, this._btnTxt, this._btnRen, this._btnDel] = [...this._utils.children]; this._utils.addEventListener('click', this); this._txtWrap = $add(` `); [this._txtInput, this._txtAddBtn] = [...this._txtWrap.children]; this._txtWrap.addEventListener('click', this); this._toggleDragEvents(this._txtWrap, true); el.obj = this; el.classList.add('de-file-input'); el.addEventListener('change', this); if(el.files && el.files[0]) { this._removeFile(); } if(Cfg.fileInputs) { $hide(el); if(aib.multiFile) { this._input.setAttribute('multiple', true); } } if(FileInput._isThumbMode) { this._initThumbs(); } else { $before(this._input, this._txtWrap); $after(this._input, this._utils); } } changeMode(showThumbs) { $toggle(this._input, !Cfg.fileInputs); toggleAttr(this._input, 'multiple', true, aib.multiFile && Cfg.fileInputs); $toggle(this._btnRen, Cfg.fileInputs && this.hasFile); if(!(showThumbs ^ !!this._thumb)) { return; } if(showThumbs) { this._initThumbs(); return; } $before(this._input, this._txtWrap); $after(this._input, this._utils); $del($q('de-file-txt-area')); $show(this._parent.fileTr); $show(this._txtWrap); if(this._mediaEl) { deWindow.URL.revokeObjectURL(this._mediaEl.src); } this._toggleDragEvents(this._thumb, false); $del(this._thumb); this._thumb = this._mediaEl = null; } clearInp() { if(FileInput._isThumbMode) { this._thumb.classList.add('de-file-off'); if(this._mediaEl) { deWindow.URL.revokeObjectURL(this._mediaEl.src); this._mediaEl.parentNode.title = Lng.youCanDrag[lang]; this._mediaEl.remove(); this._mediaEl = null; } } if(this._btnDel) { this._toggleDelBtn(false); $hide(this._btnSpoil); if(this._spoilEl) { this._spoilEl.checked = this._btnSpoil.checked = false; } $hide(this._btnRar); $hide(this._txtAddBtn); $del(this._rarMsg); if(FileInput._isThumbMode) { $hide(this._txtWrap); } this._txtInput.value = ''; this._txtInput.classList.add('de-file-txt-noedit'); this._txtInput.placeholder = Lng.dropFileHere[lang]; } this.extraFile = this.imgFile = null; this._isTxtEditable = this._isTxtEditName = false; this._changeFilesCount(-1); this._removeFile(); } handleEvent(e) { const el = e.target; const thumb = this._thumb; const isThumb = el === thumb || el.className === 'de-file-img'; switch(e.type) { case 'change': { const inpArray = this._parent._inputs; const curInpIdx = inpArray.indexOf(this); const filesLen = el.files.length; if(filesLen > 1) { const allowedLen = Math.min(filesLen, inpArray.length - curInpIdx); let j = allowedLen; for(let i = 0; i < allowedLen; ++i) { FileInput._readDroppedFile(inpArray[curInpIdx + i], el.files[i]).then(() => { if(!--j) { // Clear original file input after all allowed files will be read. this._removeFileHelper(); } }); this._parent._files[curInpIdx + i] = el.files[i]; } } else { if(filesLen > 0) { setTimeout(() => this._onFileChange(false), 20); this._parent._files[curInpIdx] = el.files[0]; } else { this.clearInp(); delete this._parent._files[curInpIdx]; } } DollchanAPI.notify('filechange', this._parent._files); return; } case 'click': { const parent = el.parentNode; if(isThumb) { this._input.click(); } else if(parent === this._btnDel) { this.clearInp(); this._parent.hideEmpty(); delete this._parent._files[this._parent._inputs.indexOf(this)]; DollchanAPI.notify('filechange', this._parent._files); } else if(parent === this._btnRar) { this._addRarJpeg(); } else if(parent === this._btnRen) { const isShow = this._isTxtEditName = !this._isTxtEditName; this._isTxtEditable = !this._isTxtEditable; if(FileInput._isThumbMode) { $toggle(this._txtWrap, isShow); } $toggle(this._txtAddBtn, isShow); this._txtInput.classList.toggle('de-file-txt-noedit', !isShow); if(isShow) { this._txtInput.focus(); } } else if(parent === this._btnTxt) { this._toggleDelBtn(this._isTxtEditable = true); $show(this._txtAddBtn); if(FileInput._isThumbMode) { $toggle(this._txtWrap); } this._txtInput.classList.remove('de-file-txt-noedit'); this._txtInput.placeholder = Lng.enterTheLink[lang]; this._txtInput.focus(); } else if(el === this._btnSpoil) { this._spoilEl.checked = this._btnSpoil.checked; return; } else if(el === this._txtAddBtn) { if(this._isTxtEditName) { if(FileInput._isThumbMode) { $hide(this._txtWrap); } $hide(this._txtAddBtn); this._txtInput.classList.add('de-file-txt-noedit'); this._isTxtEditable = this._isTxtEditName = false; const newName = this._txtInput.value; if(!newName) { this._txtInput.value = this.imgFile ? this.imgFile.name : this._input.files[0].name; return; } if(this.imgFile) { this.imgFile.isConstName = true; this.imgFile.name = newName; if(FileInput._isThumbMode) { this._addThumbTitle(newName, this.imgFile.data.byteLength); } return; } const file = this._input.files[0]; readFile(file).then(({ data }) => { this.imgFile = { data, name: newName, type: file.type, isConstName: true }; this._removeFileHelper(); // Clear the original file if(FileInput._isThumbMode) { this._addThumbTitle(newName, data.byteLength); } }); return; } else { this._addUrlFile(this._txtInput.value); } } else if(el === this._txtInput && !this._isTxtEditable) { this._input.click(); this._txtInput.blur(); } $pd(e); e.stopPropagation(); return; } case 'dragenter': if(isThumb) { thumb.classList.add('de-file-drag'); } return; case 'dragleave': if(isThumb && el.classList.contains('de-file-img')) { thumb.classList.remove('de-file-drag'); } return; case 'drop': { const dt = e.dataTransfer; if(!isThumb && el !== this._txtInput) { return; } const filesLen = dt.files.length; if(filesLen) { const inpArray = this._parent._inputs; const inpLen = inpArray.length; for(let i = inpArray.indexOf(this), j = 0; i < inpLen && j < filesLen; ++i, ++j) { FileInput._readDroppedFile(inpArray[i], dt.files[j]); this._parent._files[i] = dt.files[j]; } DollchanAPI.notify('filechange', this._parent._files); } else { this._addUrlFile(dt.getData('text/plain')); } if(FileInput._isThumbMode) { setTimeout(() => thumb.classList.remove('de-file-drag'), 10); } $pd(e); e.stopPropagation(); } } } hideInp() { if(FileInput._isThumbMode) { this._toggleDelBtn(false); $hide(this._thumb); $hide(this._txtWrap); } $hide(this._wrap); } showInp() { if(FileInput._isThumbMode) { $show(this._thumb); } $show(this._wrap); } static get _isThumbMode() { return Cfg.fileInputs === 2; } static _readDroppedFile(inputObj, file) { return readFile(file).then(({ data }) => { inputObj.imgFile = { data, name: file.name, type: file.type }; inputObj.showInp(); inputObj._onFileChange(true); }); } get _wrap() { return aib.multiFile ? this._input.parentNode : this._input; } _addNewThumb(fileData, fileName, fileType, fileSize) { let el = this._thumb; el.classList.remove('de-file-off'); el = el.firstChild.firstChild; el.title = `${ fileName }, ${ (fileSize / 1024).toFixed(2) }KB`; this._mediaEl = el = $aBegin(el, fileType.startsWith('video/') ? '' : ''); el.src = deWindow.URL.createObjectURL(new Blob([fileData])); if((el = el.nextSibling)) { deWindow.URL.revokeObjectURL(el.src); el.remove(); } } _addRarJpeg() { const el = this._parent.rarInput; el.onchange = e => { $hide(this._btnRar); const myBtn = this._rarMsg = $aBegin(this._utils, ''); const file = e.target.files[0]; readFile(file).then(({ data }) => { if(this._rarMsg === myBtn) { myBtn.className = 'de-file-rarmsg'; const origFileName = this.imgFile ? this.imgFile.name : this._input.files[0].name; myBtn.title = origFileName + ' + ' + file.name; myBtn.textContent = origFileName.split('.').pop() + ' + ' + file.name.split('.').pop(); this.extraFile = data; } }); }; el.click(); } _addThumbTitle(name, size) { this._thumb.firstChild.firstChild.title = `${ name }, ${ (size / 1024).toFixed(2) }KB`; } _addUrlFile(url, file = null) { if(!url) { return Promise.reject(new Error('URL is null')); } $popup('file-loading', Lng.loading[lang], true); return ContentLoader.loadImgData(url, false).then(data => { if(file) { deWindow.URL.revokeObjectURL(url); } if(!data) { $popup('file-loading', Lng.cantLoad[lang] + ' URL: ' + url); return; } closePopup('file-loading'); this._isTxtEditable = this._isTxtEditName = false; let name = file ? file.name : url.split('/').pop(); const type = file && file.type || getFileType(name); if(!type || name.includes('?')) { let ext; switch((data[0] << 8) | data[1]) { case 0xFFD8: ext = 'jpg'; break; case 0x8950: ext = 'png'; break; case 0x4749: ext = 'gif'; break; case 0x1A45: ext = 'webm'; break; default: ext = ''; } if(ext) { name = name.split('?').shift() + '.' + ext; } } this.imgFile = { data: data.buffer, name, type: type || getFileType(name) }; if(!file) { file = new Blob([data], { type: this.imgFile.type }); file.name = name; } this._parent._files[this._parent._inputs.indexOf(this)] = file; DollchanAPI.notify('filechange', this._parent._files); if(FileInput._isThumbMode) { $hide(this._txtWrap); } this._onFileChange(true); }); } _changeFilesCount(val) { this._parent.filesCount = Math.max(this._parent.filesCount + val, 0); if(aib.dobrochan) { $id('post_files_count').value = this._parent.filesCount + 1; } } _initThumbs() { const { fileTr } = this._parent; $hide(fileTr); $hide(this._txtWrap); const isTr = fileTr.tagName === 'TR'; const txtArea = $q('.de-file-txt-area') || $bBegin(fileTr, isTr ? '' : '
'); (isTr ? txtArea.lastChild : txtArea).appendChild(this._txtWrap); this._thumb = $bEnd(this._parent.thumbsEl, `
`); this._thumb.addEventListener('click', this); this._thumb.addEventListener('dragenter', this); this._thumb.appendChild(this._utils); this._toggleDragEvents(this._thumb, true); if(this.hasFile) { this._showFileThumb(); } } _onFileChange(hasImgFile) { this._txtInput.value = hasImgFile ? this.imgFile.name : this._input.files[0].name; if(!hasImgFile) { this.imgFile = null; } if(this._parent.onchange) { this._parent.onchange(); } if(FileInput._isThumbMode) { this._showFileThumb(); } if(this.hasFile) { this.extraFile = null; } else { this.hasFile = true; this._changeFilesCount(+1); this._toggleDelBtn(true); $hide(this._txtAddBtn); if(FileInput._isThumbMode) { $hide(this._txtWrap); } if(this._spoilEl) { this._btnSpoil.checked = this._spoilEl.checked; $show(this._btnSpoil); } this._txtInput.classList.add('de-file-txt-noedit'); this._txtInput.placeholder = Lng.dropFileHere[lang]; } this._parent.hideEmpty(); if(!nav.isPresto && !aib._4chan && /^image\/(?:png|jpeg)$/.test(hasImgFile ? this.imgFile.type : this._input.files[0].type) ) { $del(this._rarMsg); $show(this._btnRar); } } _removeFile() { this._removeFileHelper(); this.hasFile = false; if(this._parent._files) { delete this._parent._files[this._parent._inputs.indexOf(this)]; } } _removeFileHelper() { const oldEl = this._input; const newEl = $aEnd(oldEl, oldEl.outerHTML); oldEl.removeEventListener('change', this); newEl.addEventListener('change', this); newEl.obj = this; this._input = newEl; oldEl.remove(); } _showFileThumb() { const { imgFile } = this; if(imgFile) { this._addNewThumb(imgFile.data, imgFile.name, imgFile.type, imgFile.data.byteLength); return; } const file = this._input.files[0]; if(file) { readFile(file).then(({ data }) => { if(this._input.files[0] === file) { this._addNewThumb(data, file.name, file.type, file.size); } }); } } _toggleDelBtn(isShow) { $toggle(this._btnDel, isShow); $toggle(this._btnRen, Cfg.fileInputs && isShow && this.hasFile); $toggle(this._btnTxt, !isShow); } _toggleDragEvents(el, isAdd) { const name = isAdd ? 'addEventListener' : 'removeEventListener'; el[name]('dragover', $pd); el[name]('dragenter', this); el[name]('dragleave', this); el[name]('drop', this); } } /* ==[ FormCaptcha.js ]======================================================================================= CAPTCHA =========================================================================================================== */ class Captcha { constructor(el, initNum) { this.hasCaptcha = true; this.textEl = null; this.tNum = initNum; this.parentEl = nav.matchesSelector(el, aib.qFormTr) ? el : aib.getCapParent(el); this.isAdded = false; this.isSubmitWait = false; this._isRecap = !aib._02ch && !!$q('[id*="recaptcha"], [class*="recaptcha"]', this.parentEl); this._lastUpdate = null; this.originHTML = this.parentEl.innerHTML; $hide(this.parentEl); if(!this._isRecap) { this.parentEl.innerHTML = ''; } } addCaptcha() { if(this.isAdded) { // Run this function only once return; } this.isAdded = true; if(!this._isRecap) { this.parentEl.innerHTML = this.originHTML; this.textEl = $q('input[type="text"][name*="aptcha"]', this.parentEl); } else { const el = $q('#g-recaptcha, .g-recaptcha'); $replace(el, `
`); } this.initCapPromise(); } handleEvent(e) { switch(e.type) { case 'keypress': { if(!Cfg.captchaLang || e.which === 0) { return; } const ruUa = 'йцукенгшщзхъїфыівапролджэєячсмитьбюёґ'; const en = "qwertyuiop[]]assdfghjkl;''zxcvbnm,.`\\"; const code = e.charCode || e.keyCode; let i, chr = String.fromCharCode(code).toLowerCase(); if(Cfg.captchaLang === 1) { if(code < 0x0410 || code > 0x04FF || (i = ruUa.indexOf(chr)) === -1) { return; } chr = en[i]; } else { if(code < 0x0021 || code > 0x007A || (i = en.indexOf(chr)) === -1) { return; } chr = ruUa[i]; } insertText(e.target, chr); break; } case 'focus': this.updateOutdated(); } $pd(e); e.stopPropagation(); } initCapPromise() { const initPromise = aib.initCaptcha ? aib.initCaptcha(this) : null; if(initPromise) { initPromise.then(() => this.showCaptcha(), err => { if(err instanceof AjaxError) { this._setUpdateError(err); } else { this.hasCaptcha = false; } }); } else if(this.hasCaptcha) { this.showCaptcha(true); } } initImage(img) { img.title = Lng.refresh[lang]; img.alt = Lng.loading[lang]; img.style.cssText = 'vertical-align: text-bottom; border: none; cursor: pointer;'; img.onclick = () => this.refreshCaptcha(true); } initTextEl() { this.textEl.autocomplete = 'off'; if(!aib.kusaba && (aib.multiFile || Cfg.fileInputs !== 2)) { this.textEl.placeholder = Lng.cap[lang]; } this.textEl.addEventListener('keypress', this); this.textEl.onkeypress = null; this.textEl.addEventListener('focus', this); this.textEl.onfocus = null; } showCaptcha(isUpdateImage = false) { if(!this.textEl) { $show(this.parentEl); if(aib.updateCaptcha) { aib.updateCaptcha(this, false); } else if(this._isRecap) { this._updateRecap(); } return; } this.initTextEl(); let img; if(this._isRecap || !(img = $q('img', this.parentEl))) { $show(this.parentEl); return; } this.initImage(img); const a = img.parentNode; if(a.tagName === 'A') { $replace(a, img); } if(isUpdateImage) { this.refreshCaptcha(false); } else { this._lastUpdate = Date.now(); } $show(this.parentEl); } refreshCaptcha(isFocus, isErr = false, tNum = this.tNum) { if(!this.isAdded || tNum !== this.tNum) { this.tNum = tNum; this.isAdded = false; this.hasCaptcha = true; this.textEl = null; $hide(this.parentEl); this.addCaptcha(); return; } else if(!this.hasCaptcha && !isErr) { return; } this._lastUpdate = Date.now(); if(aib.updateCaptcha) { const updatePromise = aib.updateCaptcha(this, isErr); if(updatePromise) { updatePromise.then(() => this._updateTextEl(isFocus), err => this._setUpdateError(err)); } } else if(this._isRecap) { this._updateRecap(); } else if(this.textEl) { this._updateTextEl(isFocus); const img = $q('img', this.parentEl); if(!img) { return; } if(aib.getCaptchaSrc) { const src = img.getAttribute('src'); if(src) { img.src = ''; img.src = aib.getCaptchaSrc(src, tNum); } } else { img.click(); } } } updateHelper(url, fn) { if(aib._capUpdPromise) { aib._capUpdPromise.cancelPromise(); } return (aib._capUpdPromise = $ajax(url).then(xhr => { aib._capUpdPromise = null; fn(xhr); }, err => { if(!(err instanceof CancelError)) { aib._capUpdPromise = null; return CancelablePromise.reject(err); } })); } updateOutdated() { if(this._lastUpdate && (Date.now() - this._lastUpdate > Cfg.capUpdTime * 1e3)) { this.refreshCaptcha(false); } } _setUpdateError(e) { if(e) { this.parentEl = e.toString(); this.isAdded = false; this.parentEl.onclick = () => { this.parentEl.onclick = null; this.addCaptcha(); }; $show(this.parentEl); } } _updateRecap() { // EXCLUDED FROM FIREFOX EXTENSION - START const script = doc.createElement('script'); script.type = 'text/javascript'; script.src = aib.prot + '//www.google.com/recaptcha/api.js'; doc.head.appendChild(script); setTimeout(() => script.remove(), 1e5); // EXCLUDED FROM FIREFOX EXTENSION - END } _updateTextEl(isFocus) { if(this.textEl) { this.textEl.value = ''; if(isFocus) { this.textEl.focus(); } } } } /* ==[ Posts.js ]============================================================================================= POSTS =========================================================================================================== */ class AbstractPost { constructor(thr, num, isOp) { this.isOp = isOp; this.kid = null; this.num = num; this.ref = new RefMap(this); this.thr = thr; this._hasEvents = false; this._linkDelay = 0; this._menu = null; this._menuDelay = 0; } get btnFav() { const value = $q('.de-btn-fav, .de-btn-fav-sel', this.btns); Object.defineProperty(this, 'btnFav', { value }); return value; } get btnHide() { const value = this.btns.firstChild; Object.defineProperty(this, 'btnHide', { value }); return value; } get images() { const value = new PostImages(this); Object.defineProperty(this, 'images', { value }); return value; } get mp3Obj() { const value = $bBegin(this.msg, '
'); Object.defineProperty(this, 'mp3Obj', { value }); return value; } * refLinks() { const links = $Q('a', this.msg); for(let lNum, i = 0, len = links.length; i < len; ++i) { const link = links[i]; const tc = link.textContent; if(tc[0] !== '>' || tc[1] !== '>' || !(lNum = parseInt(tc.substr(2), 10))) { continue; } yield [link, lNum]; } } get msg() { const value = $q(aib.qPostMsg, this.el); Object.defineProperty(this, 'msg', { value, configurable: true }); return value; } get trunc() { let value = null; const el = aib.qTrunc && $q(aib.qTrunc, this.el); if(el && /long|full comment|gekürzt|слишком|длинн|мног|полн/i.test(el.textContent)) { value = el; } Object.defineProperty(this, 'trunc', { value, configurable: true }); return value; } get videos() { const value = Cfg.embedYTube ? new Videos(this) : null; Object.defineProperty(this, 'videos', { value }); return value; } addFuncs() { RefMap.updateRefMap(this, true); embedAudioLinks(this); } handleEvent(e) { let temp, el = fixEventEl(e.target); const { type } = e; const isOutEvent = type === 'mouseout'; const isPview = this instanceof Pview; if(type === 'click') { switch(e.button) { case 0: break; case 1: e.stopPropagation(); // Skip the click on wheel button /* falls through */ default: return; } if(this._menu) { // Hide the dropdown menu after the click on its option this._menu.removeMenu(); this._menu = null; } switch(el.tagName) { case 'A': // Click on YouTube link - show/hide player or thumbnail if(el.classList.contains('de-video-link')) { this.videos.clickLink(el, Cfg.embedYTube); $pd(e); return; } // Check if the link is not an image container if(!(temp = el.firstElementChild) || temp.tagName !== 'IMG') { temp = el.parentNode; if(temp === this.trunc) { // Click on "truncated message" link this._getFullMsg(temp, false); $pd(e); e.stopPropagation(); } else if(Cfg.insertNum && pr.form && (this._pref === temp || this._pref === el) && !/Reply|Ответ/.test(el.textContent) ) { // Click on post number link - show quick reply or redirect with an #anchor $pd(e); e.stopPropagation(); if(!Cfg.showRepBtn) { quotetxt = deWindow.getSelection().toString(); pr.showQuickReply(isPview ? Pview.topParent : this, this.num, !isPview, false); quotetxt = ''; } else if(pr.isQuick || (aib.t && pr.isHidden)) { pr.showQuickReply(isPview ? Pview.topParent : this, this.num, false, true); } else if(aib.t) { const formText = pr.txta.value; const isOnNewLine = formText === '' || formText.slice(-1) === '\n'; insertText(pr.txta, `>>${ this.num }${ isOnNewLine ? '\n' : '' }`); } else { deWindow.location.assign(el.href.replace(/#i/, '#')); } } else if((temp = el.textContent)[0] === '>' && temp[1] === '>' && !temp[2].includes('/') ) { // Click on >>link - scroll to the referenced post const post = pByNum.get(+temp.match(/\d+/)); if(post) { post.selectAndScrollTo(); } } return; } el = temp; // The link is an image container /* falls through */ case 'IMG': // Click on attached image - expand/collapse if(el.classList.contains('de-video-thumb')) { if(Cfg.embedYTube === 1) { const { videos } = this; videos.currentLink.classList.add('de-current'); videos.setPlayer(videos.playerInfo, el.classList.contains('de-ytube')); $pd(e); } } else if(Cfg.expandImgs !== 0) { this._clickImage(el, e); } return; case 'OBJECT': case 'VIDEO': // Click on attached video - expand/collapse if(Cfg.expandImgs !== 0 && !ExpandableImage.isControlClick(e)) { this._clickImage(el, e); } return; } if(aib.makaba) { // Makaba: Click on like/dislike elements let c = el.classList; if(c.contains('post__rate') || c[0] === 'like-div' || c[0] === 'dislike-div' || (temp = el.parentNode) && ( (c = temp.classList).contains('post__rate') || c[0] === 'like-div' || c[0] === 'dislike-div') || (temp = temp.parentNode) && ( (c = temp.className) === 'like-div' || c === 'dislike-div') ) { const task = temp.id.split('-')[0]; const num = +temp.id.match(/\d+/); $ajax(`/api/${ task }?board=${ aib.b }&num=${ num }`).then(xhr => { const data = JSON.parse(xhr.responseText); if(data.Status !== 'OK') { $popup('err-2chlike', data.Reason); return; } temp.classList.add(`${ task }-div-checked`, `post__rate_${ task }d`); const countEl = $q(`.${ task }-count, #${ task }-count${ num }`, temp); countEl.textContent = +countEl.textContent + 1; }, () => $popup('err-2chlike', Lng.noConnect[lang])); } // Makaba: Click on "truncated message" link if(el.classList.contains('expand-large-comment')) { this._getFullMsg(el, false); $pd(e); e.stopPropagation(); } } // Click on post buttons switch(el.classList[0]) { case 'de-btn-expthr': this.thr.loadPosts('all'); return; case 'de-btn-fav': this.thr.toggleFavState(true, isPview ? this : null); return; case 'de-btn-fav-sel': this.thr.toggleFavState(false, isPview ? this : null); return; case 'de-btn-hide': case 'de-btn-hide-user': case 'de-btn-unhide': case 'de-btn-unhide-user': this.setUserVisib(!this.isHidden); return; case 'de-btn-reply': pr.showQuickReply(isPview ? Pview.topParent : this, this.num, !isPview, false); quotetxt = ''; return; case 'de-btn-sage': Spells.addSpell(9, '', false); return; case 'de-btn-stick': this.toggleSticky(true); return; case 'de-btn-stick-on': this.toggleSticky(false); return; } return; } if(!this._hasEvents) { this._hasEvents = true; this.el.addEventListener('click', this, true); this.el.addEventListener('mouseout', this, true); } // Mouseover/mouseout on YouTube links if(el.classList.contains('de-video-link')) { if(aib.makaba && !el.videoInfo) { const origMsg = this.msg.firstChild; this.videos.updatePost($Q('.de-video-link', origMsg), $Q('.de-video-link', origMsg.nextSibling), true); } if(Cfg.embedYTube === 2) { this.videos.toggleFloatedThumb(el, isOutEvent); } } // Mouseover/mouseout on attached images/videos - update title if(!isOutEvent && Cfg.expandImgs && el.tagName === 'IMG' && !el.classList.contains('de-fullimg') && (temp = this.images.getImageByEl(el)) && (temp.isImage || temp.isVideo) ) { el.title = Cfg.expandImgs === 1 ? Lng.expImgInline[lang] : Lng.expImgFull[lang]; } // Mouseover/mouseout on post buttons - update title, add/delete dropdown menu switch(el.classList[0]) { case 'de-post-btns': el.removeAttribute('title'); return; case 'de-btn-reply': { const title = this.btns.title = this.isOp ? Lng.replyToThr[lang] : Lng.replyToPost[lang]; if(Cfg.showRepBtn === 1) { if(!isOutEvent) { quotetxt = deWindow.getSelection().toString(); } this._addMenu(el, isOutEvent, `${ title }` + (aib.reportForm ? `${ this.num === this.thr.num ? Lng.reportThr[lang] : Lng.reportPost[lang] }` : '' ) + (Cfg.markMyPosts || Cfg.markMyLinks ? `${ MyPosts.has(this.num) ? Lng.deleteMyPost[lang] : Lng.markMyPost[lang] }` : '' )); } return; } case 'de-btn-hide': case 'de-btn-hide-user': case 'de-btn-unhide': case 'de-btn-unhide-user': this.btns.title = this.isOp ? Lng.toggleThr[lang] : Lng.togglePost[lang]; if(Cfg.showHideBtn === 1) { this._addMenu(el, isOutEvent, (this instanceof Pview ? pByNum.get(this.num) : this)._getMenuHide()); } return; case 'de-btn-expthr': this.btns.title = Lng.expandThr[lang]; this._addMenu(el, isOutEvent, arrTags(Lng.selExpandThr[lang], '', '')); return; case 'de-btn-fav': this.btns.title = Lng.addFav[lang]; return; case 'de-btn-fav-sel': this.btns.title = Lng.delFav[lang]; return; case 'de-btn-sage': this.btns.title = 'SAGE'; return; case 'de-btn-stick': this.btns.title = Lng.attachPview[lang]; return; case 'de-btn-src': if(el.parentNode.className !== 'de-fullimg-info') { this._addMenu(el, isOutEvent, Menu.getMenuImgSrc(el)); } return; // Mouseover/mouseout on >>links - show/delete post previews default: if(!Cfg.linksNavig || el.tagName !== 'A' || el.isNotRefLink) { return; } if(!el.textContent.startsWith('>>')) { el.isNotRefLink = true; return; } // Don't use classList here, 'de-link-postref ' should be first el.className = 'de-link-postref ' + el.className; /* falls through */ case 'de-link-backref': case 'de-link-postref': if(!Cfg.linksNavig) { return; } if(isOutEvent) { // Mouseout - We need to delete previews clearTimeout(this._linkDelay); if(!(aib.getPostOfEl(fixEventEl(e.relatedTarget)) instanceof Pview) && Pview.top) { Pview.top.markToDel(); // If cursor is not over one of previews - delete all previews } else if(this.kid) { this.kid.markToDel(); // If cursor is over any preview - delete its kids } } else { // Mouseover - we need to show a preview for this link this._linkDelay = setTimeout(() => (this.kid = Pview.showPview(this, el)), Cfg.linksOver); } $pd(e); e.stopPropagation(); } } toggleFavBtn(isEnable) { const elClass = isEnable ? 'de-btn-fav-sel' : 'de-btn-fav'; if(this.btnFav) { this.btnFav.setAttribute('class', elClass); } if(this.thr.btnFav) { this.thr.btnFav.setAttribute('class', elClass); } } updateMsg(newMsg, sRunner) { let videoExt, videoLinks; const origMsg = aib.dobrochan ? this.msg.firstElementChild : this.msg; if(Cfg.embedYTube) { videoExt = $q('.de-video-ext', origMsg); videoLinks = $Q(':not(.de-video-ext) > .de-video-link', origMsg); } $replace(origMsg, newMsg); Object.defineProperties(this, { msg : { configurable: true, value: newMsg }, trunc : { configurable: true, value: null } }); Post.Сontent.removeTempData(this); if(Cfg.embedYTube) { this.videos.updatePost(videoLinks, $Q('a[href*="youtu"], a[href*="vimeo.com"]', newMsg), false); if(videoExt) { newMsg.appendChild(videoExt); } } this.addFuncs(); sRunner.runSpells(this); embedPostMsgImages(this.el); if(this.isHidden) { this.hideContent(this.isHidden); } closePopup('load-fullmsg'); } _addMenu(el, isOutEvent, html) { if(!this.menu || this.menu.parentEl !== el) { if(isOutEvent) { clearTimeout(this._menuDelay); } else { this._menuDelay = setTimeout(() => this._showMenu(el, html), Cfg.linksOver); } } } _clickImage(el, e) { const image = this.images.getImageByEl(el); if(!image || (!image.isImage && !image.isVideo)) { return; } image.expandImg((Cfg.expandImgs === 1) ^ e.ctrlKey, e); $pd(e); e.stopPropagation(); } _getFullMsg(truncEl, isInit) { if(aib.deleteTruncMsg) { aib.deleteTruncMsg(this, truncEl, isInit); return; } if(!isInit) { $popup('load-fullmsg', Lng.loading[lang], true); } ajaxLoad(aib.getThrUrl(aib.b, this.tNum)).then(form => { let sourceEl; const maybeSpells = new Maybe(SpellsRunner); if(this.isOp) { sourceEl = form; } else { const posts = $Q(aib.qRPost, form); for(let i = 0, len = posts.length; i < len; ++i) { const post = posts[i]; if(this.num === aib.getPNum(post)) { sourceEl = post; break; } } } if(sourceEl) { this.updateMsg(aib.fixHTML(doc.adoptNode($q(aib.qPostMsg, sourceEl))), maybeSpells.value); truncEl.remove(); } if(maybeSpells.hasValue) { maybeSpells.value.endSpells(); } }, emptyFn); } _showMenu(el, html) { if(this._menu) { this._menu.removeMenu(); } this._menu = new Menu(el, html, el => (this instanceof Pview ? pByNum.get(this.num) : this)._clickMenu(el), false); this._menu.onremove = () => (this._menu = null); } } class Post extends AbstractPost { constructor(el, thr, num, count, isOp, prev) { super(thr, num, isOp); this.count = count; this.el = el; this.isDeleted = false; this.isHidden = false; this.isOmitted = false; this.isViewed = false; this.next = null; this.prev = prev; this.spellHidden = false; this.userToggled = false; this._selRange = null; this._selText = ''; if(prev) { prev.next = this; } pByEl.set(el, this); pByNum.set(num, this); let isMyPost = MyPosts.has(num); if(isMyPost) { this.el.classList.add('de-mypost'); } else if(localData && this.el.classList.contains('de-mypost')) { MyPosts.set(num, thr.num); isMyPost = true; } el.classList.add(isOp ? 'de-oppost' : 'de-reply'); this.sage = aib.getSage(el); this.btns = $aEnd(this._pref = $q(aib.qPostRef, el), '' + Post.getPostBtns(isOp, aib.t) + (this.sage ? '' : '') + (isOp ? '' : `${ count + 1 }`) + (isMyPost ? '(You)' : '') + ''); this.counterEl = isOp ? null : $q('.de-post-counter', this.btns); if(Cfg.expandTrunc && this.trunc) { this._getFullMsg(this.trunc, true); } el.addEventListener('mouseover', this, true); } static addMark(postEl, forced) { if(!doc.hidden && !forced) { Post.clearMarks(); } else { if(!Post.hasNew) { Post.hasNew = true; doc.addEventListener('click', Post.clearMarks, true); } postEl.classList.add('de-new-post'); } } static clearMarks() { if(Post.hasNew) { Post.hasNew = false; $each($Q('.de-new-post'), el => el.classList.remove('de-new-post')); doc.removeEventListener('click', Post.clearMarks, true); } } static getPostBtns(isOp, noExpThr) { return '' + '' + '' + (isOp ? (noExpThr ? '' : '') + '' : ''); } static findSameText(pNum, isHidden, words, curPost) { const curWords = Post.getWrds(curPost.text); const len = curWords.length; let i = words.length; const olen = i; let _olen = i; let n = 0; if(len < olen * 0.4 || len > olen * 3) { return; } while(i--) { if(olen > 6 && words[i].length < 3) { _olen--; continue; } let j = len; while(j--) { if(curWords[j] === words[i] || words[i].match(/>>\d+/) && curWords[j].match(/>>\d+/)) { n++; } } } if(n < _olen * 0.4 || len > _olen * 3) { return; } if(isHidden) { if(curPost.spellHidden) { Post.Note.reset(); } else { curPost.setVisib(false); } if(curPost.userToggled) { HiddenPosts.removeStorage(curPost.num); curPost.userToggled = false; } } else { curPost.setUserVisib(true, true, 'similar to >>' + pNum); } return false; } static getWrds(text) { return text.replace(/\s+/g, ' ').replace(/[^a-zа-яё ]/ig, '').trim().substring(0, 800).split(' '); } static hideContent(headerEl, btnHide, isUser, isHide) { if(!isHide) { btnHide.setAttribute('class', isUser ? 'de-btn-hide-user' : 'de-btn-hide'); $each($Q('.de-post-hiddencontent', headerEl.parentNode), el => el.classList.remove('de-post-hiddencontent')); return; } if(aib.t) { Thread.first.hidCounter++; } btnHide.setAttribute('class', isUser ? 'de-btn-unhide-user' : 'de-btn-unhide'); if(headerEl) { for(let el = headerEl.nextElementSibling; el; el = el.nextElementSibling) { el.classList.add('de-post-hiddencontent'); } } } get banned() { const value = aib.getBanId(this.el); Object.defineProperty(this, 'banned', { value, writable: true }); return value; } get bottom() { return (this.isOp && this.isHidden ? this.thr.el.previousElementSibling : this.el) .getBoundingClientRect().bottom; } get headerEl() { return new Post.Сontent(this).headerEl; } get html() { return new Post.Сontent(this).html; } get nextInThread() { const post = this.next; return !post || post.count === 0 ? null : post; } get nextNotDeleted() { let post = this.nextInThread; while(post && post.isDeleted) { post = post.nextInThread; } return post; } get note() { const value = new Post.Note(this); Object.defineProperty(this, 'note', { value }); return value; } get posterName() { return new Post.Сontent(this).posterName; } get posterTrip() { return new Post.Сontent(this).posterTrip; } get subj() { return new Post.Сontent(this).subj; } get text() { return new Post.Сontent(this).text; } get title() { return new Post.Сontent(this).title; } get tNum() { return this.thr.num; } get top() { return (this.isOp && this.isHidden ? this.thr.el.previousElementSibling : this.el) .getBoundingClientRect().top; } get wrap() { return new Post.Сontent(this).wrap; } addFuncs() { super.addFuncs(); if(isExpImg) { this.toggleImages(true, false); } } deleteCounter() { this.isDeleted = true; this.counterEl.textContent = Lng.deleted[lang]; this.counterEl.classList.add('de-post-counter-deleted'); this.el.classList.add('de-post-removed'); this.wrap.classList.add('de-wrap-removed'); } deletePost(isRemovePost) { if(isRemovePost) { this.wrap.remove(); pByEl.delete(this.el); pByNum.delete(this.num); if(this.isHidden) { this.ref.unhideRef(); } RefMap.updateRefMap(this, false); if((this.prev.next = this.next)) { this.next.prev = this.prev; } return; } this.deleteCounter(); ($q('input[type="checkbox"]', this.el) || {}).disabled = true; } getAdjacentVisPost(toUp) { let post = toUp ? this.prev : this.next; while(post) { if(post.thr.isHidden) { post = toUp ? post.thr.op.prev : post.thr.last.next; } else if(post.isHidden || post.isOmitted) { post = toUp ? post.prev : post.next; } else { return post; } } return null; } hideContent(needToHide) { if(this.isOp) { if(!aib.t) { $toggle(this.thr.el, !needToHide); $toggle(this.thr.btns, !needToHide); } } else { Post.hideContent(this.headerEl, this.btnHide, this.userToggled, needToHide); } } select() { if(this.isOp) { if(this.isHidden) { this.thr.el.previousElementSibling.classList.add('de-selected'); } this.thr.el.classList.add('de-selected'); } else { this.el.classList.add('de-selected'); } } selectAndScrollTo(scrollNode = this.el) { scrollTo(0, deWindow.pageYOffset + scrollNode.getBoundingClientRect().top - Post.sizing.wHeight / 2 + scrollNode.clientHeight / 2); if(HotKeys.enabled) { if(HotKeys.cPost) { HotKeys.cPost.unselect(); } HotKeys.cPost = this; HotKeys.lastPageOffset = deWindow.pageYOffset; } else { const el = $q('.de-selected'); if(el) { el.unselect(); } } this.select(); } setUserVisib(isHide, isSave = true, note = null) { this.userToggled = true; this.setVisib(isHide, note); if(this.isOp || this.isHidden === isHide) { const hideClass = isHide ? 'de-btn-unhide-user' : 'de-btn-hide-user'; this.btnHide.setAttribute('class', hideClass); if(this.isOp) { this.thr.btnHide.setAttribute('class', hideClass); } } if(isSave) { const { num } = this; HiddenPosts.set(num, this.thr.num, isHide); if(this.isOp) { if(isHide) { HiddenThreads.set(num, num, this.title); } else { HiddenThreads.removeStorage(num); } } sendStorageEvent('__de-post', { hide : isHide, brd : aib.b, num, thrNum : this.thr.num, title : this.isOp ? this.title : '' }); } this.ref.toggleRef(isHide, false); } setVisib(isHide, note = null) { if(this.isHidden === isHide) { if(isHide && note) { this.note.set(note); } return; } if(this.isOp) { this.thr.isHidden = isHide; } else { if(Cfg.delHiddPost === 1 || Cfg.delHiddPost === 2) { this.wrap.classList.toggle('de-hidden', isHide); } else { this._pref.onmouseover = this._pref.onmouseout = !isHide ? null : e => { const yOffset = deWindow.pageYOffset; this.hideContent(e.type === 'mouseout'); scrollTo(deWindow.pageXOffset, yOffset); }; } } if(Cfg.strikeHidd) { setTimeout(() => this._strikePostNum(isHide), 50); } if(isHide) { this.note.set(note); } else { this.note.hideNote(); } this.hideContent(this.isHidden = isHide); } spellHide(note) { this.spellHidden = true; if(!this.userToggled) { this.setVisib(true, note); this.ref.hideRef(); } } spellUnhide() { this.spellHidden = false; if(!this.userToggled) { this.setVisib(false); this.ref.unhideRef(); } } toggleImages(isExpand = !this.images.expanded, isExpandVideos = true) { for(const image of this.images) { if((image.isImage || isExpandVideos && image.isVideo) && (image.expanded ^ isExpand)) { if(isExpand) { image.expandImg(true, null); } else { image.collapseImg(null); } } } } unselect() { if(this.isOp) { const el = $id('de-thr-hid-' + this.num); if(el) { el.classList.remove('de-selected'); } this.thr.el.classList.remove('de-selected'); } else { this.el.classList.remove('de-selected'); } } _clickMenu(el) { const isHide = !this.isHidden; const isPview = this instanceof Pview; const { num } = this; switch(el.getAttribute('info')) { case 'hide-sel': { let { startContainer: start, endContainer: end } = this._selRange; if(start.nodeType === 3) { start = start.parentNode; } if(end.nodeType === 3) { end = end.parentNode; } const inMsgSel = `${ aib.qPostMsg }, ${ aib.qPostMsg } *`; if((nav.matchesSelector(start, inMsgSel) && nav.matchesSelector(end, inMsgSel)) || ( nav.matchesSelector(start, aib.qPostSubj) && nav.matchesSelector(end, aib.qPostSubj) )) { if(this._selText.includes('\n')) { Spells.addSpell(1 /* #exp */, `/${ quoteReg(this._selText).replace(/\r?\n/g, '\\n') }/`, false); } else { Spells.addSpell(0 /* #words */, this._selText.toLowerCase(), false); } } else { dummy.innerHTML = ''; dummy.appendChild(this._selRange.cloneContents()); Spells.addSpell(2 /* #exph */, `/${ quoteReg(dummy.innerHTML.replace(/^<[^>]+>|<[^>]+>$/g, '')) }/`, false); } return; } case 'hide-name': Spells.addSpell(6 /* #name */, this.posterName, false); return; case 'hide-trip': Spells.addSpell(7 /* #trip */, this.posterTrip, false); return; case 'hide-img': { const { weight: w, width: wi, height: h } = this.images.firstAttach; Spells.addSpell(8 /* #img */, [0, [w, w], [wi, wi, h, h]], false); return; } case 'hide-imgn': Spells.addSpell(3 /* #imgn */, `/${ quoteReg(this.images.firstAttach.name) }/`, false); return; case 'hide-ihash': ImagesHashStorage.getHash(this.images.firstAttach).then(hash => { if(hash !== -1) { Spells.addSpell(4 /* #ihash */, hash, false); } }); return; case 'hide-noimg': Spells.addSpell(0x108 /* (#all & !#img) */, '', true); return; case 'hide-text': { const words = Post.getWrds(this.text); for(let post = Thread.first.op; post; post = post.next) { Post.findSameText(num, !isHide, words, post); } return; } case 'hide-notext': Spells.addSpell(0x10B /* (#all & !#tlen) */, '', true); return; case 'hide-refs': this.ref.toggleRef(isHide, true); this.setUserVisib(isHide); return; case 'hide-refsonly': Spells.addSpell(0 /* #words */, '>>' + num, false); return; case 'post-markmy': { const isAdd = !MyPosts.has(num); if(isAdd) { MyPosts.set(num, this.thr.num); } else { MyPosts.removeStorage(num); } this.el.classList.toggle('de-mypost', isAdd); $each($Q(`[de-form] ${ aib.qPostMsg } a[href$="${ aib.anchor + num }"]`), el => { const post = aib.getPostOfEl(el); if(post.el !== this.el) { el.classList.toggle('de-ref-you', isAdd); post.el.classList.toggle('de-mypost-reply', isAdd); } }); return; } case 'post-reply': pr.showQuickReply(isPview ? Pview.topParent : this, num, !isPview, false); quotetxt = ''; return; case 'post-report': aib.reportForm(num, this.thr.num); return; case 'thr-exp': { const task = +el.textContent.match(/\d+/); this.thr.loadPosts(!task ? 'all' : task === 10 ? 'more' : task); } } } _getMenuHide() { const item = name => `${ Lng.selHiderMenu[name][lang] }`; const sel = deWindow.getSelection(); const ssel = sel.toString().trim(); if(ssel) { this._selText = ssel; this._selRange = sel.getRangeAt(0); } return `${ ssel ? item('sel') : '' }${ this.posterName ? item('name') : '' }${ this.posterTrip ? item('trip') : '' }${ this.images.hasAttachments ? item('img') + item('imgn') + item('ihash') : item('noimg') }${ this.text ? item('text') : item('notext') }${ !Cfg.hideRefPsts && this.ref.hasMap ? item('refs') : '' }${ item('refsonly') }`; } _strikePostNum(isHide) { const { num } = this; if(isHide) { Post.hiddenNums.add(+num); } else { Post.hiddenNums.delete(+num); } $each($Q(`[de-form] a[href$="${ aib.anchor + num }"]`), el => { el.classList.toggle('de-link-hid', isHide); if(Cfg.removeHidd && el.classList.contains('de-link-backref')) { const refMapEl = el.parentNode; if(isHide === !$q('.de-link-backref:not(.de-link-hid)', refMapEl)) { $toggle(refMapEl, !isHide); } } }); } } Post.hasNew = false; Post.hiddenNums = new Set(); Post.Сontent = class PostContent extends TemporaryContent { constructor(post) { super(post); if(this._isInited) { return; } this._isInited = true; this.el = post.el; this.post = post; } get headerEl() { const value = $q(aib.qPostHeader, this.el); Object.defineProperty(this, 'headerEl', { value }); return value; } get html() { const value = this.el.outerHTML; Object.defineProperty(this, 'html', { value }); return value; } get posterName() { const pName = $q(aib.qPostName, this.el); const value = pName ? pName.textContent.trim().replace(/\s/g, ' ') : ''; Object.defineProperty(this, 'posterName', { value }); return value; } get posterTrip() { const pTrip = $q(aib.qPostTrip, this.el); const value = pTrip ? pTrip.textContent : ''; Object.defineProperty(this, 'posterTrip', { value }); return value; } get subj() { const subj = $q(aib.qPostSubj, this.el); const value = subj ? subj.textContent : ''; Object.defineProperty(this, 'subj', { value }); return value; } get text() { const value = this.post.msg.innerHTML .replace(/<\/?(?:br|p|li)[^>]*?>/gi, '\n') .replace(/<[^>]+?>/g, '') .replace(/>/g, '>') .replace(/</g, '<') .replace(/ /g, '\u00A0').trim(); Object.defineProperty(this, 'text', { value }); return value; } get title() { const value = this.subj || this.text.substring(0, 70).replace(/\s+/g, ' '); Object.defineProperty(this, 'title', { value }); return value; } get wrap() { const value = aib.getPostWrap(this.el, this.post.isOp); Object.defineProperty(this, 'wrap', { value }); return value; } }; Post.Note = class PostNote { constructor(post) { this.text = null; this._post = post; this.isHideThr = this._post.isOp && !aib.t; // Hide threads only on board if(!this.isHideThr) { // Create usual post note this._noteEl = this.textEl = $bEnd(post.btns, ''); return; } // Create a stub before the thread, that also hides thread by CSS this._noteEl = $bBegin(post.thr.el, `
`); this._aEl = $q('a', this._noteEl); this.textEl = this._aEl.nextElementSibling; } hideNote() { if(this.isHideThr) { this._aEl.onmouseover = this._aEl.onmouseout = this._aEl.onclick = null; } $hide(this._noteEl); } reset() { this.text = null; if(this.isHideThr) { this.set(null); } else { this.hideNote(); } } set(note) { this.text = note; let text; if(this.isHideThr) { this._aEl.onmouseover = this._aEl.onmouseout = e => this._post.hideContent(e.type === 'mouseout'); this._aEl.onclick = e => { $pd(e); this._post.setUserVisib(!this._post.isHidden); }; text = (this._post.title ? `(${ this._post.title }) ` : '') + (note ? `[autohide: ${ note }]` : ''); } else { text = note ? `autohide: ${ note }` : ''; } this.textEl.textContent = text; $show(this._noteEl); } }; Post.sizing = { get dPxRatio() { const value = deWindow.devicePixelRatio || 1; Object.defineProperty(this, 'dPxRatio', { value }); return value; }, get wHeight() { const value = nav.viewportHeight(); if(!this._enabled) { doc.defaultView.addEventListener('resize', this); this._enabled = true; } Object.defineProperties(this, { wHeight : { writable: true, configurable: true, value }, wWidth : { writable: true, configurable: true, value: nav.viewportWidth() } }); return value; }, get wWidth() { const value = nav.viewportWidth(); if(!this._enabled) { doc.defaultView.addEventListener('resize', this); this._enabled = true; } Object.defineProperties(this, { wHeight : { writable: true, configurable: true, value: nav.viewportHeight() }, wWidth : { writable: true, configurable: true, value } }); return value; }, handleEvent() { this.wHeight = nav.viewportHeight(); this.wWidth = nav.viewportWidth(); }, _enabled: false }; /* ==[ PostPreviews.js ]====================================================================================== POST PREVIEWS =========================================================================================================== */ class Pview extends AbstractPost { constructor(parent, link, pNum, tNum) { super(parent.thr, pNum, pNum === tNum); this.isSticky = false; this.parent = parent; this.remoteThr = null; this.tNum = tNum; this._isCached = false; this._isLeft = false; this._isTop = false; this._link = link; this._newPos = null; this._offsetTop = 0; this._readDelay = 0; let post = pByNum.get(pNum); if(post && (!post.isOp || !(parent instanceof Pview) || !parent._isCached)) { this._buildPview(post); return; } this._isCached = true; this.brd = link.pathname.match(/^\/?(.+\/)/)[1].replace(aib.res, '').replace(/\/$/, ''); if(PviewsCache.has(this.brd + tNum)) { post = PviewsCache.get(this.brd + tNum).getPost(pNum); if(post) { this._buildPview(post); } else { this._showPview(this.el = $add(`
${ Lng.postNotFound[lang] }
`)); } return; } this._showPview(this.el = $add(`
${ Lng.loading[lang] }
`)); // Get post preview via ajax. Always use DOM parsing. this._loadPromise = ajaxPostsLoad(this.brd, tNum, false, false) .then(pBuilder => this._onload(pBuilder), err => this._onerror(err)); } static get topParent() { return Pview.top ? Pview.top.parent : null; } static showPview(parent, link) { const tNum = +(link.pathname.match(/.+?\/[^\d]*(\d+)/) || [0, aib.getPostOfEl(link).tNum])[1]; let pNum = link.textContent.match(/\d+/g); pNum = pNum ? +pNum.pop() : tNum; const isTop = !(parent instanceof Pview); let pv = isTop ? Pview.top : parent.kid; clearTimeout(Pview._delTO); if(pv && pv.num === pNum) { if(pv.kid) { pv.kid.deletePview(); } if(pv._link !== link) { // If cursor hovers new link with the same number - move old preview here pv._setPosition(link, Cfg.animation); pv._link.classList.remove('de-link-parent'); link.classList.add('de-link-parent'); pv._link = link; if(pv.parent.num !== parent.num) { $each($Q('.de-link-pview', pv.el), el => el.classList.remove('de-link-pview')); Pview._markLink(pv.el, parent.num); } } pv.parent = parent; } else if(!Cfg.noNavigHidd || !pByNum.has(pNum) || !pByNum.get(pNum).hidden) { // Show new preview under new link if(pv) { pv.deletePview(); } pv = new Pview(parent, link, pNum, tNum); if(isTop) { Pview.top = pv; } } else { return null; } return pv; } static updatePosition(scroll) { let pv = Pview.top; if(!pv) { return; } const { parent } = pv; if(parent.isOmitted) { pv.deletePview(); return; } if(parent.thr.loadCount === 1 && !parent.el.contains(pv._link)) { const el = parent.ref.getElByNum(pv.num); if(!el) { pv.deletePview(); return; } pv._link = el; } const cr = parent.isHidden ? parent : pv._link.getBoundingClientRect(); const diff = pv._isTop ? pv._offsetTop - deWindow.pageYOffset - cr.bottom : pv._offsetTop + pv.el.offsetHeight - deWindow.pageYOffset - cr.top; if(Math.abs(diff) > 1) { if(scroll) { scrollTo(deWindow.pageXOffset, deWindow.pageYOffset - diff); } do { pv._offsetTop -= diff; pv.el.style.top = Math.max(pv._offsetTop, 0) + 'px'; } while((pv = pv.kid)); } } get stickBtn() { const value = $q('.de-btn-stick', this.el); Object.defineProperty(this, 'stickBtn', { value }); return value; } deletePview() { this.parent.kid = null; this._link.classList.remove('de-link-parent'); if(Pview.top === this) { Pview.top = null; } if(this._loadPromise) { this._loadPromise.cancelPromise(); this._loadPromise = null; } let vPost = AttachedImage.viewer && AttachedImage.viewer.data.post; let pv = this; do { clearTimeout(pv._readDelay); if(vPost === pv) { AttachedImage.closeImg(); vPost = null; } const { el } = pv; pByEl.delete(el); if(Cfg.animation) { $animate(el, 'de-pview-anim', true); el.style.animationName = `de-post-close-${ this._isTop ? 't' : 'b' }${ this._isLeft ? 'l' : 'r' }`; } else { el.remove(); } } while((pv = pv.kid)); } deleteNonSticky() { let lastSticky = null, pv = this; do { if(pv.isSticky) { lastSticky = pv; } } while((pv = pv.kid)); if(!lastSticky) { this.deletePview(); } else if(lastSticky.kid) { lastSticky.kid.deletePview(); } } handleEvent(e) { const pv = e.target; if(e.type === 'animationend' && pv.style.animationName) { pv.classList.remove('de-pview-anim'); pv.style.cssText = this._newPos; this._newPos = null; $delAll('.de-css-move', doc.head); pv.removeEventListener('animationend', this); return; } let isOverEvent = false; checkMouse: do { switch(e.type) { case 'mouseover': isOverEvent = true; break; case 'mouseout': break; default: break checkMouse; } const el = fixEventEl(e.relatedTarget); if(!el || isOverEvent && (el.tagName !== 'A' || el.isNotRefLink) || el !== this.el && !this.el.contains(el) ) { if(isOverEvent) { this.mouseEnter(); } else if(Pview.top) { Pview.top.markToDel(); } } } while(false); if(!this.loading) { super.handleEvent(e); } } markToDel() { clearTimeout(Pview._delTO); Pview._delTO = setTimeout(() => this.deleteNonSticky(), Cfg.linksOut); } mouseEnter() { if(this.kid) { this.kid.markToDel(); } else { clearTimeout(Pview._delTO); } } setUserVisib() { const post = pByNum.get(this.num); const isHide = post.isHidden; post.setUserVisib(!isHide); Pview.updatePosition(true); $each($Q(`.de-btn-pview-hide[de-num="${ this.num }"]`), el => { el.setAttribute('class', `${ isHide ? 'de-btn-hide-user' : 'de-btn-unhide-user' } de-btn-pview-hide`); el.parentNode.classList.toggle('de-post-hide', !isHide); }); } toggleSticky(isEnabled) { this.stickBtn.setAttribute('class', isEnabled ? 'de-btn-stick-on' : 'de-btn-stick'); this.isSticky = isEnabled; } static _markLink(el, num) { $each($Q(`a[href*="${ num }"]`, el), el => el.textContent.startsWith('>>' + num) && el.classList.add('de-link-pview')); } async _buildPview(post) { $del(this.el); const { num } = this; const pv = this.el = post.el.cloneNode(true); pByEl.set(pv, this); const isMyPost = MyPosts.has(num); pv.className = `${ aib.cReply } de-pview${ post.isViewed ? ' de-viewed' : '' }${ isMyPost ? ' de-mypost' : '' }` + `${ post.el.classList.contains('de-mypost-reply') ? ' de-mypost-reply' : '' }`; $show(pv); $each($Q('.de-post-hiddencontent', pv), el => el.classList.remove('de-post-hiddencontent')); if(Cfg.linksNavig) { Pview._markLink(pv, this.parent.num); } this._pref = $q(aib.qPostRef, pv); this._link.classList.add('de-link-parent'); const { isOp } = this; let f; const isFav = isOp && (post.thr.isFav || ((f = (await readFavorites())[aib.host]) && (f = f[this.brd]) && (num in f))); const isCached = post instanceof CacheItem; const pCountHtml = (post.isDeleted ? ` de-post-counter-deleted">${ Lng.deleted[lang] }` : `">${ isOp ? '(OP)' : post.count + +!(aib.JsonBuilder && isCached) }`) + (isMyPost ? '(You)' : ''); const pText = '' + (isOp ? `` + '' : '') + (post.sage ? '' : '') + '' + '${ pText }`); embedAudioLinks(this); if(Cfg.embedYTube) { new VideosParser().parse(this).endParser(); } embedPostMsgImages(pv); processImgInfoLinks(this); } else { const btnsEl = this.btns = $q('.de-post-btns', pv); $del($q('.de-post-counter', btnsEl)); if(post.isHidden) { btnsEl.classList.add('de-post-hide'); } btnsEl.innerHTML = `${ pText }`; $delAll(`${ !aib.t && isOp ? aib.qOmitted + ', ' : '' }.de-fullimg-wrap, .de-fullimg-after`, pv); $each($Q(aib.qPostImg, pv), el => $show(el.parentNode)); const link = $q('.de-link-parent', pv); if(link) { link.classList.remove('de-link-parent'); } if(Cfg.embedYTube && post.videos.hasLinks) { if(post.videos.playerInfo !== null) { Object.defineProperty(this, 'videos', { value: new Videos(this, $q('.de-video-obj', pv), post.videos.playerInfo) }); } this.videos.updatePost($Q('.de-video-link', post.el), $Q('.de-video-link', pv), true); } if(Cfg.addImgs) { $each($Q('.de-img-embed', pv), $show); } if(Cfg.markViewed) { this._readDelay = setTimeout(post => { if(!post.isViewed) { post.el.classList.add('de-viewed'); post.isViewed = true; } const arr = (sesStorage['de-viewed'] || '').split(','); arr.push(post.num); sesStorage['de-viewed'] = arr; }, post.text.length > 100 ? 2e3 : 500, post); } } pv.addEventListener('click', this, true); this._showPview(pv); } _onerror(err) { if(!(err instanceof CancelError)) { this.el.innerHTML = (err instanceof AjaxError) && err.code === 404 ? Lng.postNotFound[lang] : getErrorMessage(err); } } _onload(pBuilder) { const b = this.brd; const { num } = this.parent; const post = new PviewsCache(pBuilder, b, this.tNum).getPost(this.num); if(post && (aib.b !== b || !post.ref.hasMap || !post.ref.has(num))) { (post.ref.hasMap ? $q('.de-refmap', post.el) : $aEnd(post.msg, '
')) .insertAdjacentHTML('afterbegin', `>>${ aib.b === b ? '' : `/${ aib.b }/` }${ num }, `); } if(post) { this._buildPview(post); } else { this.el.innerHTML = Lng.postNotFound[lang]; } } _setPosition(link, isAnim) { let oldCSS; const cr = link.getBoundingClientRect(); const offX = cr.left + deWindow.pageXOffset + cr.width / 2; const offY = cr.top; const bWidth = nav.viewportWidth(); const isLeft = offX < bWidth / 2; const pv = this.el; const temp = isLeft ? offX : offX - Math.min(parseInt(pv.offsetWidth, 10), offX - 10); const lmw = `max-width:${ bWidth - temp - 10 }px; left:${ temp }px;`; const { style } = pv; if(isAnim) { oldCSS = style.cssText; } style.cssText = (isAnim ? 'opacity: 0; ' : '') + lmw; let top = pv.offsetHeight; const isTop = offY + top + cr.height < nav.viewportHeight() || offY - top < 5; top = deWindow.pageYOffset + (isTop ? offY + cr.height : offY - top); this._offsetTop = top; this._isLeft = isLeft; this._isTop = isTop; if(!isAnim) { style.top = top + 'px'; return; } const uId = 'de-movecss-' + Math.round(Math.random() * 1e3); $css(`@keyframes ${ uId } { to { ${ lmw } top:${ top }px; } }`).className = 'de-css-move'; if(this._newPos) { style.cssText = this._newPos; pv.removeEventListener('animationend', this); } else { style.cssText = oldCSS; } this._newPos = `${ lmw } top:${ top }px;`; pv.addEventListener('animationend', this); pv.classList.add('de-pview-anim'); style.animationName = uId; } _showMenu(el, html) { super._showMenu(el, html); this._menu.onover = () => this.mouseEnter(); this._menu.onout = () => Pview.top.markToDel(); } _showPview(el) { el.addEventListener('mouseover', this, true); el.addEventListener('mouseout', this, true); this.thr.form.el.appendChild(el); this._setPosition(this._link, false); if(Cfg.animation) { el.addEventListener('animationend', function aEvent() { el.removeEventListener('animationend', aEvent); el.classList.remove('de-pview-anim'); el.style.animationName = ''; }); el.classList.add('de-pview-anim'); el.style.animationName = `de-post-open-${ this._isTop ? 't' : 'b' }${ this._isLeft ? 'l' : 'r' }`; } } } Pview.top = null; Pview._delTO = null; class CacheItem { constructor(pBuilder, thrUrl, count) { this._pBuilder = pBuilder; this._thrUrl = thrUrl; this.count = count; this.isDeleted = false; this.isInited = false; this.isOp = count === 0; this.isViewed = false; } * refLinks() { yield * this._pBuilder.getRefLinks(this.count, this._thrUrl); } get msg() { const value = $q(aib.qPostMsg, this.el); Object.defineProperty(this, 'msg', { value }); return value; } get ref() { const value = new RefMap(this); Object.defineProperty(this, 'ref', { value }); return value; } get sage() { const value = aib.getSage(this.el); Object.defineProperty(this, 'sage', { value }); return value; } get title() { return new Post.Сontent(this).title; } get el() { const value = this.isOp ? this._pBuilder.getOpEl() : this._pBuilder.getPostEl(this.count - 1); Object.defineProperty(this, 'el', { value: doc.adoptNode(value) }); return value; } get thr() { let value = null; if(this.isOp) { const pcount = this._pBuilder.length; value = { lastNum: this._pBuilder.getPNum(pcount - 1), pcount }; Object.defineProperty(value, 'title', { get: () => this.title }); } Object.defineProperty(this, 'thr', { value }); return value; } } class PviewsCache extends TemporaryContent { constructor(pBuilder, b, tNum) { super(b + tNum); if(this._isInited) { return; } this._isInited = true; const lPByNum = new Map(); const thrUrl = aib.getThrUrl(b, tNum); lPByNum.set(tNum, new CacheItem(pBuilder, thrUrl, 0)); for(let i = 0; i < pBuilder.length; ++i) { lPByNum.set(pBuilder.getPNum(i), new CacheItem(pBuilder, thrUrl, i + 1)); } DelForm.tNums.add(tNum); this._b = b; this._posts = lPByNum; if(Cfg.linksNavig) { RefMap.gen(lPByNum); } } getPost(num) { const post = this._posts.get(num); if(post && !post.isInited) { if(this._b === aib.b && pByNum.has(num)) { post.ref.makeUnion(pByNum.get(num).ref); } if(post.ref.hasMap) { post.ref.initPostRef(post._thrUrl, Cfg.strikeHidd && Post.hiddenNums.size ? Post.hiddenNums : null); } post.isInited = true; } return post; } } PviewsCache.purgeSecs = 3e5; /* ==[ PostImages.js ]======================================================================================== IMAGES images expanding (in post / by center), navigate buttons, image-links embedding =========================================================================================================== */ // Navigation buttons for expanding of images/videos by center class ImagesNavigBtns { constructor(viewerObj) { const btns = $bEnd(docBody, `
`); [this.prevBtn, this.nextBtn, this.autoBtn] = [...btns.children]; this._btns = btns; this._btnsStyle = btns.style; this._hideTmt = 0; this._isHidden = true; this._oldX = -1; this._oldY = -1; this._viewer = viewerObj; doc.defaultView.addEventListener('mousemove', this); btns.addEventListener('mouseover', this); } handleEvent(e) { switch(e.type) { case 'mousemove': { const { clientX: curX, clientY: curY } = e; if(this._oldX !== curX || this._oldY !== curY) { this._oldX = curX; this._oldY = curY; this.showBtns(); } return; } case 'mouseover': if(!this.hasEvents) { this.hasEvents = true; this._btns.addEventListener('mouseout', this); this._btns.addEventListener('click', this); } if(!this._isHidden) { clearTimeout(this._hideTmt); KeyEditListener.setTitle(this.prevBtn, 4); KeyEditListener.setTitle(this.nextBtn, 17); } return; case 'mouseout': this._setHideTmt(); return; case 'click': { const parent = e.target.parentNode; const viewer = this._viewer; switch(parent.id) { case 'de-img-btn-next': viewer.navigate(true); return; case 'de-img-btn-prev': viewer.navigate(false); return; case 'de-img-btn-rotate': viewer.rotateView(true); return; case 'de-img-btn-auto': this.autoBtn.title = (viewer.isAutoPlay = !viewer.isAutoPlay) ? Lng.autoPlayOff[lang] : Lng.autoPlayOn[lang]; viewer.toggleVideoLoop(); parent.classList.toggle('de-img-btn-auto-on'); } } } } hideBtns() { this._btnsStyle.display = 'none'; this._isHidden = true; this._oldX = this._oldY = -1; } removeBtns() { this._btns.remove(); doc.defaultView.removeEventListener('mousemove', this); clearTimeout(this._hideTmt); } showBtns() { if(this._isHidden) { this._btnsStyle.removeProperty('display'); this._isHidden = false; this._setHideTmt(); } } _setHideTmt() { clearTimeout(this._hideTmt); this._hideTmt = setTimeout(() => this.hideBtns(), 2e3); } } // Expanding of images/videos BY CENTER: resizing, moving, opening, closing class ImagesViewer { constructor(data) { this.data = null; this.isAutoPlay = false; this._data = null; this._elStyle = null; this._fullEl = null; this._height = 0; this._minSize = 0; this._moved = false; this._oldL = 0; this._oldT = 0; this._oldX = 0; this._oldY = 0; this._parentEl = null; this._width = 0; this._showFullImg(data); } closeImgViewer(e) { if(this.hasOwnProperty('_btns')) { this._btns.removeBtns(); } this._removeFullImg(e); } handleEvent(e) { switch(e.type) { case 'mousedown': if(this.data.isVideo && ExpandableImage.isControlClick(e)) { return; } this._oldX = e.clientX; this._oldY = e.clientY; docBody.addEventListener('mousemove', this, true); docBody.addEventListener('mouseup', this, true); break; case 'mousemove': { const { clientX: curX, clientY: curY } = e; if(curX !== this._oldX || curY !== this._oldY) { this._oldL = parseInt(this._elStyle.left, 10) + curX - this._oldX; this._elStyle.left = this._oldL + 'px'; this._oldT = parseInt(this._elStyle.top, 10) + curY - this._oldY; this._elStyle.top = this._oldT + 'px'; this._oldX = curX; this._oldY = curY; this._moved = true; } return; } case 'mouseup': docBody.removeEventListener('mousemove', this, true); docBody.removeEventListener('mouseup', this, true); return; case 'click': { const el = e.target; if(this.data.isVideo && ExpandableImage.isControlClick(e) || el.tagName !== 'IMG' && el.tagName !== 'VIDEO' && !el.classList.contains('de-fullimg-wrap') && !el.classList.contains('de-fullimg-wrap-link') && !el.classList.contains('de-fullimg-video-hack') && el.className !== 'de-fullimg-load' ) { return; } if(e.button === 0) { if(this._moved) { this._moved = false; } else { this.closeImgViewer(e); AttachedImage.viewer = null; } e.stopPropagation(); break; } return; } case 'mousewheel': this._handleWheelEvent(e.clientX, e.clientY, -1 / 40 * ('wheelDeltaY' in e ? e.wheelDeltaY : e.wheelDelta)); break; default: // 'wheel' event this._handleWheelEvent(e.clientX, e.clientY, e.deltaY); } $pd(e); } navigate(isForward, isVideoOnly = false) { let { data } = this; data.cancelWebmLoad(this._fullEl); do { data = data.getFollowImg(isForward); } while(data && !data.isVideo && !data.isImage || isVideoOnly && data.isImage); if(data) { this.updateImgViewer(data, true, null); data.post.selectAndScrollTo(data.post.images.first.el); } } rotateView(isNextAngle) { if(isNextAngle) { this.data.rotate += this.data.rotate === 270 ? -270 : 90; } const angle = this.data.rotate; const isVert = angle === 90 || angle === 270; const img = $q('img, video', this._fullEl); img.style.transform = `rotate(${ angle }deg)${ angle === 90 ? ' translateY(-100%)' : angle === 270 ? ' translateX(-100%)' : '' }`; img.classList.toggle('de-fullimg-rotated', isVert); img.style.height = `${ (isVert ? this._height / this._width : 1) * 100 }%`; if(this.data.isVideo && nav.firefoxVer >= 59) { img.previousElementSibling.style = (isVert ? 'width: calc(100% - 40px); height: 100%; ' : '') + (angle === 90 ? 'right: 0; ' : '') + (angle === 180 ? 'bottom: 0;' : ''); } if(isNextAngle || angle !== 180) { this._rotateFullImg(this._fullEl); } } toggleVideoLoop() { if(this.data.isVideo) { toggleAttr($q('video', this._fullEl), 'loop', '', !this.isAutoPlay); } } updateImgViewer(data, showButtons, e) { this._removeFullImg(e); this._showFullImg(data, showButtons); } get _btns() { const value = new ImagesNavigBtns(this); Object.defineProperty(this, '_btns', { value }); return value; } get _zoomFactor() { const value = 1 + (Cfg.zoomFactor / 100); Object.defineProperty(this, '_zoomFactor', { value }); return value; } _handleWheelEvent(clientX, clientY, delta) { if(delta === 0) { return; } let width, height; const { _width: oldW, _height: oldH } = this; if(delta > 0) { width = oldW / this._zoomFactor; height = oldH / this._zoomFactor; if(width <= this._minSize && height <= this._minSize) { return; } } else { width = oldW * this._zoomFactor; height = oldH * this._zoomFactor; } this._width = width; this._height = height; this._elStyle.width = width + 'px'; this._elStyle.height = height + 'px'; this._oldL = parseInt(clientX - (width / oldW) * (clientX - this._oldL), 10); this._elStyle.left = this._oldL + 'px'; this._oldT = parseInt(clientY - (height / oldH) * (clientY - this._oldT), 10); this._elStyle.top = this._oldT + 'px'; } _removeFullImg(e) { const { data } = this; data.cancelWebmLoad(this._fullEl); if(data.inPview && data.post.isSticky) { data.post.toggleSticky(false); } this._parentEl.remove(); if(e && data.inPview) { data.sendCloseEvent(e, false); } } _resizeFullImg(el) { if(el !== this._fullEl) { return; } let [width, height, minSize] = this.data.computeFullSize(); this._minSize = minSize ? minSize / this._zoomFactor : Cfg.minImgSize; if(Post.sizing.wWidth - this._oldL - this._width < 5 || Post.sizing.wHeight - this._oldT - this._height < 5 ) { return; } const cPointX = this._oldL + this._width / 2; const cPointY = this._oldT + this._height / 2; const maxWidth = (Post.sizing.wWidth - cPointX - 2) * 2; const maxHeight = (Post.sizing.wHeight - cPointY - 2) * 2; if(width > maxWidth || height > maxHeight) { const ar = width / height; if(ar > maxWidth / maxHeight) { width = maxWidth; height = width / ar; } else { height = maxHeight; width = height * ar; } if(minSize && width < minSize || height < minSize) { this._minSize = Math.max(width, height); } } this._width = width; this._height = height; this._elStyle.width = width + 'px'; this._elStyle.height = height + 'px'; this._elStyle.left = `${ this._oldL = parseInt(cPointX - width / 2, 10) }px`; this._elStyle.top = `${ this._oldT = parseInt(cPointY - height / 2, 10) }px`; } _rotateFullImg(el) { if(el !== this._fullEl) { return; } const { _width, _height } = this; this._width = _height; this._height = _width; this._elStyle.width = _height + 'px'; this._elStyle.height = _width + 'px'; const halfWidth = _width / 2; const halfHeight = _height / 2; this._elStyle.left = `${ this._oldL = parseInt(this._oldL + halfWidth - halfHeight, 10) }px`; this._elStyle.top = `${ this._oldT = parseInt(this._oldT + halfHeight - halfWidth, 10) }px`; } _showFullImg(data) { const [width, height, minSize] = data.computeFullSize(); this._fullEl = data.getFullImg(false, el => this._resizeFullImg(el), el => this._rotateFullImg(el)); this._width = width; this._height = height; this._minSize = minSize ? minSize / this._zoomFactor : Cfg.minImgSize; this._oldL = (Post.sizing.wWidth - width) / 2 - 1; this._oldT = (Post.sizing.wHeight - height) / 2 - 1; const el = $add(`
`); el.appendChild(this._fullEl); if(data.isImage) { $aBegin(this._fullEl, ``) .appendChild($q('img', this._fullEl)); } this._elStyle = el.style; this.data = data; this._parentEl = el; el.addEventListener('onwheel' in el ? 'wheel' : 'mousewheel', this, true); el.addEventListener('mousedown', this, true); el.addEventListener('click', this, true); data.srcBtnEvents(this); if(data.inPview && !data.post.isSticky) { data.post.toggleSticky(true); } const btns = this._btns; if(!data.inPview) { btns.showBtns(); btns.autoBtn.classList.toggle('de-img-btn-none', !data.isVideo); } else if(this.hasOwnProperty('_btns')) { btns.hideBtns(); } data.post.thr.form.el.appendChild(el); this.toggleVideoLoop(); if(this.data.rotate) { this.rotateView(false); } data.checkForRedirect(this._fullEl); } } // Post image/video main initialization class ExpandableImage { constructor(post, el, prev) { this.el = el; this.expanded = false; this.next = null; this.post = post; this.prev = prev; this.redirected = false; this.rotate = 0; this._fullEl = null; this._webmTitleLoad = null; if(prev) { prev.next = this; } } static isControlClick(e) { return Cfg.webmControl && e.clientY > (e.target.getBoundingClientRect().bottom - 40); } get height() { return (this._size || [-1, -1])[1]; } get inPview() { const value = this.post instanceof Pview; Object.defineProperty(this, 'inPview', { value }); return value; } get isImage() { const value = /(jpe?g|png|gif|webp)$/i.test(this.src) || (this.src.startsWith('blob:') && !this.el.hasAttribute('de-video')); Object.defineProperty(this, 'isImage', { value }); return value; } get isVideo() { const value = /(webm|mp4|ogv)(&|$)/i.test(this.src) || (this.src.startsWith('blob:') && this.el.hasAttribute('de-video')); Object.defineProperty(this, 'isVideo', { value }); return value; } get src() { const value = this._getImageSrc(); Object.defineProperty(this, 'src', { value, configurable: true }); return value; } get width() { return (this._size || [-1, -1])[0]; } cancelWebmLoad(fullEl) { if(this.isVideo) { const videoEl = $q('video', fullEl); videoEl.pause(); videoEl.removeAttribute('src'); videoEl.load(); } if(this._webmTitleLoad) { this._webmTitleLoad.cancelPromise(); this._webmTitleLoad = null; } } checkForRedirect(fullEl) { if(!aib.getImgRedirectSrc || this.redirected) { return; } aib.getImgRedirectSrc(this.src).then(newSrc => { this.redirected = true; Object.defineProperty(this, 'src', { value: newSrc }); $q('img, video', fullEl).src = this.el.src = this.el.parentNode.href = $q(aib.qImgNameLink, aib.getImgWrap(this.el)).href = newSrc; if(!this.isVideo) { $q('a', fullEl).href = newSrc; } }); } collapseImg(e) { // Collapse an image that expanded in post if(e && this.isVideo && ExpandableImage.isControlClick(e)) { return; } let fullImgTop; if(e) { fullImgTop = e.target.getBoundingClientRect().top; } this.cancelWebmLoad(this._fullEl); this.expanded = false; this._fullEl.remove(); this._fullEl = null; $show(this.el.parentNode); (aib.hasPicWrap ? this._getImageParent : this.el.parentNode).nextSibling.remove(); if(e) { $pd(e); if(this.inPview) { this.sendCloseEvent(e, true); } const origImgTop = this.el.getBoundingClientRect().top; if(fullImgTop < 0 || origImgTop < 0) { scrollTo(deWindow.pageXOffset, deWindow.pageYOffset + origImgTop); } } } computeFullSize() { if(!this._size) { if(this.isVideo) { return [0, 0, null]; } const el = new Image(); el.src = this.el.src; return [el.width, el.height, null]; } let [width, height] = this._size; if(Cfg.resizeDPI) { width /= Post.sizing.dPxRatio; height /= Post.sizing.dPxRatio; } const minSize = this.isVideo ? Math.max(Cfg.minImgSize, Cfg.minWebmWidth) : Cfg.minImgSize; if(width < minSize && height < minSize) { const ar = width / height; if(width > height) { width = minSize; height = width / ar; } else { height = minSize; width = this.isVideo ? minSize : height * ar; } } const maxWidth = Post.sizing.wWidth - 2; const maxHeight = Post.sizing.wHeight - (Cfg.imgInfoLink ? 24 : 2) - (nav.firefoxVer >= 59 && this.isVideo ? 19 : 0); if(width > maxWidth || height > maxHeight) { const ar = width / height; if(ar > maxWidth / maxHeight) { width = maxWidth; height = width / ar; } else { height = maxHeight; width = height * ar; } if(width < minSize || height < minSize) { return [width, height, Math.max(width, height)]; } } return [width, height, null]; } expandImg(inPost, e) { if(e && !e.bubbles) { return; } if(!inPost) { const { viewer } = AttachedImage; if(!viewer) { AttachedImage.viewer = new ImagesViewer(this); return; } if(viewer.data === this) { viewer.closeImgViewer(e); AttachedImage.viewer = null; return; } viewer.updateImgViewer(this, e); return; } let origImgTop; if(e) { origImgTop = e.target.getBoundingClientRect().top; } this.expanded = true; const { el } = this; (aib.hasPicWrap ? this._getImageParent : el.parentNode).insertAdjacentHTML('afterend', '
'); this._fullEl = this.getFullImg(true, null, null); this._fullEl.addEventListener('click', e => this.collapseImg(e), true); this.srcBtnEvents(this); $hide(el.parentNode); $after(el.parentNode, this._fullEl); this.checkForRedirect(this._fullEl); if(e) { const fullImgTop = this._fullEl.getBoundingClientRect().top; if(fullImgTop < 0 || origImgTop < 0) { scrollTo(deWindow.pageXOffset, deWindow.pageYOffset + fullImgTop); } } } getFollowImg(isForward) { const nImage = isForward ? this.next : this.prev; if(nImage) { return nImage; } let imgs, { post } = this; do { post = post.getAdjacentVisPost(!isForward); if(!post) { post = isForward ? Thread.first.op : Thread.last.last; if(post.isHidden || post.thr.isHidden) { post = post.getAdjacentVisPost(!isForward); if(!post) { return null; } } } imgs = post.images; } while(imgs.first === null); return isForward ? imgs.first : imgs.last; } getFullImg(inPost, onsizechange, onrotate) { let wrapEl, name, origSrc; const src = this._getImageSrc(); const parent = this._getImageParent; if(this.el.className !== 'de-img-embed') { const nameEl = $q(aib.qImgNameLink, parent) || $q('a', parent); origSrc = nameEl.getAttribute('de-href') || nameEl.href; ({ name } = this); } else { origSrc = parent.href; name = origSrc.split('/').pop(); } const imgNameEl = (Cfg.imgSrcBtns ? '' : '') + `${ name }`; const wrapClass = `${ inPost ? ' de-fullimg-wrap-inpost' : ` de-fullimg-wrap-center${ this._size ? '' : ' de-fullimg-wrap-nosize' }` }${ this.isVideo ? ' de-fullimg-video' : '' }`; // Expand images: JPG, PNG, GIF, WEBP if(!this.isVideo) { const waitEl = !aib.getImgRedirectSrc && this._size ? '' : ''; wrapEl = $add(``); const imgEl = $q('.de-fullimg', wrapEl); imgEl.onload = imgEl.onerror = ({ target: img }) => { if(!(img.naturalHeight + img.naturalWidth)) { if(!img.onceLoaded) { img.src = img.src; img.onceLoaded = true; } return; } const { naturalWidth: newW, naturalHeight: newH } = img; const ar = this._size ? this._size[1] / this._size[0] : newH / newW; const isRotated = !img.scrollWidth ? false : img.scrollHeight / img.scrollWidth > 1 ? ar < 1 : ar > 1; if(!this._size || isRotated) { this._size = isRotated ? [newH, newW] : [newW, newH]; } const parentEl = img.parentNode.parentNode; const waitEl = $q('.de-fullimg-load', parentEl); if(waitEl) { $hide(waitEl); parentEl.classList.remove('de-fullimg-wrap-nosize'); if(onsizechange) { onsizechange(parentEl); } } else if(isRotated && onrotate) { onrotate(parentEl); } }; DollchanAPI.notify('expandmedia', src); return wrapEl; } // Expand videos: WEBM, MP4 // FIXME: handle null size videos const isWebm = origSrc.split('.').pop() === 'webm'; const needTitle = isWebm && Cfg.webmTitles; let inPostSize = ''; if(inPost) { const [width, height] = this.computeFullSize(); inPostSize = ` style="width: ${ width }px; height: ${ height }px;"`; } const hasTitle = needTitle && this.el.hasAttribute('de-metatitle'); const title = hasTitle ? this.el.getAttribute('de-metatitle') : ''; wrapEl = $add(`
${ nav.firefoxVer < 59 ? '' : '
' }
${ imgNameEl }${ hasTitle && title ? ` - ${ title }` : '' } ${ needTitle && !hasTitle ? ` ` : '' }
`); const videoEl = $q('video', wrapEl); videoEl.volume = Cfg.webmVolume / 100; videoEl.addEventListener('ended', () => AttachedImage.viewer.navigate(true, true)); videoEl.addEventListener('error', ({ target: el }) => { if(!el.onceLoaded) { el.load(); el.onceLoaded = true; } }); if(!this._size) { videoEl.addEventListener('loadedmetadata', ({ target: el }) => { this._size = [el.videoWidth, el.videoHeight]; onsizechange(wrapEl); }); } // Sync webm volume on all browser tabs setTimeout(() => videoEl.dispatchEvent(new CustomEvent('volumechange')), 150); videoEl.addEventListener('volumechange', ({ target: el, isTrusted }) => { const val = el.muted ? 0 : Math.round(el.volume * 100); if(isTrusted && val !== Cfg.webmVolume) { saveCfg('webmVolume', val); sendStorageEvent('__de-webmvolume', val); } }); // MS Edge needs an external app with DollchanAPI to play webms if(nav.isMsEdge && isWebm && !DollchanAPI.hasListener('expandmedia')) { const href = 'https://github.com/Kagami/webmify/'; $popup('err-expandmedia', `${ Lng.errMsEdgeWebm[lang] }:\n${ href }`, false); } // Get webm title: load file and parse its metadata if(needTitle && !hasTitle) { this._webmTitleLoad = ContentLoader.loadImgData(videoEl.src, false).then(data => { $hide($q('.de-wait', wrapEl)); if(!data) { return; } let str = '', d = (new WebmParser(data.buffer)).getWebmData(); if(!d) { return; } d = d[0]; for(let i = 0, len = d.length; i < len; ++i) { // Segment Info = 0x1549A966, segment title = 0x7BA9[length | 0x80] if(d[i] === 0x49 && d[i + 1] === 0xA9 && d[i + 2] === 0x66 && d[i + 18] === 0x7B && d[i + 19] === 0xA9 ) { i += 20; for(let end = (d[i++] & 0x7F) + i; i < end; ++i) { str += String.fromCharCode(d[i]); } break; } } const loadedTitle = decodeURIComponent(escape(str)); this.el.setAttribute('de-metatitle', loadedTitle); if(str) { $q('.de-fullimg-link', wrapEl).textContent += ` - ${ videoEl.title = loadedTitle.replace(/\./g, ' ') }`; } }); } DollchanAPI.notify('expandmedia', src); return wrapEl; } sendCloseEvent(e, inPost) { let { post } = this; let cr = post.el.getBoundingClientRect(); const x = e.pageX - deWindow.pageXOffset; const y = e.pageY - deWindow.pageYOffset; if(!inPost) { while(x > cr.right || x < cr.left || y > cr.bottom || y < cr.top) { post = post.parent; if(post && (post instanceof Pview)) { cr = post.el.getBoundingClientRect(); } else { if(Pview.top) { Pview.top.markToDel(); } return; } } post.mouseEnter(); } else if(x > cr.right || y > cr.bottom && Pview.top) { Pview.top.markToDel(); } } srcBtnEvents({ _fullEl }) { if(!Cfg.imgSrcBtns) { return; } const srcBtnEl = $q('.de-btn-src', _fullEl); srcBtnEl.addEventListener('mouseover', () => (srcBtnEl.odelay = setTimeout(() => { const menuHtml = !this.isVideo ? Menu.getMenuImgSrc(srcBtnEl) : `${ Lng.getFrameLinks[lang] }`; new Menu(srcBtnEl, menuHtml, !this.isVideo ? emptyFn : optiontEl => { ContentLoader.getDataFromImg($q('video', _fullEl)).then(arr => { $popup('upload', Lng.sending[lang], true); const name = this.name.substring(0, this.name.lastIndexOf('.')) + '.png'; const blob = new Blob([arr], { type: 'image/png' }); let formData; if(!nav.isChrome || nav.scriptHandler !== 'WebExtension') { formData = new FormData(); formData.append('file', blob, name); } const ajaxParams = { data: formData || { arr, name }, method: 'POST' }; const frameLinkHtml = `${ Lng.saveFrame[lang] }`; $ajax('https://tmp.saucenao.com/', ajaxParams, true).then(xhr => { let hostUrl, errMsg = Lng.errSaucenao[lang]; try { const res = JSON.parse(xhr.responseText); if(res.status === 'success') { hostUrl = res.url ? Menu.getMenuImgSrc(res.url) : ''; } else { errMsg += ':
' + res.error_message; } } catch(e) {} $popup('upload', (hostUrl || errMsg) + frameLinkHtml); }, () => $popup('upload', Lng.errSaucenao[lang] + frameLinkHtml)); }, emptyFn); }); }, Cfg.linksOver))); srcBtnEl.addEventListener('mouseout', e => clearTimeout(e.target.odelay)); } get _size() { const value = this._getImageSize(); Object.defineProperty(this, '_size', { value, writable: true }); return value; } } // Initialization of embedded image that added to the link in post message class EmbeddedImage extends ExpandableImage { get _getImageParent() { const value = this.el.parentNode; Object.defineProperty(this, '_getImageParent', { value }); return value; } _getImageSize() { return [this.el.naturalWidth, this.el.naturalHeight]; } _getImageSrc() { return this.el.src; } } // Initialization of image/video that attached to the post class AttachedImage extends ExpandableImage { static closeImg() { const { viewer } = AttachedImage; if(viewer) { viewer.closeImgViewer(null); AttachedImage.viewer = null; } } get info() { const value = aib.getImgInfo(this._getImageParent); Object.defineProperty(this, 'info', { value }); return value; } get name() { const value = aib.getImgRealName(this._getImageParent).trim(); Object.defineProperty(this, 'name', { value }); return value; } get nameLink() { const value = $q(aib.qImgNameLink, this._getImageParent); Object.defineProperty(this, 'nameLink', { value }); return value; } get weight() { let value = 0; if(this.info) { const w = this.info.match(/(\d+(?:[.,]\d+)?)\s*([mмkк])?i?[bб]/i); const w1 = w[1].replace(',', '.'); value = w[2] === 'M' ? (w1 * 1e3) | 0 : !w[2] ? Math.round(w1 / 1e3) : w1; } Object.defineProperty(this, 'weight', { value }); return value; } get _getImageParent() { const value = aib.getImgWrap(this.el); Object.defineProperty(this, '_getImageParent', { value }); return value; } _getImageSize() { if(this.info) { const size = this.info.match(/(?:[\s(]|^)(\d+)\s?[x\u00D7]\s?(\d+)(?:[)\s,]|$)/); return size ? [size[1], size[2]] : null; } return null; } _getImageSrc() { // XXX: DON'T USE aib.getImgSrcLink(this.el).href // If #ihash spells enabled, Chrome reads href in ajaxed posts as empty -> image can't be expanded! return aib.getImgSrcLink(this.el).getAttribute('href'); } } AttachedImage.viewer = null; // A class that finds a set of images in a post class PostImages { constructor(post) { let first = null, last = null, els = $Q(aib.qPostImg, post.el); let hasAttachments = false; const filesMap = new Map(); for(let i = 0, len = els.length; i < len; ++i) { const el = els[i]; last = new AttachedImage(post, el, last); filesMap.set(el, last); hasAttachments = true; if(!first) { first = last; } } if(Cfg.addImgs || localData) { els = $Q('.de-img-embed', post.el); for(let i = 0, len = els.length; i < len; ++i) { const el = els[i]; last = new EmbeddedImage(post, el, last); filesMap.set(el, last); if(!first) { first = last; } } } this.first = first; this.last = last; this.hasAttachments = hasAttachments; this._map = filesMap; } get expanded() { for(let img = this.first; img; img = img.next) { if(img.expanded) { return true; } } return false; } get firstAttach() { return this.hasAttachments ? this.first : null; } getImageByEl(el) { return this._map.get(el); } [Symbol.iterator]() { return { _img: this.first, next() { const value = this._img; if(value) { this._img = value.next; return { value, done: false }; } return { done: true }; } }; } } const ImagesHashStorage = Object.create({ get getHash() { const value = this._getHashHelper.bind(this); Object.defineProperty(this, 'getHash', { value }); return value; }, endFn() { if(this.hasOwnProperty('_storage')) { sesStorage['de-imageshash'] = JSON.stringify(this._storage); } if(this.hasOwnProperty('_workers')) { this._workers.clearWorkers(); delete this._workers; } }, get _canvas() { const value = doc.createElement('canvas'); Object.defineProperty(this, '_canvas', { value }); return value; }, get _storage() { let value = null; try { value = JSON.parse(sesStorage['de-imageshash']); } finally { if(!value) { value = {}; } Object.defineProperty(this, '_storage', { value }); return value; } }, get _workers() { const value = new WorkerPool(4, this._genImgHash, emptyFn); Object.defineProperty(this, '_workers', { value, configurable: true }); return value; }, _genImgHash: ([arrBuf, oldw, oldh]) => { const buf = new Uint8Array(arrBuf); const size = oldw * oldh; for(let i = 0, j = 0; i < size; i++, j += 4) { buf[i] = buf[j] * 0.3 + buf[j + 1] * 0.59 + buf[j + 2] * 0.11; } const newh = 8; const neww = 8; const levels = 3; const areas = 256 / levels; const values = 256 / (levels - 1); let hash = 0; for(let i = 0; i < newh; ++i) { for(let j = 0; j < neww; ++j) { let temp = i / (newh - 1) * (oldh - 1); const l = Math.min(temp | 0, oldh - 2); const u = temp - l; temp = j / (neww - 1) * (oldw - 1); const c = Math.min(temp | 0, oldw - 2); const t = temp - c; hash = (hash << 4) + Math.min(values * (((buf[l * oldw + c] * ((1 - t) * (1 - u)) + buf[l * oldw + c + 1] * (t * (1 - u)) + buf[(l + 1) * oldw + c + 1] * (t * u) + buf[(l + 1) * oldw + c] * ((1 - t) * u)) / areas) | 0), 255); const g = hash & 0xF0000000; if(g) { hash ^= g >>> 24; } hash &= ~g; } } return { hash }; }, async _getHashHelper({ el, src }) { if(src in this._storage) { return this._storage[src]; } if(!el.complete) { await new Promise(resolve => el.addEventListener('load', () => resolve())); } if(el.naturalWidth + el.naturalHeight === 0) { return -1; } let data, buffer, val = -1; const { naturalWidth: w, naturalHeight: h } = el; if(aib._4chan) { const imgData = await ContentLoader.loadImgData(el.src); if(imgData) { ({ buffer } = imgData); } } else { const cnv = this._canvas; cnv.width = w; cnv.height = h; const ctx = cnv.getContext('2d'); ctx.drawImage(el, 0, 0); ({ buffer } = ctx.getImageData(0, 0, w, h).data); } if(buffer) { data = await new Promise(resolve => this._workers.runWorker([buffer, w, h], [buffer], val => resolve(val))); if(data && ('hash' in data)) { val = data.hash; } } this._storage[src] = val; return val; } }); function addImgSrcButtons(link, src) { link.insertAdjacentHTML('beforebegin', ``); } // Adding features for info links of images function processImgInfoLinks(parent, addSrc = Cfg.imgSrcBtns, imgNames = Cfg.imgNames) { if(addSrc || imgNames) { if(parent instanceof AbstractPost) { processPostImgInfoLinks(parent, addSrc, imgNames); } else { const posts = $Q(aib.qRPost + ', ' + aib.qOPost + ', .de-oppost', parent); for(let i = 0, len = posts.length; i < len; ++i) { processPostImgInfoLinks(pByEl.get(posts[i]), addSrc, imgNames); } } } } function processPostImgInfoLinks(post, addSrc, imgNames) { if(!post) { return; } for(const image of post.images) { const link = image.nameLink; if(!link) { return; } if(addSrc) { addImgSrcButtons(link, image.isVideo ? image.el.src : null); } const { name } = image; if(!link.classList.contains('de-img-name')) { link.classList.add('de-img-name'); link.title = name; link.setAttribute('download', name); link.setAttribute('de-href', link.href); } if(imgNames) { let ext; if(!(ext = link.getAttribute('de-img-ext'))) { ext = name.split('.').pop() || link.href.split('/').pop().split('.').pop(); link.setAttribute('de-img-ext', ext); link.setAttribute('de-img-name-old', link.textContent); } link.textContent = imgNames === 2 ? ext : name; } } } // Adding image previews before links in post message function embedPostMsgImages(el) { if(!Cfg.addImgs || localData) { return; } const els = $Q(aib.qMsgImgLink, el); for(let i = 0, len = els.length; i < len; ++i) { const link = els[i]; const url = link.href; if(url.includes('?') || aib.getPostOfEl(link).hidden) { continue; } $bBegin(link, `
`); if(Cfg.imgSrcBtns) { addImgSrcButtons(link); } } } /* ==[ PostBuilders.js ]====================================================================================== BUILDERS FOR LOADED POSTS =========================================================================================================== */ class DOMPostsBuilder { constructor(form, isArchived) { this._form = form; this._posts = $Q(aib.qRPost, form); this.length = this._posts.length; this.postersCount = ''; this._isArchived = isArchived; } get isClosed() { return aib.qClosed && !!$q(aib.qClosed, this._form) || this._isArchived; } getOpMessage() { return aib.fixHTML(doc.adoptNode($q(aib.qPostMsg, this._form))); } getPNum(i) { return aib.getPNum(this._posts[i]); } getOpEl() { return aib.fixHTML(aib.getOp($q(aib.qThread, this._form) || this._form)); } getPostEl(i) { return aib.fixHTML(this._posts[i]); } * getRefLinks(i, thrUrl) { // i === 0 - OP-post const msg = i === 0 ? $q(aib.qPostMsg, this._form) : $q(aib.qPostMsg, this._posts[i - 1]); const links = $Q('a', msg); for(let i = 0, len = links.length; i < len; ++i) { const link = links[i]; const tc = link.textContent; if(tc[0] === '>' && tc[1] === '>') { const lNum = parseInt(tc.substr(2), 10); if(lNum) { yield [link, lNum]; const url = link.getAttribute('href'); if(url[0] === '#') { link.setAttribute('href', thrUrl + url); } } } } } * bannedPostsData() { const banEls = $Q(aib.qBan, this._form); for(let i = 0, len = banEls.length; i < len; ++i) { const banEl = banEls[i]; const postEl = aib.getPostElOfEl(banEl); yield [1, postEl ? aib.getPNum(postEl) : null, doc.adoptNode(banEl)]; } } } class _4chanPostsBuilder { constructor(json, brd) { this._posts = json.posts; this._brd = brd; this.length = json.posts.length - 1; this.postersCount = this._posts[0].unique_ips; } static fixFileName(name, maxLength) { const decodedName = name.replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, "'") .replace(/</g, '<').replace(/>/g, '>'); return decodedName.length <= maxLength ? { isFixed: false, name } : { isFixed : true, name : decodedName.slice(0, 25).replace(/&/g, '&').replace(/"/g, '"') .replace(/'/g, ''').replace(//g, '>') }; } get isClosed() { return !!(this._posts[0].closed || this._posts[0].archived); } getOpMessage() { const { no, com } = this._posts[0]; return $add(aib.fixHTML(`
${ com }
`)); } getPNum(i) { return this._posts[i + 1].no; } getOpEl() { return this.getPostEl(-1); } getPostEl(i) { return $add(aib.fixHTML(this.getPostHTML(i))).lastElementChild; } getPostHTML(i) { const data = this._posts[i + 1]; const num = data.no; const brd = this._brd; const _icon = id => `//s.4cdn.org/image/${ id }${ deWindow.devicePixelRatio < 2 ? '.gif' : '@2x.gif' }`; // --- FILE --- let fileHTML = ''; if(data.filedeleted) { fileHTML = `
File deleted.
`; } else if(typeof data.filename === 'string') { let { name, isFixed: needTitle } = _4chanPostsBuilder.fixFileName(data.filename, 30); name += data.ext; if(!data.tn_w && !data.tn_h && data.ext === '.gif') { data.tn_w = data.w; data.tn_h = data.h; } const isSpoiler = data.spoiler; if(isSpoiler) { name = 'Spoiler Image'; data.tn_w = data.tn_h = 100; needTitle = false; } const size = prettifySize(data.fsize); const fileTextTitle = isSpoiler ? ` title="${ data.filename + data.ext }"` : ''; const aHref = needTitle ? `title="${ data.filename + data.ext }"` : ''; const imgSrc = isSpoiler ? '//s.4cdn.org/image/spoiler.png' : `//i.4cdn.org/${ brd }/${ data.tim }s.jpg`; fileHTML = `
File: ${ name } (${ size }, ${ data.ext === '.pdf' ? 'PDF' : data.w + 'x' + data.h })
${ size }
${ size } ${ data.ext.substr(1).toUpperCase() }
`; } // --- CAPCODE --- let highlight = '', ccBy = ''; let cc = data.capcode; switch(cc) { case 'admin_highlight': highlight = ' highlightPost'; cc = 'admin'; /* falls through */ case 'admin': ccBy = 'Administrators'; break; case 'mod': ccBy = 'Moderators'; break; case 'developer': ccBy = 'Developers'; break; case 'manager': ccBy = 'Managers'; break; case 'founder': ccBy = 'Founder'; } let ccName = '', ccText = '', ccImg = '', ccClass = ''; if(cc) { ccName = cc[0].toUpperCase() + cc.slice(1); ccText = `## ${ ccName }`; ccImg = `${
				ccName } Icon.`; ccClass = 'capcode' + (cc === 'founder' ? 'Admin' : ccName); } // --- POST --- const { name = '' } = data; const nameEl = `${ name }`; const mobNameEl = name.length <= 30 ? nameEl : `${ name.substring(30) }(…)`; const tripEl = `${ data.trip ? `${ data.trip }` : '' }`; const posteruidEl = data.id && !data.capcode ? `(ID: ${ data.id })` : ''; const flagEl = data.country ? `` : ''; const emailEl = data.email ? `` : ''; const replyEl = `No.${ num }`; const subjEl = `${ data.sub || '' }`; return `
>>
${ fileHTML }
${ data.com || '' }
`; } * bannedPostsData() {} } _4chanPostsBuilder._customSpoiler = new Map(); class DobrochanPostsBuilder { constructor(json, brd) { if(json.error) { throw new AjaxError(0, `API error: ${ json.error.message }`); } this._json = json.result; this._brd = brd; this._posts = json.result.threads[0].posts; this.length = this._posts.length - 1; this.postersCount = ''; } get isClosed() { return !!this._json.threads[0].archived; } getOpMessage() { return $add(aib.fixHTML(`
${ this._posts[0].message_html }
`)); } getPNum(i) { return this._posts[i + 1].display_id; } getOpEl() { return this.getPostEl(-1); } getPostEl(i) { const el = $add(aib.fixHTML(this.getPostHTML(i))); if(i === -1) { return el; } return el.firstElementChild.firstElementChild.lastElementChild; } getPostHTML(i) { const data = this._posts[i + 1]; const num = data.display_id; const brd = this._brd; const multiFile = data.files.length > 1; // --- FILE --- let filesHTML = ''; for(const { file_id, metadata, rating, size, src, thumb, thumb_height, thumb_width } of data.files) { let fileName, fullFileName, th = thumb; let thumbW = 200; let thumbH = 200; const ext = src.split('.').pop(); if(brd === 'b' || brd === 'rf') { fileName = fullFileName = th.split('/').pop(); } else { fileName = fullFileName = src.split('/').pop(); if(multiFile && fileName.length > 20) { fileName = fileName.substr(0, 20 - ext.length) + '(…)' + ext; } } const maxRating = 'r15'; // FIXME: read from settings if(rating === 'r-18g' && maxRating !== 'r-18g') { th = 'images/r-18g.png'; } else if(rating === 'r-18' && (maxRating !== 'r-18g' || maxRating !== 'r-18')) { th = 'images/r-18.png'; } else if(rating === 'r-15' && maxRating === 'sfw') { th = 'images/r-15.png'; } else if(rating === 'illegal') { th = 'images/illegal.png'; } else { thumbW = thumb_width; thumbH = thumb_height; } const fileInfo = `
Файл: ${ fileName }
${ ext }, ${ prettifySize(size) }, ${ metadata.width }x${ metadata.height } ${ multiFile ? '' : ' - Нажмите на картинку для увеличения' }
edit
`; filesHTML += `${ multiFile ? '' : fileInfo }
${ multiFile ? fileInfo : '' }
`; } // --- POST --- const date = data.date.replace(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/, (all, y, mo, d, h, m, s) => { const dt = new Date(y, +mo - 1, d, h, m, s); return `${ pad2(dt.getDate()) } ${ Lng.fullMonth[1][dt.getMonth()] } ${ dt.getFullYear() } (${ Lng.week[1][dt.getDay()] }) ${ pad2(dt.getHours()) }:${ pad2(dt.getMinutes()) }`; }); const isOp = i === -1; return `${ isOp ? `
` : `
>> ` } No.${ num }
${ filesHTML } ${ multiFile ? '
' : '' }
${ data.message_html }
${ isOp ? '' : '
' }`; } * bannedPostsData() {} } class MakabaPostsBuilder { constructor(json, brd) { if(json.Error) { throw new AjaxError(0, `API error: ${ json.Error } (${ json.Code })`); } this._json = json; this._brd = brd; this._posts = json.threads[0].posts; this.length = aib._2channel ? json.counter_posts - 1 : json.posts_count; this.postersCount = json.unique_posters; } get isClosed() { return this._json.is_closed; } getOpMessage() { return $add(aib.fixHTML(this._getPostMsg(this._posts[0]))); } getPNum(i) { return this._posts[i + 1].num; } getOpEl() { return this.getPostEl(-1); } getPostEl(i) { return $add(aib.fixHTML(this.getPostHTML(i))).firstElementChild; } getPostHTML(i) { const data = this._posts[i + 1]; const { num } = data; const brd = this._brd; const isNew = this._isNew; const p = isNew ? 'post__' : ''; const _switch = (val, obj) => val in obj ? obj[val] : obj['@@default']; // --- FILE --- let filesHTML = ''; if(data.files && data.files.length !== 0) { filesHTML = `
`; for(const file of data.files) { const imgId = num + '-' + file.md5; const { fullname = file.name, displayname: dispName = file.name } = file; const isVideo = file.type === 6 || file.type === 10; const imgClass = isNew ? `post__file-preview${ isVideo ? ' post__file-webm' : '' }${ data.nsfw ? ' post__file-nsfw' : '' }` : `img preview${ isVideo ? ' webm-file' : '' }`; filesHTML += `
${ dispName } (${ file.size }Кб, ` + `${ file.width }x${ file.height }${ isVideo ? ', ' + file.duration : '' })
`; } filesHTML += '
'; } // --- POST --- const emailEl = data.email ? `${ data.name }` : `${ data.name }`; const tripEl = !data.trip ? '' : `## ${ aib._2channel ? 'Admin' : 'Abu' } ##`, '!!%mod%!!' : `${ p }mod">## Mod ##`, '!!%Inquisitor%!!' : `${ p }inquisitor">## Applejack ##`, '!!%coder%!!' : `${ p }mod">## Кодер ##`, '!!%curunir%!!' : `${ p }mod">## Curunir ##`, '@@default' : `${ data.trip_style ? data.trip_style : isNew ? 'post__trip' : 'postertrip' }">` + data.trip }) }`; const refHref = `/${ brd }/res/${ parseInt(data.parent) || num }.html#${ num }`; let rate = ''; if(this._hasLikes) { const likes = `
` : 'like-div"> ' } `; const dislikes = likes.replace(/like/g, 'dislike').replace('icon__thunder', 'icon__thumbdown'); rate = `${ likes }${ data.likes || 0 }
${ dislikes }${ data.dislikes || 0 }
`; } const isOp = i === -1; const wrapClass = !isNew ? 'post-wrapper' : isOp ? 'thread__oppost' : 'thread__post'; const timeReflink = `${ data.date } ` + `` + `${ aib._2channel ? 'No.' : '№' }` + `${ num } `; return `
${ !data.subject ? '' : `` + `${ data.subject + (data.tags ? ` /${ data.tags }/` : '') }` } ${ emailEl } ${ data.icon ? `` + `${ data.icon }` : '' } ${ tripEl } ${ data.op === 1 ? `# OP ` : '' } ${ isNew ? timeReflink : ` ${ timeReflink } ` } ${ rate }
${ filesHTML } ${ this._getPostMsg(data) }
`; } * bannedPostsData() { const p = this._isNew ? 'post__' : ''; for(const { banned, num } of this._posts) { switch(banned) { case 1: yield [1, num, $add(`(Автор этого поста был забанен.)`)]; break; case 2: yield [2, num, $add(`` + '(Автор этого поста был предупрежден.)')]; break; } } } get _hasLikes() { const value = !!$q('.like-div, .post__rate'); Object.defineProperty(this, '_hasLikes', { value }); return value; } get _isNew() { const value = !!$q('.post_type_oppost'); Object.defineProperty(this, '_isNew', { value }); return value; } _getPostMsg(data) { const _switch = (val, obj) => val in obj ? obj[val] : obj['@@default']; const comment = data.comment.replace(/