// ==UserScript==
// @name Supercharged Local Directory File Browser
// @version 3.1.2
// @description Makes file:/// directory ("Index of...") pages (and many server-generated index pages) actually useful. Adds navigation links, file preview pane, keyboard navigation, user-defined shortcuts, filtering, more.
// @author Gaspar Schott (Michael Schrauzer) mshroud@gmail.com
// @license GPL-3.0-or-later
// @homepageURL https://openuserjs.org/scripts/gaspar_schot/Supercharged_Local_Directory_File_Browser
// @contributionURL https://paypal.me/mschrauzer
// @include file://*/
// @include file://*/?*
// @include *!localhost*/
// @include *michaelschrauzer.com/backups*
// @include *downloads.it.ox.ac.uk/*/
// @include *otrrlibrary.org/*
// @include *hypem.com*
// @include http://ftp.gnu.org/*/
// @include https://hypem.com/*/
// @include https://nodejs.org/dist*
// @include http://www.caratulas.com*/
// @include *fromv.ir/*/
// @include https://cdimage.parrotsec.org/parrot/iso*
// @include http://mirror.centos.org/centos*
// @require http://code.jquery.com/jquery-latest.min.js
// NOTE: This script was developed in Vivaldi, running on Mac OS High Sierra. It has been tested in various Chrome and Gecko-based browsers.
// It has been minimally tested on Windows and not at all on other OSes. It should work, but please report any issues.
// The script does not work on local directories in Safari because Safari does not allow local directories to be browsed, but it will work on remote directories (or on local directories through a local server).
// NOTE: By default, Greasemonkey and Tampermonkey will not run scripts on file:/// urls, so for this script to work, you will have to enable it first.
// For Tampermonkey, go to Chrome extension page, and tick the 'Allow access to file URLs' checkbox at the Tampermonkey extension section.
// For Greasemonkey, open about:config and change greasemonkey.fileIsGreaseable to true.
// @namespace https://greasyfork.org/users/16170
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
var $ = jQuery;
// ***** USER SETTINGS ***** //
const $settings = {
// Paste your exported settings between the two lines below:
//--------------------------------------------------------//
shortcuts: // N.B.: Directory links must end with "/", file links must end with another character.
// You may add as many menus and links as you like; just copy the example below and edit as needed.
// Local directory shortcuts must begin with "file:///"; external shortcuts must begin with the correct protocol ("http://" or "ftp://", etc.).
// Note that because of same-origin security concerns, the browser will not allow you to navigate from an external webpage to a local directory.
// But see this page for possible workarounds: https://stackoverflow.com/questions/39007243/cannot-open-local-file-chrome-not-allowed-to-load-local-resource
[
// {
// "menu_title":"My Sample Menu",
// "links":
// [
// { "link_name":"My Directory Link 1", "link":"file:///Path/To/My/Directory/" },
// { "link_name":"My Directory Link 2", "link":"file:///Path/To/My/Directory_2/" },
// { "link_name":"My External Link", "link":"https://www.mywebpage.com/" },
// { "link_name":"My File Link", "link":"file:///Path/To/My/File.ext" },
// ]
// },
{
"menu_title":"Volumes",
"links":
[
{ "link_name":"Mac", "link":"file:///Volumes/Mac/" },
{ "link_name":"PQI 64GB", "link":"file:///Volumes/PQI 64GB%20USB%20Drive%201/" },
{ "link_name":"JETDRIVE 128GB", "link":"file:///Volumes/JETDRIVE%20128GB%20Drive/" },
]
},
{
"menu_title":"Root Links",
"links":
[
{ "link_name":"Applications", "link":"file:///Applications/" },
{ "link_name":"Library", "link":"file:///Library/" },
{ "link_name":"Users", "link":"file:///Users/" },
{ "link_name":"Volumes", "link":"file:///Volumes/" },
]
},
{
"menu_title":"MacBookPro",
"links":
[
{ "link_name":"Desktop", "link":"file:///Users/MacBookPro/Desktop/" },
{ "link_name":"Documents", "link":"file:///Users/MacBookPro/Documents/" },
{ "link_name":"Downloads", "link":"file:///Users/MacBookPro/Downloads/" },
{ "link_name":"Downloads", "link":"file:///Users/MacBookPro/Dropbox/" },
{ "link_name":"Library", "link":"file:///Users/MacBookPro/Library/" },
{ "link_name":"Own Cloud", "link":"file:///Users/MacBookPro/ownCloud/" },
]
},
{
"menu_title":"Business",
"links":
[
{ "link_name":"Fonts System", "link":"file:///Users/MacBookPro/Library/Fonts/" },
{ "link_name":"Fonts PQI", "link":"file:///Volumes/PQI%2064GB%20USB%20Drive%201/04%20GRAPHICS%20Fonts/" },
{ "link_name":"AP Book Covers", "link":"file:///Users/MacBookPro/Documents/04%20BUSINESS/ANGELICO%20PRESS/AP%20BOOK%20COVERS%20Working/" },
{ "link_name":"Invoices", "link":"file:///Users/MacBookPro/Dropbox/DOCUMENTS/INVOICES/" },
{ "link_name":"WWW", "link":"file:///Applications/AMPPS/www/ "}
]
},
{
"menu_title":"Empty Vessel",
"links":
[
{ "link_name":"Library", "link":"file:///Users/MacBookPro/Documents/02%20LIBRARY/" },
{ "link_name":"The Empty Vessel", "link":"file:///Users/MacBookPro/Documents/02%20LIBRARY/10%20THE%20EMPTY%20VESSEL/" },
{ "link_name":"Literature", "link": "file:///Users/MacBookPro/Documents/02%20LIBRARY/P%20LITERATURE/" },
{ "link_name":"Defoe", "link": "file:///Users/MacBookPro/Documents/02%20LIBRARY/P%20LITERATURE/00%201660-1731%20DEFOE%20DANIEL/" },
{ "link_name":"Working Text Files", "link": "file:///Users/MacBookPro/Documents/02%20LIBRARY/P%20LITERATURE/WORKING%20TEXT%20FILES/" },
]
},
{
"menu_title":"External Links",
"links":
[
{ "link_name":"michaelschrauzer.com/backups", "link":"https://michaelschrauzer.com/backups/" },
{ "link_name":"michaelschrauzer.com/backups/buffalo", "link":"https://michaelschrauzer.com/backups/BUFFALO/?dark_theme=true&hide_details=true&sort=name" },
{ "link_name":"michaelschrauzer.com/backups/spoken_word", "link":"https://michaelschrauzer.com/backups/BUFFALO/SPOKEN%20WORD/?dark_theme=true&hide_details=true&selected=9&sort=name" },
{ "link_name":"Mere Nature","link":"file:///Users/MacBookPro/Documents/02%20LIBRARY/P%20LITERATURE/00%201660-1731%20DEFOE%20DANIEL/DEFOE%201726%20Mere%20Nature%20Delineated.htm" },
]
}
],
UI_font: // Choose an installed font for the UI.
'lucidagrande, sans-serif',
UI_font_size: // Choose a default UI font size; use any standard CSS units.
'13px',
alternate_background: // If true (default false), alternate sidebar row background color.
true,
ignore_files: // If true (default), ignored files (see "$row_settings" below, after Keybindings and Changelog) will be greyed-out (default) in the file list and will not be loaded in the content pane when selected;
// If false, they will be treated as normal files, so if they are selected, the browser will attempt to download any file types it can't handle (which makes keyboard navigation inconvenient).
true,
hide_ignored_files: // If true, ignored files will be completely hidden from the file list;
// If false (default), ignored files will appear greyed-out.
false,
hide_invisibles: // Un*x/Mac OS only: If true (default), files or directories beginning with a "." will be hidden.
true,
hide_details: // If true (default), hide file and directory details; if false, show them.
true,
default_sort: // Choose from: 'name', 'size', 'date', 'kind', 'ext', 'default'.
// default = Chrome sorting: dirs on top, files alphabetical.
'ext',
dirs_on_top: // If true, directories will always be listed firs except when sorting by "name" (since otherwise sorting by "name" would equal "default").
// If false (default), directories and files will be sorted together. (In practice, dirs will typically still be separated when sorting by size, kind, and extension.)
true,
apps_as_dirs: // Un*x/Mac OS only: if true, treat apps as directories; allows app contents to be browsed. This is the default behavior for Chrome.
// If false (default), treat apps as ignored files.
false,
dark_theme: // If true (default: false), gives the content pane a dark background, and inverts html and text content.
true,
grid_image_size: // Default = 200
200,
grid_font_size: // Default = 1
1,
autoload_media: // If true (defautl: true), the first audio or video file found in a directory will be automatically selected and loaded for playback; also, cover art (if any, will be loaded in the preview pane).
true,
autoload_index_files: // If true (default: false), automatically select first "index.ext" file found in directory.
false,
use_custom_icons: // if true (default), use custom icons for dirs and files
// if false, use browser/server default icons
true
//--------------------------------------------------------//
// Paste your exported settings between the above two lines.
}
// $ROW_TYPES:
// DO NOT DELETE ANY EXISTING CATEGORIES!
// Add file extensions for sorting and custom icon display to the existing categories.
// You can also define your own new categories, but do not add an extension to more than one row_type category.
// Do not add leading "." to the extensions.
const $row_types = {
// myCategory: ['ext1','ext2',],
dir: ['/'],
app: ['app/','app','exe','msi'],
archive: ['zip','rar','cbr','7z','tar','gz','dmg','pkg','archive'],
audio: ['mp3','m4a','aac','aif','aiff','ape','flac','ogg','wav'],
font: ['otf','ttf','woff','woff2','afm','pfb','pfm','tfm'],
graphics: ['indd','idml','indt','icml','ai','eps','pages','qxp','qxb','qxd','mif','sla','dtp','pmd','pub','fm','book','inx'],
htm: ['htm','html','xhtm','xhtml'],
image: ['jpg','jpeg','png','apng','gif','bmp','webp','svg','tif','tiff','psd','raw','dng','cr2','nef','arw'],
office: ['doc','docx','epub','xls','xlsx','xlm','odt','odf','rtf'],
pdf: ['pdf'],
text: ['txt','log','md','nfo'],
code: ['c','conf','css','h','ini','js','json','jsx','less','list','lock','php','plist','py','sass','strings','xml'],
video: ['mpeg','mov','m4v','webm','mp4'],
};
// $ROW_SETTINGS: Ignore or Exclude files by extension
const $row_settings = {
ignore: // Files with these extensions will not be loaded if selected in the sidebar (prevents the browser from attempting to download the file).
['exe','doc','docx','rtf','xls','xlsx','odt','odp','csv','msi','dll','indd','idml','pages','numbers','tif','tiff','raw','dng','cr2','nef','arw','eps','psd','ai','afm','pfb','pfm','tfm','zip','pkg','swf','pls','ics','DS_Store','ds_store','ds_store','alias','dmg','gz','qxp','icon.jpg','thumbs.db','ape','srf','epub'],
exclude: // Files with these exensions will not be inverted in dark mode
['htm','html','xhtm','xhtml'],
};
// ***** END USER SETTINGS ***** //
// KEYBINDINGS:
// Arrow Up/Down: Select prev/next item. If audio is playing, and prev/next file is also audio, it will be selected but not loaded in the audio player; press return to load it.
// Arrow Left/Right: Select prev/next row of the same kind as the current selection, except if current selection is a media file, select and begin playback of that item.
// Cmd/Ctrl + Arrow Up: Go to parent directory
// Opt/Alt + Arrow Left/Right: Skip audio ±10s
// Shift + Opt/Alt + Arrow Left/Right: Skip audio ±30s
// Space: Pause/Play media files
// Return: Open selected directory, select file, or pause/play media.
// Cmd/Ctrl + D: Toggle file details (size, date modified) in some index page types.
// Cmd/Ctrl + G: Show or Reset Grid
// Cmd/Ctrl + I: Toggle Invisibles
// Cmd/Ctrl + Shift + O: Open selected item in new window/tab
// Cmd/Ctrl + R: Reload grids and previewed content, reset scaled images/fonts, reset media files to beginning.
// Cmd/Ctrl + W: Close previewed content (doesn't work in all browsers; use close button instead), or close window if no content is being previewed.
// Cmd/Ctrl + Shift + >: Scale preview items and grids.
// CHANGELOG:
//• 3.1.2
//• FIXED: Light theme image grid items had transparent backgrounds.
//• 3.1.1
//• CHANGED: If autoload_media = false, don't select anything.
//• FIXED: Image grid columns weren't flexing to fill width.
//• 3.1.0
//• Improved font and image grid previews: added unstyled file names for clarity, file names are no longer lowercased, and dashes and underscores are replaced with spaces.
//• Various small UI tweaks.
//• 3.0.0
//• NEW: Support for video playback (finally!). Default supported video extensions: .mpeg, .mov, .m4v, .webm, .mp4 (add additional extensions below in $row_types > video).
//• IMPROVED: Cover art auto-selection: files with "back" in the name will be ignored and files with "front" or "cover" in the name will be selected.
//• IMPROVED: Directory preview styling.
//• IMPROVED: Better support for Firefox.
//• ADDED: "Autoload media" menu item.
//• CHANGED: "autoload_audio" renamed to "autoload_media"; if you export your user settings, please this update this item accordingly when you paste them back in.
//• CHANGED: Completely reworked arrow navigation and autoload_media behavior because previous behavior was confusing.
//• Up/Down Arrows will now always select the prev/next row.
//• If the audio player is not visible, it will be displayed and the selected audio file will be loaded for playback.
//• If audio is playing and the prev/next selected file is also audio, it will be selected but not loaded, so that the currently playing audio will not be interrupted. (Press return/enter to load and begin playback of selected audio.)
//• Selecting audio files deselects video files and closes video player.
//• Selecting video files deselects audio files and closes audio player.
//• Left/Right Arrows will now always select the prev/next row of the same sort kind as the currently selected file, except:
//• if the current selection is an audio file, the L/R arrows will select and begin playback of that selection.)
//• Note that if the current selection is _not_ an audio file, any currently playing audio will continue without interruption.
//• FIXED: Media files did not scroll into view when next file began playing.
//• CHANGED: Autoload cover art now works irrespective of "autoload_media" setting.
//• IMPROVED: Left/Right arrow navigation will select prev/next dir or row if there are no media, image, or font files are in the directory.
//• IMPROVED: You can now close previewed content and audio files separately from each other.
//• CHANGED: Audio file titles shown separately from other file or dir titles.
//• IMPROVED: Added string normalization for navigation by typed string: accented characters will be matched by their base ASCII letter (e.g., á = a, Ñ = n, ß = s, etc.).
//• IMPROVED: Added "other" sort category for files whose extensions are not listed in $row_types.
//• FIXED: Parent links were incorrectly formatted.
//• FIXED: Arrow buttons in preview pane were not working properly. Now, if an image or font is displayed, clicking the arrows will select the prev/next image or font file.
//• ADDED: Contact link in shortcuts menu
//• FIXED: "Donate" link.
//• Fixes for various style glitches introduced in the last version.
//• Many, many small fixes.
//• CHANGED: moved $row_types to just below user settings, for easier management and updates.
//• Internal: Reorganized, abstracted, and DRYed many functions; added more comments.
//• 2.7.1
//• Added: User settings to choose default UI font-family and UI font size.
//• Added: User setting and menu item to alternate sidebar row background color.
//• Improved: Directory preview styling: alternating row background, font-family and font size honor UI settings.
//• Internal: Completely reorganized CSS by declarations instead of selectors (DRY CSS).
//• FIX: Font previous sometimes forgets dark mode?
//• 2.7.0: New features and user settings. Please export your user_settings before updating and note the changes mentioned below.
//• NEW (and experimental): Display a standard index of the selected sidebar directory in the preview pane.
// This is very handy for browsing directories from the sidebar.
// Clicking files and directories directly in the preview pane works as you'd expect, but it can be a little weird,
// since you can navigate up and down the directory structure in the preview pane independently from the sidebar.
//• NEW: Added URL query strings to remember directory selection history and various temporary UI settings between directory changes:
// sort order, show/hide details, default/dark mode, sidebar width, and previously selected directory.
//• NEW: Select files and directories by typed string.
//• Improved: Converted user shortcut settings to JSON for greater flexibility.
// Now you can create and name your own shortcut menu categories.
// IMPORTANT: You must re-enter your old shortcuts in the new settings format.
//• Added: Menu item to reset/delete query strings and return to the default user_settings in the script.
//• Added: New user setting to show/hide details by default. (Don't know why it took so long to add this.)
//• Added: User customizable file kinds for sorting.
// You may add or remove file kind categories and file extensions to suit your own files:
// See "$row_types" in code below, at the beginning of "General Setup" and just after the Changelog, to add your own.
//• Removed "ignore_file_types" from the user_settings, because the list of ignored file extensions has been moved:
// See "$row_settings" in code below, at the beginning of "General Setup" and just after the Changelog, to add your own.
//• Removed "user_name" from the user_settings, because it is no longer needed.
//• Improved: File shortcuts work much more reliably now, and thanks to query strings, you can now bookmark more than one file in a directory.
//• Improved: Various small UI changes.
//• Fixed: Toggle sidebar wasn't working.
//• Fixed: Ignored files weren't being sorted.
//• Internals: Abstracted a bunch of functions, removed some unneeded variables and functions. More to be done.
//• If you like this script, please consider making a donation. See the "Donate" menu item. Thanks!
//• 2.6.5
//• Fixed: First and last audio files would repeat when ended instead of going to next track in some circumstances.
//• Fixed: Various issues with file navigation.
//• 2.6.4
//• Added: Nice custom icons for dirs and various file types. Other minor UI tweaks.
//• Added: New user setting to use default file icons instead the new custom ones, in case you don't like them.
//• Added: Separate close button for audio player, since there was no way to close it while leaving other previewed content open.
//• Fixed: Really, really fixed reload button and reload shortcut not working (I hope).
//• Fixed: Yet more issues with arrow navigation.
//• Fixed: Various UI issues with Firefox.
//• Improved: Sidebar resizing should be more reliable (drag event was interacting with sidebar).
//• Other: Abstracted some styles and cleaned up code.
//• Many other bug fixes.
//• 2.6.3: Minor UI improvements and bugfixes.
//• Changed: Open dirs on double-click. (You can still open them by selecting and pressing "Return" or the Right Arrow Key.)
//• Changed: Removed autoplay_audio preference.
//• Fixed: Reload button and reload shortcut weren't working correctly.
//• Fixed: Clicking audio file name didn't pause/play file.
//• Fixed: Sidebar height didn't reset when changing sort order.
//• Fixed: Directories with a "." in the name were being sorted as if the trailing text was an extension.
//• Fixed: Corrected some code that prevented the script from working in Safari; while Safari still doesn't allow local directories to be browsed, the script will work on server-generated pages.
//• Other: Removed some unneeded styles and functions, simplified arrow navigation code.
//• 2.6.2: Fixes for a few more pesky bugs. Just when you think you're safe.... Apologies.
//• Fixed: Reload and Close buttons and keyboard combinations now work for audio files.
//• Fixed: Preview pane titlebar wasn't showing in some circumstances.
//• 2.6.1: Hopefully fixed a bug when navigating folders containing audio files. Sorry about that!
//• 2.6.0: Sorting, new user settings, and much more! This is a pretty substantial update.
//• Added: Donate link (paypal.me/mschrauzer) to the main shortcuts menu. If you like this script, please support its development. Thank you!
//• Added: Support for additional common server-generated index types. The script should now work on index pages structured as unordered lists, "
" text, and html tables.
//• Added: Sorting by name, size, date modified, kind, file extension, and default Chrome sorting (i.e., dirs on top, files alphabetical).
//• Click the "Details" button (or Cmd/Ctrl + D) to show the available sort options.
//• Note: Some server configurations don't provide size or date information; on such sites, these sorting options will not be available.
//• Note: Sorting by kind is based on the file extension, so it is rather coarse (at least for now); many non-image/audio/pdf files will simply be categorized as generic "Files".
//• Added: Added "Sort by..." menu item in the main shortcuts menu.
//• Added: New User Settings (gives you control over some behavior added in the last update):
//• default_sort: Choose default sort method: by name, size, date, kind, extension, or Chrome default (dirs on top, files alphabetical).
//• dirs_on_top: Choose whether directories should be sorted separately from files.
//• autoload_index_files: If true (default false), autoload first index.[ext] file found in directory.
//• autoload_media:
//• If false (default), treat audio files like other files for navigation purposes. Use up and down arrows as normal, only show audio controls when an audio file is selected.
//• (Note that when false, only one file in the directory at a time can be selected.)
//• If true, autoload first audio file in directory (and cover art, if any) and navigate audio with left and right arrows, other files with up and down arrows. This was the previous behavior of the script.
//• Added: Alert reminder to add your computer user account name to the settings.
//• Enhancement: UI: Added flyout submenus to main shortcuts menu.
//• Enhancement: Added .aiff, .ape, .m4a to recognized audio format types.
//• Enhancement: Added .svg to recognized image format types (they now are shown in an element instead of an