/** * Script Name: JS-скрипт для файлового хранилища Getcourse * Version: 1.0 * Author: Максим Калмыков * Url: https://t.me/getcomponent */ $(function () { if (!window.userInfo.isAdmin) return; (function () { if (!window.gcAccountUserMenu) return; const profile = window.gcAccountUserMenu.items.find(menuItem => menuItem.id === 'profile'); if (!profile) return; const fileService = profile.subitems.find(profileItem => profileItem.id === 'fileserviceAccountStat'); if (fileService) fileService.url += '?sort=-created_at'; })(); if (location.pathname.indexOf("/fileservice/control/account/storage") === -1) return; $('.standard-page-content > .btn-group').prepend("

Показать сначала:

Новые файлыСтарые файлы"); const archiveImage = "https://fs.getcourse.ru/fileservice/file/download/a/556025/sc/469/h/389a4619093e40c4ae3576d7b6340425.png"; const docsInfo = { pdf: { icon: "https://fs.getcourse.ru/fileservice/file/download/a/556025/sc/206/h/d8f3c98573c09bc7e43750dc7ad51d54.png", exts: ['pdf'] }, sheet: { icon: "https://fs.getcourse.ru/fileservice/file/download/a/556025/sc/163/h/39f56b599f06e954a521c515bf3df8c3.png", exts: ['xlsx', 'csv'] }, doc: { icon: "https://fs.getcourse.ru/fileservice/file/download/a/556025/sc/245/h/a58bcff963c7d8ad326014b6328bfb64.png", exts: ['docx', 'doc'] }, js: { icon: "https://fs.getcourse.ru/fileservice/file/download/a/556025/sc/111/h/d1093f7c9ea35d210357795a495e28ee.png", exts: ['js'] }, css: { icon: "https://fs.getcourse.ru/fileservice/file/download/a/556025/sc/294/h/7d9010eb630eeaf84fd3c88aaa92791e.png", exts: ['css'] }, eml: { icon: "https://fs.getcourse.ru/fileservice/file/download/a/602055/sc/204/h/7d037cda84be880d8964cac137f3c663.png", exts: ['eml'] } }; $('#files .gc-file-link').each((_, row) => { const $fileShowContainer = $(row).find('td[data-col-seq="2"]'), fileNameStr = $fileShowContainer.text().trim(), fileShowItemLink = $fileShowContainer.find('a').attr('href'), fileTypeText = $(row).find('td[data-col-seq="3"]').text(), pageFileLink = $(row).find('td[data-col-seq="1"] > a').attr('href'); if (fileTypeText == 'изображение' || fileTypeText == 'image' || fileTypeText == 'fotografías') { $fileShowContainer.append(`
`); } else if (fileTypeText == 'видео' || fileTypeText == 'video' || fileTypeText == 'vídeos') { $fileShowContainer.append(`
`); } else if (fileTypeText == 'аудио' || fileTypeText == 'audio' || fileTypeText == 'audios') { $fileShowContainer.append(`
`); } else if (fileTypeText == 'архив' || fileTypeText == 'archive' || fileTypeText == 'archivos') { insertBadge($fileShowContainer, archiveImage); } else if (fileTypeText == 'документ' || fileTypeText == 'document' || fileTypeText == 'documentos') { insertBadge($fileShowContainer, getDocIcon(fileNameStr, docsInfo)); } getFileLink(pageFileLink, $fileShowContainer); }); function insertBadge($container, badge) { if (!badge) return; $container.prepend(`
`); } function getDocIcon(fileName, docsInfo) { const extension = fileName.match(/\.([^.]+)$|$/)[1]; if (!extension) return false; for (key in docsInfo) { if (docsInfo[key]['exts'].includes(extension)) { return docsInfo[key]['icon']; } } return false; } function getFileLink(fileToLink, $container) { $.get(fileToLink, function (data) { const htmlPage = $('
').html(data); $container.append(htmlPage.find('.col-md-10 > input[type="text"]').css({ "display": "block", "height": 0, "padding": 0, "opacity": 0, "border": 0 })); $container.append(""); $container.on('click', (e) => { if (e.target && ($(e.target).hasClass('btn_copy') || $(e.target).hasClass('form-control'))) { $(e.target).parent().find('input')[0].select(); document.execCommand('copy'); $(e.target).parent().find('.btn_copy').html(' Скопированна').addClass('btn-info'); } }); }); } $('.uploadify-container').data('uploadifive').settings.onUploadComplete = function (e, fileHashNameStr) { const $item = e.queueItem; const link = `/fileservice/control/account/file-by-hash?hash=${fileHashNameStr}&from=storage`; $item.find('.fileinfo').html(` ${fileHashNameStr} `); $.get(link, (data) => { const pageHtml = $('
').html(data), fileLinkStr = pageHtml.find('input.form-control[type="text"]').val(), inputEl = document.createElement('input'), spanEl = document.createElement('span'); $item.find('span.filename').before(spanEl); $item.find('span.filename').after(inputEl); $(inputEl).attr('type', 'text').val(fileLinkStr).css({ "display": "block", "height": 0, "padding": 0, "opacity": 0, "border": 0 }); $(spanEl).html(' ') .css({ "cursor": "pointer", "font-size": "20px" }).on('click', function () { inputEl.select(); document.execCommand('copy'); $(spanEl).css('color', "#45dc4b"); }); }); } });