`);
+ $('#readme_md').hide().html('');
+ $('#head_md').hide().html('');
+
+ /**
+ * Callback after the column list request successfully returns data
+ * The result returned by @param res (object)
+ * @param path the requested path
+ * @param prevReqParams parameters used in request
+ */
+ function successResultCallback(res, path, prevReqParams) {
+
+ // Temporarily store nextPageToken and currentPageIndex in the list element
+ $('#list')
+ .data('nextPageToken', res['nextPageToken'])
+ .data('curPageIndex', res['curPageIndex']);
+
+ // Remove loading spinner
+ $('#spinner').remove();
+
+ if (res['nextPageToken'] === null) {
+ // If it is the last page, unbind the scroll event, reset scroll_status, and append the data
+ $(window).off('scroll');
+ window.scroll_status.event_bound = false;
+ window.scroll_status.loading_lock = false;
+ append_files_to_list(path, res['data']['files']);
+ } else {
+ // If it is not the last page, append data and bind the scroll event (if not already bound), update scroll_status
+ append_files_to_list(path, res['data']['files']);
+ if (window.scroll_status.event_bound !== true) {
+ // Bind event, if not yet bound
+ $(window).on('scroll', function () {
+ var scrollTop = $(this).scrollTop();
+ var scrollHeight = getDocumentHeight();
+ var windowHeight = $(this).height();
+ // Roll to the bottom
+ if (scrollTop + windowHeight > scrollHeight - (Os.isMobile ? 130 : 80)) {
+ /*
+ When the event of scrolling to the bottom is triggered, if it is already loading at this time, the event is ignored;
+ Otherwise, go to loading and occupy the loading lock, indicating that loading is in progress
+ */
+ if (window.scroll_status.loading_lock === true) {
+ return;
+ }
+ window.scroll_status.loading_lock = true;
+
+ // Show a loading spinner
+ $(``)
+ .insertBefore('#readme_md');
+ mdui.updateSpinners();
+ // mdui.mutation();
+
+ let $list = $('#list');
+ requestListPath(path, {
+ password: prevReqParams['password'],
+ page_token: $list.data('nextPageToken'),
+ // Request next page
+ page_index: $list.data('curPageIndex') + 1
+ },
+ successResultCallback,
+ // The password is the same as before. No authError
+ null
+ )
+ }
+ });
+ window.scroll_status.event_bound = true
+ }
+ }
+
+ // After loading successfully and rendering new data successfully, release the loading lock so that you can continue to process the "scroll to bottom" event
+ if (window.scroll_status.loading_lock === true) {
+ window.scroll_status.loading_lock = false
+ }
+ }
+
+ // Start requesting data from page 1
+ requestListPath(path, {password: password},
+ successResultCallback,
+ function (path) {
+ $('#spinner').remove();
+ var pass = prompt("Directory encryption, please enter the password", "");
+ localStorage.setItem('password' + path, pass);
+ if (pass != null && pass != "") {
+ list(path);
+ } else {
+ history.go(-1);
+ }
+ });
+}
+
+/**
+ * Append the data of the requested new page to the list
+ * @param path
+ * @param files request result
+ */
+function append_files_to_list(path, files) {
+ var $list = $('#list');
+ // Is it the last page of data?
+ var is_lastpage_loaded = null === $list.data('nextPageToken');
+ var is_firstpage = '0' == $list.data('curPageIndex');
+
+ html = "";
+ let targetFiles = [];
+ for (i in files) {
+ var item = files[i];
+ var p = path + item.name + '/';
+ if (item['size'] == undefined) {
+ item['size'] = "";
+ }
+
+ item['modifiedTime'] = utc2beijing(item['modifiedTime']);
+ item['size'] = formatFileSize(item['size']);
+ if (item['mimeType'] == 'application/vnd.google-apps.folder') {
+ html += `
`);
+ $('#readme_md').hide().html('');
+ $('#head_md').hide().html('');
+
+ /**
+ * Callback after successful search request returns data
+ * The result returned by @param res (object)
+ * @param path the requested path
+ * @param prevReqParams parameters used in request
+ */
+ function searchSuccessCallback(res, prevReqParams) {
+
+ // Temporarily store nextPageToken and currentPageIndex in the list element
+ $('#list')
+ .data('nextPageToken', res['nextPageToken'])
+ .data('curPageIndex', res['curPageIndex']);
+
+ // Remove loading spinner
+ $('#spinner').remove();
+
+ if (res['nextPageToken'] === null) {
+ // If it is the last page, unbind the scroll event, reset scroll_status, and append the data
+ $(window).off('scroll');
+ window.scroll_status.event_bound = false;
+ window.scroll_status.loading_lock = false;
+ append_search_result_to_list(res['data']['files']);
+ } else {
+ // If it is not the last page, append data and bind the scroll event (if not already bound), update scroll_status
+ append_search_result_to_list(res['data']['files']);
+ if (window.scroll_status.event_bound !== true) {
+ // Bind event, if not yet bound
+ $(window).on('scroll', function () {
+ var scrollTop = $(this).scrollTop();
+ var scrollHeight = getDocumentHeight();
+ var windowHeight = $(this).height();
+ // Roll to the bottom
+ if (scrollTop + windowHeight > scrollHeight - (Os.isMobile ? 130 : 80)) {
+ /*
+ When the event of scrolling to the bottom is triggered, if it is already loading at this time, the event is ignored;
+ Otherwise, go to loading and occupy the loading lock, indicating that loading is in progress
+ */
+ if (window.scroll_status.loading_lock === true) {
+ return;
+ }
+ window.scroll_status.loading_lock = true;
+
+ // Show a loading spinner
+ $(``)
+ .insertBefore('#readme_md');
+ mdui.updateSpinners();
+ // mdui.mutation();
+
+ let $list = $('#list');
+ requestSearch({
+ q: window.MODEL.q,
+ page_token: $list.data('nextPageToken'),
+ // Request next page
+ page_index: $list.data('curPageIndex') + 1
+ },
+ searchSuccessCallback
+ )
+ }
+ });
+ window.scroll_status.event_bound = true
+ }
+ }
+
+ // After loading successfully and rendering new data successfully, release the loading lock so that you can continue to process the "scroll to bottom" event
+ if (window.scroll_status.loading_lock === true) {
+ window.scroll_status.loading_lock = false
+ }
+ }
+
+ // Start requesting data from page 1
+ requestSearch({q: window.MODEL.q}, searchSuccessCallback);
+}
+
+/**
+ * Append a new page of search results
+ * @param files
+ */
+function append_search_result_to_list(files) {
+ var $list = $('#list');
+ // Is it the last page of data?
+ var is_lastpage_loaded = null === $list.data('nextPageToken');
+ // var is_firstpage = '0' == $list.data('curPageIndex');
+
+ html = "";
+
+ for (i in files) {
+ var item = files[i];
+ if (item['size'] == undefined) {
+ item['size'] = "";
+ }
+
+ item['modifiedTime'] = utc2beijing(item['modifiedTime']);
+ item['size'] = formatFileSize(item['size']);
+ if (item['mimeType'] == 'application/vnd.google-apps.folder') {
+ html += `
`;
+ }
+ }
+
+ // When it is page 1, remove the horizontal loading bar
+ $list.html(($list.data('curPageIndex') == '0' ? '' : $list.html()) + html);
+ // When it is the last page, count and display the total number of items
+ if (is_lastpage_loaded) {
+ $('#count').removeClass('mdui-hidden').find('.number').text($list.find('li.mdui-list-item').length);
+ }
+}
+
+/**
+ * Search result item click event
+ * @param a_ele Clicked element
+ */
+function onSearchResultItemClick(a_ele) {
+ var me = $(a_ele);
+ var can_preview = me.hasClass('view');
+ var cur = window.current_drive_order;
+ var dialog = mdui.dialog({
+ title: '',
+ content: '
Getting target path...
',
+ // content: '',
+ history: false,
+ modal: true,
+ closeOnEsc: true
+ });
+ mdui.updateSpinners();
+
+ // Request a path
+ $.post(`/${cur}:id2path`, {id: a_ele.id}, function (data) {
+ if (data) {
+ dialog.close();
+ var href = `/${cur}:${data}${can_preview ? '?a=view' : ''}`;
+ dialog = mdui.dialog({
+ title: 'Target path',
+ content: `${data}`,
+ history: false,
+ modal: true,
+ closeOnEsc: true,
+ buttons: [
+ {
+ text: 'turn on', onClick: function () {
+ window.location.href = href
+ }
+ }, {
+ text: 'Open in new tab', onClick: function () {
+ window.open(href)
+ }
+ }
+ , {text: 'cancel'}
+ ]
+ });
+ return;
+ }
+ dialog.close();
+ dialog = mdui.dialog({
+ title: ' Failed to get the target path',
+ content: 'It may be because this item does not exist in the disc! It may also be because the file [Shared with me] has not been added to Personal Drive!',
+ history: false,
+ modal: true,
+ closeOnEsc: true,
+ buttons: [
+ {text: 'WTF ???'}
+ ]
+ });
+ })
+}
+
+function get_file(path, file, callback) {
+ var key = "file_path_" + path + file['modifiedTime'];
+ var data = localStorage.getItem(key);
+ if (data != undefined) {
+ return callback(data);
+ } else {
+ $.get(path, function (d) {
+ localStorage.setItem(key, d);
+ callback(d);
+ });
+ }
+}
+
+
+// File display ?a=view
+function file(path) {
+ var name = path.split('/').pop();
+ var ext = name.split('.').pop().toLowerCase().replace(`?a=view`, "").toLowerCase();
+ if ("|html|php|css|go|java|js|json|txt|sh|md|".indexOf(`|${ext}|`) >= 0) {
+ return file_code(path);
+ }
+
+ if ("|mp4|webm|avi|".indexOf(`|${ext}|`) >= 0) {
+ return file_video(path);
+ }
+
+ if ("|mpg|mpeg|mkv|rm|rmvb|mov|wmv|asf|ts|flv|".indexOf(`|${ext}|`) >= 0) {
+ return file_video(path);
+ }
+
+ if ("|mp3|flac|wav|ogg|m4a|".indexOf(`|${ext}|`) >= 0) {
+ return file_audio(path);
+ }
+
+ if ("|bmp|jpg|jpeg|png|gif|".indexOf(`|${ext}|`) >= 0) {
+ return file_image(path);
+ }
+
+ if ('pdf' === ext) return file_pdf(path);
+}
+
+// Document display |html|php|css|go|java|js|json|txt|sh|md|
+function file_code(path) {
+ var type = {
+ "html": "html",
+ "php": "php",
+ "css": "css",
+ "go": "golang",
+ "java": "java",
+ "js": "javascript",
+ "json": "json",
+ "txt": "Text",
+ "sh": "sh",
+ "md": "Markdown",
+ };
+ var name = path.split('/').pop();
+ var ext = name.split('.').pop().toLowerCase();
+ var href = window.location.origin + path;
+ var content = `
+